gpt4 book ai didi

c++ - 场景刷新卡住

转载 作者:太空狗 更新时间:2023-10-29 23:07:52 25 4
gpt4 key购买 nike

我渲染 2D(基于图 block 的)场景并注册按键。当按下箭头键时,我移动相机。虽然按键注册得很好,但我的场景不会更新,直到我切换到另一个窗口并返回

你能告诉我导致问题的原因吗?

附言。我在 Linux 上工作,在 glut (freeglut) 的帮助下开发 OpenGL 应用程序。

我的渲染函数:

void render() {
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();

if (s_map)
for (int i = s_iCameraX; i < sc_iTilesY + s_iCameraY && i < s_map->usiHeight; i++)
{
for (int j = s_iCameraY; j < sc_iTilesX + s_iCameraX && j < s_map->usiWidth; j++)
{
short val = s_map->data[i][j];
if (val == 0x0010) glBindTexture(GL_TEXTURE_2D, texture[0]);
else if (val == 0x0020) glBindTexture(GL_TEXTURE_2D, texture[1]);

glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(j-s_iCameraX, i-s_iCameraY);
glTexCoord2f(1.0f, 0.0f); glVertex2f(j-s_iCameraX+1.0f, i-s_iCameraY);
glTexCoord2f(1.0f, 1.0f); glVertex2f(j-s_iCameraX+1.0f, i-s_iCameraY+1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex2f(j-s_iCameraX, i-s_iCameraY+1.0f);
glEnd();
}
}

glutSwapBuffers();
}

我的特殊键处理函数:

void keyproc(int key, int x, int y) {
switch (key)
{
case GLUT_KEY_UP:
printf("UP: %d %d\n", s_iCameraX, s_iCameraY);
if (s_iCameraY - 1 >= 0) s_iCameraY--;
break;

case GLUT_KEY_DOWN:
printf("DOWN: %d %d\n", s_iCameraX, s_iCameraY);
if (s_map && s_iCameraY + 1 < s_map->usiHeight) s_iCameraY++;
break;

case GLUT_KEY_RIGHT:
printf("RIGHT: %d %d\n", s_iCameraX, s_iCameraY);
if (s_map && s_iCameraX + 1 < s_map->usiWidth) s_iCameraX++;
break;

case GLUT_KEY_LEFT:
printf("LEFT: %d %d\n", s_iCameraX, s_iCameraY);
if (s_iCameraX - 1 >= 0) s_iCameraX--;
break;

default: break;
}
}

最佳答案

以下可能值得一试:添加空闲回调:

void idle(void)
{
// Force GLUT to render the scene
glutPostRedisplay();
}

关于c++ - 场景刷新卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11439128/

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