我正在开发类似 Minecraft 的游戏。我为每个16x16x16块创建显示列表。它工作正常。但是当我尝试添加块选择时,它是不可见的。它仅在我处于某些随机位置时出现(我在 0,0,0 处渲染选择)。我不知道出了什么问题。
我的渲染循环:
while (isRunning) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
timer.nextFrame();
input(timer.getDelta());
tex.bind();
glLoadIdentity();
renderChunks();
renderText();
renderSelection();
Display.update();
errorCheck();
if (Display.isCloseRequested()) {
isRunning = false;
}
}
渲染块:
glRotated(player.getRy(), 1, 0, 0);
glRotated(player.getRx(), 0, 1, 0);
glTranslatef(-player.getX(), -player.getY(), -player.getZ());
//---------
for (int x = minWorldChunkX; x < maxWorldChunkX; ++x) {
for (int y = minWorldChunkY; y < maxWorldChunkY; ++y) {
for (int z = minWorldChunkZ; z < maxWorldChunkZ; ++z) {
glPushMatrix();
glTranslatef(x << 4, y << 4, z << 4);
glCallList(chunkDisplayLists.get(new ChunkPosition(x, y, z)));
glPopMatrix();
}
}
}
渲染选择:
glPushMatrix();
glCallList(selectionDisplayList);
glPopMatrix();
选择显示列表:
selectionDisplayList = glGenLists(1);
glNewList(selectionDisplayList, GL_COMPILE);
glBegin(GL_LINES);
glColor3f(0, 0, 0);
glLineWidth(3);
glVertex3f(1, 1, 1);
glVertex3f(1, 0, 1);
glVertex3f(1, 0, 1);
glVertex3f(1, 0, 0);
glVertex3f(1, 0, 0);
glVertex3f(1, 1, 0);
glVertex3f(1, 1, 0);
glVertex3f(1, 1, 1);
glVertex3f(0, 1, 0);
glVertex3f(0, 0, 0);
glVertex3f(0, 0, 0);
glVertex3f(0, 0, 1);
glVertex3f(0, 0, 1);
glVertex3f(0, 1, 1);
glVertex3f(0, 1, 1);
glVertex3f(0, 1, 0);
glVertex3f(0, 1, 0);
glVertex3f(1, 1, 0);
glVertex3f(0, 0, 0);
glVertex3f(1, 0, 0);
glVertex3f(0, 0, 1);
glVertex3f(1, 0, 1);
glVertex3f(0, 1, 1);
glVertex3f(1, 1, 1);
glEnd();
glEndList();
源代码在我的github上可用
编辑:当我在渲染块之前将 renderSelection() 从渲染循环移动到 renderChunks() 时,它起作用了。但是当我将 renderSelection() 更改为:
glPushMatrix();
glDisable(GL_DEPTH_TEST);
glCallList(selectionDisplayList);
glEnable(GL_DEPTH_TEST);
glPopMatrix();
它完全消失了。
编辑2:在渲染选择修复它时禁用混合。