Render anti-aliasing points

Source: Internet
Author: User

Scene

When rendering a point, if the size is larger, it is actually a rectangle, which requires an anti-aliasing technique. Use anti-aliasing to enable blending operations, make sure that the anti-aliasing settings for the video card are user-controlled or open.


Code

#include <GL/glut.h>


void Mydisplay (void)

{

Glclearcolor (1.0f, 1.0f, 1.0f, 0.0f);

Glclear (Gl_color_buffer_bit);

Glenable (Gl_point_smooth);

Glenable (Gl_blend);

Glblendfunc (Gl_src_alpha, Gl_one_minus_src_alpha);

Glhint (Gl_point_smooth_hint, gl_nicest);

Glpointsize (10.0f);


Glbegin (gl_points);

glcolor3f (0.0, 1.0, 0.0);

glvertex2f (0.0, 0.0);

Glend ();


Glflush ();

Return

}


int main (int argc, char *argv[])

{

Glutinit (&ARGC, argv);

Glutinitdisplaymode (Glut_rgb | Glut_single);

Glutinitwindowposition (100, 100);

Glutinitwindowsize (400, 400);

Glutcreatewindow ("First OpenGL program");

Glutdisplayfunc (&mydisplay);

Glutmainloop ();

return 0;

}


Suggestions

Generally to draw a better effect of the dot, it is best to use the texture.


Anti-aliasing Ideas

Sets the pixel color between adjacent steps to a transition color, making it soft, so that the object appears smooth


Problem

1) Parameter interpretation of function glpointsize in OpenGL is the diameter of the specified rasterized point

When actually set to 10.0f, the point has been set to the maximum value and cannot continue to expand

2) Glbegin (gl_points); The parameter value of the function is gl_points, not gl_point, remember

3) glpointsize (10.0f); Call to function must precede glbegin (gl_points)

4) Glblendfunc (Gl_src_alpha, Gl_one_minus_src_alpha); the second parameter value of the function specifies that the Gl_one is invalid, and that the value is valid for the intersection of a line

5) Draw the line (even if only draw a line) should pass Gl_lines, accidentally passed Gl_line, compile will not error

, but it is not effective. Draw points gl_points, quadrilateral gl_quads. Accidentally wrote a Gl_quad compile error using an undefined enumeration variable. Gl_line,gl_point,opengl is used to define the drawing mode of the polygon, as well as the Gl_fill mode.

Render anti-aliasing points

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.