我正在开发类似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;
}
}
renderChunks:
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();
}
}
}
renderSelection:
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: 渲染选择时禁用混合会修复它。
答案 0 :(得分:0)
在渲染块选择时禁用混合会修复它。
新的renderSelection代码:
glPushMatrix();
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glCallList(selectionDisplayList);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glPopMatrix();
更新:它实际上是由其他东西引起的:
selectionDisplayList = glGenLists(1);
glNewList(selectionDisplayList, GL_COMPILE);
glBegin(GL_LINES);
...
glLineWidth(3);//This is what caused the issue
...
通常在glBegin()和glEnd()之间设置行宽应该会导致错误,但它不在我的计算机上(ATI显卡,Ubuntu)。在其他计算机上,glError()返回非零值。