OpenGL的小问题
柳11 2011-09-08 10:19:53 刚学OpenGL,当使用多重采样和颜色索引的时候,就会出现这种情况,我也到网上查了下,无果!!特来请教各位大神啊,
这里附上代码和问题的描述,劳驾各位呢!!!
view sourceprint?001 #include<stdio.h>
002 #include<stdlib.h>
003 #include<GL/glew.h>
004 #include<GL/glut.h>
005
006
007 static int bgtoggle=1;
008
009 void Init()
010 {
011 GLint buf,sbuf;
012 int i,j;
013 glClearColor(0.0,0.0,0.0,0.0);
014 glGetIntegerv(GL_SAMPLE_BUFFERS,&buf);
015 printf("number of sample buffers is %d \n",buf);
016 glGetIntegerv(GL_SAMPLES,&sbuf);
017 printf("number of samples is %d \n",sbuf);
018
019 glNewList(1,GL_COMPILE);
020 for(i=0;i<19;i++){
021 glPushMatrix();
022 glRotatef(360.0*(float)i/19.0,0.0,0.0,1.0);
023 glColor3f(1.0,1.0,1.0);
024 glLineWidth((i/3)+1.0);
025 glBegin(GL_LINES);
026 glVertex2f(0.25,0.25);
027 glVertex2f(0.9,0.2);
028 glEnd();
029 glColor3f(0.0,1.0,1.0);
030 glBegin(GL_TRIANGLES);
031 glVertex2f(0.25,0.0);
032 glVertex2f(0.9,0.0);
033 glVertex2f(0.875,0.10);
034 glEnd();
035 glPopMatrix();
036 }
037 glEndList();
038
039 glNewList(2,GL_COMPILE);
040 glColor3f(1.0,0.5,0.0);
041 glBegin(GL_QUADS);
042 for(i=0;i<16;i++)
043 for(j=0;j<16;j++)
044 if((i+i)%2==0){
045 glVertex2f(-2.0+(i*0.25),-2.0+(j*0.25));
046 glVertex2f(-2.0+(i*0.25),-1.75+(j*0.25));
047 glVertex2f(-1.75+(i*0.25),-1.75+(j*0.25));
048 glVertex2f(-1.75+(i*0.25),-2.0+(j*0.25));
049 }
050 glEnd();
051 glEndList();
052
053 }
054
055 void display()
056 {
057 glClear(GL_COLOR_BUFFER_BIT);
058
059 if(bgtoggle)
060 glCallList(2);
061 glEnable(GL_MULTISAMPLE);
062 glPushMatrix();
063 glTranslatef(-1.0,0.0,0.0);
064 glCallList(1);
065 glPopMatrix();
066
067 glDisable(GL_MULTISAMPLE);
068 glPushMatrix();
069 glTranslatef(1.0,0.0,0.0);
070 glCallList(1);
071 glPopMatrix();
072 glutSwapBuffers();
073
074 }
075
076 void keyboard(unsigned char key,int x,int y)
077 {
078 switch(key){
079 case 'b':
080 bgtoggle=!bgtoggle;
081 glutPostRedisplay();
082 break;
083 case 27:
084 exit(0);
085 break;
086 default:
087 break;
088 }
089
090 }
091 void reshape(int w,int h)
092 {
093 glViewport(0,0,(GLsizei)w,(GLsizei)h);
094 glMatrixMode(GL_PROJECTION);
095 glLoadIdentity();
096 glOrtho(0.0,(GLdouble)w,0.0,(GLdouble)h,-1.0,1.0);
097 glMatrixMode(GL_MODELVIEW);
098 glLoadIdentity();
099 }
100
101
102 int main(int argc,char **argv)
103 {
104 glutInit(&argc,argv);
105 glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GL_MULTISAMPLE);
106 glutInitWindowPosition(100,100);
107 glutInitWindowSize(600,600);
108 glutCreateWindow("自己动手,丰衣足食");
109 Init();
110 glutDisplayFunc(display);
111 glutReshapeFunc(reshape);
112 glutKeyboardFunc(keyboard);
113 glutMainLoop();
114 return 0;
115 //这些都是红宝书上的代码,本人彩笔,还望各位表笑话咱!!!
116 }
刚学OpenGL,当使用多重采样和颜色索引的时候,就会出现这种情况,我也到网上查了下,无果!!特来请教各位大神啊,