views:

66

answers:

3

I run sample of multi sampling but it work incorrect it seems that multi sampling don't applied because of sample buffers & samples is 0. what should i do to make it correct?

thanks.

this is my code:

#include <stdio.h>
#include <stdlib.h>
#include <glew.h>
#include <GL/glut.h>

static int bgtoggle = 1;
void init(void)
{
GLint buf, sbuf;
int i, j;
glClearColor(0.0, 0.0, 0.0, 0.0);
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);
glNewList(1, GL_COMPILE);
for (i = 0; i < 19; i++) {
    glPushMatrix();
    glRotatef(360.0*(float)i/19.0, 0.0, 0.0, 1.0);
    glColor3f (1.0, 1.0, 1.0);
    glLineWidth((i%3)+1.0);
    glBegin(GL_LINES);
    glVertex2f(0.25, 0.05);
    glVertex2f(0.9, 0.2);
    glEnd();
    glColor3f(0.0, 1.0, 1.0);
    glBegin(GL_TRIANGLES);
    glVertex2f(0.25, 0.0);
    glVertex2f(0.9, 0.0);
    glVertex2f(0.875, 0.10);
    glEnd();
    glPopMatrix();
}
glEndList();
glNewList(2, GL_COMPILE);
glColor3f(1.0, 0.5, 0.0);
glBegin(GL_QUADS);
for (i = 0; i < 16; i++) {
    for (j = 0; j < 16; j++) {
        if (((i + j) % 2) == 0) {
            glVertex2f(-2.0 + (i * 0.25), -2.0 + (j * 0.25));
            glVertex2f(-2.0 + (i * 0.25), -1.75 + (j * 0.25));
            glVertex2f(-1.75 + (i * 0.25), -1.75 + (j * 0.25));
            glVertex2f(-1.75 + (i * 0.25), -2.0 + (j * 0.25));
            }
        }
    }
glEnd();
glEndList();
  }
  void display(void)
  {
glClear(GL_COLOR_BUFFER_BIT);
glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
if (bgtoggle)
    glCallList(2);
glEnable(GL_MULTISAMPLE);
glPushMatrix();
glTranslatef(-1.0, 0.0, 0.0);
glCallList(1);
glPopMatrix();
glDisable(GL_MULTISAMPLE);
glPushMatrix();
glTranslatef(1.0, 0.0, 0.0);
glCallList(1);
glPopMatrix();
glutSwapBuffers();
   }
   void keyboard(unsigned char key, int x, int y)
   {
switch (key) {
case 'b':
case 'B':
    bgtoggle = !bgtoggle;
    glutPostRedisplay();
break;
case 27: /* Escape Key */   
exit(0);
break;
default:
break;
}
}
int main(int argc,char** argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_MULTISAMPLE|GLUT_DOUBLE|GLUT_DEPTH);
glutInitWindowPosition(100,100);
glutInitWindowSize(800,600);
glutCreateWindow("MultiSample");
init();
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
 }
+1  A: 

Set appropriate GLCapabilities while creating GLContext. Make sure there are glEnable(GL_LINE_SMOOTH); and glEnable(GL_MULTISAMPLE); before drawing code.

Have You tried this one:

glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_MULTISAMPLE );
glEnable(GL_MULTISAMPLE);

Try also to use glEnable(GLUT_MULTISAMPLE_ARB) instead.

Rekin
i test all of this methods
pooya
@pooya And did they work?
Matias Valdenegro
pooya
i will update my question with my code .
pooya
A: 

The redbook says only calling glEnable(GL_MULTISAMPLE); is sufficient. I don't know exactly about the other thing(GL_LINE_SMOOTH) but apparently it is not done with multisampling. The thing is we want to get a full scene antialiasing not only for polygons, lines or points. It is very costly and with high overhead.

pooya
Create a comment in the answer to comment that answer, don't answer your own questions in that way :)
Matias Valdenegro
A: 

Is not that simple, beside enabling multisampling, you need to create a OpenGL context with samples > 0, and that is window-system dependant, and API dependant. If you provide what API are you using to create the OpenGL context/window, and we'll be able to tell you exactly how it is done.

Matias Valdenegro
we use glut in win32
pooya
I would try with another "framework", GLUT is practically a toy, and it has issues with multisampling. I recommend SDL.
Matias Valdenegro
where can i learn more about SDL ? i known a little about SDL i wrote super mario with it but i want to know how use it with openGL? thanks a lot
pooya