gpt4 book ai didi

c++ - 无法使显示列表工作

转载 作者:行者123 更新时间:2023-11-28 03:55:16 25 4
gpt4 key购买 nike

首先,和往常一样,感谢所有来自 SO 社区的大力支持。

所以我写了代码来绘制 6 个 gl_quads(形成一个立方体)。最初,这段代码是立即绘制的(在显示函数中明确调用了 24 个顶点)。我想把它们放在一个显示列表中。我阅读了有关显示列表的教程,并尝试了一下。问题是,什么也没有出现,我有一个 glulookat 明确指向立方体的方向(在即时模式下验证)。所以基本上代码在不使用显示列表时完美运行,但在我尝试使用列表时却没有。

好了,说完了,让我们看一下代码:

第二次编辑- 将 glGenLists 调用移动到 initGl 中,它工作正常。谢谢大家

*EDIT-*全局调用 glGenList:

GLuint skybox = glGenLists(1);

而且我仍然得到相同的结果。屏幕上没有任何内容。

设置列表(在 initgl 函数中):

glViewport(0,0,WINDOW_WIDTH,WINDOW_HEIGHT); 
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL);

glMatrixMode(GL_PROJECTION); //setup the projection matrix
glLoadIdentity();
gluPerspective(45, WINDOW_WIDTH/WINDOW_HEIGHT,.1,200.0);

glMatrixMode(GL_MODELVIEW); //switch to modelview
glLoadIdentity();
gluLookAt(-2,2,2,0,0,0,0,1,0);
glClearColor(0, 0, 0, 0);

glNewList(skybox, GL_COMPILE_AND_EXECUTE); //draw the list once to compile/store
drawEnv(); //draw 6 quads
glEndList(); //end list

显示函数(无关代码省略):

/* Clear buffers */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//-----Draw Skybox------
glEnable(GL_TEXTURE_2D);
glPushMatrix(); //save env settings (I've tried removing this push/pop pair with same results
glCallList(skybox);
glPopMatrix();
glDisable(GL_TEXTURE_2D);

和 drawEnv() 函数:

//---------------------------
//--------RIGHT WALL---------
//---------------------------
//This code draws correctly if I move this to the display function (immediate drawing)
glBindTexture(GL_TEXTURE_2D,rightTextureId);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f( 1.0f, 1.0f, 1.0f); //V2
glTexCoord2f(0.0, 1.0); glVertex3f( 1.0f,-1.0f, 1.0f); //V1
glTexCoord2f(1.0, 1.0); glVertex3f( 1.0f,-1.0f,-1.0f); //V3
glTexCoord2f(1.0, 0.0); glVertex3f( 1.0f, 1.0f,-1.0f); //V4
glEnd();

//repeat 5 more times

最佳答案

你快到了,你只需要先调用glGenLists() 生成一组连续的空显示列表

GLuint listID;
listID = glGenLists( 1 ); // generate 1 display list
glNewList( listID, GL_COMPILE );
// whatever you want in the display list
glEndList();

// call the display list
glCallList( listID );

您还应该进行一些错误检查以确保 glGenLists() 返回有效的显示列表。

关于c++ - 无法使显示列表工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3860528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com