我对OpenGL和游戏开发都很陌生。也许我会错过一些重要的代码或在我的代码中做了一些可怕的事情。请随时在评论中询问更多信息。
我试图用单线画出一个3D立方体。它按预期工作,但出现奇怪的行 奇怪的行从 0,0,1 移动到 1,1,0
我用不同的(纯色)颜色着色我的线条。 怪异的行有一个渐变。
由于这是很多代码,我会尝试发布最小值。正如我之前所说,随时可以要求更多。
绘制我的多维数据集的方法
private void drawBlock(Position pos) {
int x = pos.x, y = pos.y, z = pos.z;
GL11.glBegin(GL11.GL_LINE_STRIP);
GL11.glColor4f(1, 1, 1, 1);
// 0,0,0 -> 5,0,0
GL11.glVertex3i(x, y, z);
GL11.glVertex3i(x + blockSize, y, z);
// 0,0,0 -> 0,5,0
GL11.glVertex3i(x, y, z);
GL11.glVertex3i(x, y + blockSize, z);
// 0,0,0 -> 0,0,5
GL11.glVertex3i(x, y, z);
GL11.glVertex3i(x, y, z + blockSize);
GL11.glColor4f(0.1f, 0.5f, 0.5f, 1);
// 5,0,5 -> 0,0,5
GL11.glVertex3i(x + blockSize, y, z + blockSize);
GL11.glVertex3i(x, y, z + blockSize);
// 5,0,5 -> 5,5,5
GL11.glVertex3i(x + blockSize, y, z + blockSize);
GL11.glVertex3i(x + blockSize, y + blockSize, z + blockSize);
// 5,0,5 -> 5,0,0
GL11.glVertex3i(x + blockSize, y, z + blockSize);
GL11.glVertex3i(x + blockSize, y, z);
GL11.glColor4f(0.9f, 0.25f, 0.25f, 1);
// 0,5,5 -> 0,0,5
GL11.glVertex3i(x, y + blockSize, z + blockSize);
GL11.glVertex3i(x, y, z + blockSize);
// 0,5,5 -> 5,5,5
GL11.glVertex3i(x, y + blockSize, z + blockSize);
GL11.glVertex3i(x + blockSize, y + blockSize, z + blockSize);
// 0,5,5 -> 0,5,0
GL11.glVertex3i(x, y + blockSize, z + blockSize);
GL11.glVertex3i(x, y + blockSize, z);
GL11.glColor4f(1, 0.75f, 0, 1);
// 5,5,0 -> 5,0,0
GL11.glVertex3i(x + blockSize, y + blockSize, z);
GL11.glVertex3i(x + blockSize, y, z);
// 5,5,0 -> 0,5,0
GL11.glVertex3i(x + blockSize, y + blockSize, z);
GL11.glVertex3i(x, y + blockSize, z);
// 5,5,0 -> 5,5,5
GL11.glVertex3i(x + blockSize, y + blockSize, z);
GL11.glVertex3i(x + blockSize, y + blockSize, z + blockSize);
GL11.glEnd();
}
OpenGL初始化
public void init3D() {
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluPerspective((float) 100, width / height, 0.001f, 1000);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
GL11.glClearDepth(1.0f);
}
答案 0 :(得分:1)
你应该使用GL11.glBegin(GL11.GL_LINES);
而不是线条,
line_strip是连接线的序列,其中序列P1,P2,P3,P4给出线P1-P2,P2-P3,P3-P4等,而GL_LINES
仅给出P1-P2和P3-P4