6

I am using freeglut. I'm trying to get FSAA working, but nothing seems to work. Sample buffers is 1 and Samples is 4. But I'm not seeing any anti-aliasing. Am I missing something? Currently, I am running Ubuntu 12.04; not sure if that changes 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 am well aware of SDL and GLFW. I'd like to get it working in freeglut though.

More info:
Graphics card:ATI Radeon HD 4250
OpenGL version: 3.3.11627 Compatibility Profile Context

Azmisov
  • 6,493
  • 7
  • 53
  • 70

3 Answers3

0

To antialiase 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);
Stefan Fandler
  • 1,141
  • 7
  • 13
0

Your code did work properly on my computer (running Windows). Just make sure that you are using freeglut and not just regular GLUT. Thus, you should be linking to the properly library files (like freeglut.lib/freeglut.dll on windows). Additionally, it would not be a bad idea to include freeglut.h instead of glut.h to be sure that you are actually including the header file you intend to.

Also, there is no need to call glClearColor every frame. You only have to call it when you want to change the clear color. Just remember though, like glColor, glClearColor only applies to function calls that occur after it.

fintelia
  • 1,201
  • 6
  • 17
  • Hmmm. Do I need to set a different build option than "-lglut"? – Azmisov Jun 07 '12 at 04:43
  • @fintelia: Actually calling glClearColor every frame is good style. Eventually one wants to implement fancier rendering techniques that involve multiple passes or FBOs and once you do that, you have to make sure that at the beginning of rendering a frame everything is set properly. – datenwolf Mar 03 '15 at 00:12
0

GLUT on my Windows 7 NVIDIA is somehow not working either. I got 0 for both Sample buffers and Samples.

However, freeglut solves it and gives you the option to set 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");
    }   
}
leoly
  • 8,468
  • 6
  • 32
  • 33