Document directory
- Enable anti-aliasing
- Anti-tooth Quality
- Line example
- Multiple sampling
Recently encountered problems in the project: When drawing a graph, the straight line will have obvious serrations, and the graph is extremely unattractive. The image changes significantly after anti-aliasing is used.
The main method of anti-aliasing is as follows:
When the point is very large, it is shown as follows:
What we actually want to see isDotInsteadRectangle
Effect after anti-aliasing is enabled
A little round
Code
glPointSize(10);glEnable (GL_POINT_SMOOTH);glHint (GL_POINT_SMOOTH, GL_NICEST);
Enable anti-aliasing
Or enable anti-aliasing with glEnable, which can be processed based on different images
- GL_POINT_SMOOTH point
- GL_LINE_SMOOTH line
- GL_POLYGON_SMOOTH Polygon
Anti-tooth Quality
Of course, the better the effect, the slower the computer speed, that is, there is a parameter setting
GlHint is used to set the anti-sawtooth degree of point, line, and polygon.
- GL_DONT_CARE should be the default.
- GL_FASTEST speed first
- GL_NICEST graphic display quality is preferred
Line example
Not Enabled
After enabling
Obviously, after anti-aliasing is enabled, the coarse line is changed to a rectangle, but not a parallelogram.
Code
glEnable (GL_LINE_SMOOTH);glHint (GL_LINE_SMOOTH, GL_NICEST);glLineWidth (10);
Multiple sampling
It has multiple colors, depths, and multi-group texture coordinates based on the number of pixel samples. It is especially suitable for polygon.
Three steps
1. Obtain a window that supports multisampling. With GLUT, you can ask for one by calling
Gluinitdisplaymode (glu_double | glu_rgb |
Glu_multisample );
2. After you 've opened a window, you will need to verify that multisampling
Is available. For instance, GLUT may give you a window
With "almost" what you have asked for. If querying the state variable
GL_SAMPLE_BUFFERS returns a value of one and GL_SAMPLES returns
A value greater than one, then you'll be able to use multisampling.
(GL_SAMPLES returns the number of subpixel samples. If there is only
One sample, multisampling is supported tively disabled .)
GLint bufs, samples;
GlGetIntegerv (GL_SAMPLE_BUFFERS, & bufs );
GlGetIntegerv (GL_SAMPLES, & samples );
3. To turn on multisampling, call
GlEnable (GL_MULTISAMPLE );
Comparison of the two figures below
These functions are supported by OpenGL.