Smoothing OpenGL with freeglut

I am using freeglut. I am trying to get FSAA to work, but nothing works. The sample buffers are 1, and the samples are 4. But I do not see any smoothing. Am I missing something? I am currently running Ubuntu 12.04; not sure if this will change anything.

#include <GL/glut.h> #include <GL/glext.h> #include <stdio.h> void render(void); int main(int argc, char **argv){ glutInit(&argc,argv); //Initialize the window glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_MULTISAMPLE); glutInitWindowPosition(100,100); glutInitWindowSize(200,200); glutCreateWindow("Testing"); glutDisplayFunc(render); //Enable FSAA glEnable(GL_MULTISAMPLE); //2D graphics glDisable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT), 0, 0, 1); glMatrixMode(GL_MODELVIEW); GLint buf, sbuf; glGetIntegerv(GL_SAMPLE_BUFFERS, &buf); printf("number of sample buffers is %d\n", buf); glGetIntegerv(GL_SAMPLES, &sbuf); printf("number of samples is %d\n", sbuf); glutMainLoop(); return 0; } //Draw some stuff void render(void){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glColor3f(0.0f,1.0f,0.0f); glBegin(GL_LINE_LOOP); glVertex2f(10.0,10.0); glVertex2f(170.0,60.0); glVertex2f(50.0,130.0); glVertex2f(50.0,60.0); glEnd(); glutSwapBuffers(); } 

I know SDL and GLFW well. I would like to make it work in freeglut, though.

Additional Information:
Video Card: ATI Radeon HD 4250
OpenGL Version: 3.3.11627 Compatibility Profile Context

+6
source share
3 answers

To smooth your points and lines in 2D, you can also do this:

 glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH, GL_NICEST); glEnable(GL_POINT_SMOOTH); glHint(GL_POINT_SMOOTH, GL_NICEST); 
0
source

Your code really worked on my computer (running Windows). Just make sure you use freeglut and not just plain GLUT. Therefore, you must connect to the appropriate library files (eg. Freeglut.lib / freeglut.dll in windows). Also, it would be nice to include freeglut.h instead of glut.h to make sure that you really include the header file that you intend.

In addition, there is no need to call glClearColor every frame. You only need to call when you want to change the transparent color. Just remember that, for example, glColor , glClearColor applies only to function calls that occur after it.

0
source

GLUT on my Windows 7 NVIDIA does not work anyway. I got 0 for both sample buffers and Samples .

However, freeglut solves it and gives you the opportunity to install Samples .

 glutSetOption(GLUT_MULTISAMPLE, 4); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_MULTISAMPLE); 

To turn it on

 void glexMultisample(int msaa) { if (msaa) { glEnable(GL_MULTISAMPLE); // detect current settings GLint iMultiSample = 0; GLint iNumSamples = 0; glGetIntegerv(GL_SAMPLE_BUFFERS, &iMultiSample); glGetIntegerv(GL_SAMPLES, &iNumSamples); printf("MSAA on, GL_SAMPLE_BUFFERS = %d, GL_SAMPLES = %d\n", iMultiSample, iNumSamples); } else { glDisable(GL_MULTISAMPLE); printf("MSAA off\n"); } } 
0
source

Source: https://habr.com/ru/post/917254/


All Articles