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,当使用多重采样和颜色索引的时候,就会出现这种情况,我也到网上查了下,无果!!特来请教各位大神啊,



...全文
85 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
柳11 2011-09-10
  • 打赏
  • 举报
回复
只是学习下,应该可以的吧!!!!
ryfdizuo 2011-09-10
  • 打赏
  • 举报
回复
lz啊,顶点列表和颜色索引已经十分的out了。
你上这个网址下例子程序看看吧:
www.codesampler.com
柳11 2011-09-10
  • 打赏
  • 举报
回复
不懂呢,反正代码什么的没错,库函数也添加呢,也include了,总是这个提示:pixel format with necessary capabilities not found!!!
fox000002 2011-09-09
  • 打赏
  • 举报
回复
这种情况是甚么情况
jackyjkchen 2011-09-08
  • 打赏
  • 举报
回复
现在手头机器没有opengl库,先帮你顶下
柳11 2011-09-08
  • 打赏
  • 举报
回复
刚学OpenGL,当使用多重采样和颜色索引的时候,就会出现这种情况,我也到网上查了下,无果!!特来请教各位大神啊,
这里附上代码和问题的描述,劳驾各位呢!!!

#include<stdio.h>

#include<stdlib.h>

#include<GL/glew.h>

#include<GL/glut.h>





static int bgtoggle=1;



void Init()

{

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.25);

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+i)%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()

{

glClear(GL_COLOR_BUFFER_BIT);



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':

bgtoggle=!bgtoggle;

glutPostRedisplay();

break;

case 27:

exit(0);

break;

default:

break;

}

}
void reshape(int w,int h)

{

glViewport(0,0,(GLsizei)w,(GLsizei)h);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glOrtho(0.0,(GLdouble)w,0.0,(GLdouble)h,-1.0,1.0);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

}


int main(int argc,char **argv)

{

glutInit(&argc,argv);

glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GL_MULTISAMPLE);

glutInitWindowPosition(100,100);

glutInitWindowSize(600,600);

glutCreateWindow("自己动手,丰衣足食");

Init();

glutDisplayFunc(display);

glutReshapeFunc(reshape);

glutKeyboardFunc(keyboard);

glutMainLoop();

return 0;

//这些都是红宝书上的代码,本人彩笔,还望各位表笑话咱!!!

}

刚学OpenGL,当使用多重采样和颜色索引的时候,就会出现这种情况,我也到网上查了下,无果!!特来请教各位大神啊,



柳11 2011-09-08
  • 打赏
  • 举报
回复
那我再重发下吧。。。
jackyjkchen 2011-09-08
  • 打赏
  • 举报
回复
不知道那些加行号而且还能复制出来的都是什么狗屎编辑器,这些加行号的代码想帮你调试都无从下手

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧