I run sampl开发者_JAVA百科e 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();
}
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.
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.
精彩评论