我想做的是绘制一个平行六面体(使用 GL_QUADS)及其边缘(使用 GL_LINES)。平行六面体应该是一个壁球场,相机会在里面。问题是当我使用 GL_LINES 时,当相机位于平行六面体内部时,绘制的线不可见。
几个截图让你更好地理解:
内部 - 线不可见:http: //i.stack.imgur.com/OZKy5.png
外部 - 可见线:http: //i.stack.imgur.com/ah40O.png
这是我的 init 方法中的内容:
GL2 gl = drawable.getGL().getGL2(); // get the OpenGL graphics context
glu = new GLU(); // get GL Utilities
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set background (clear) color
gl.glClearDepth(1.0f); // set clear depth value to farthest
gl.glEnable(GL_DEPTH_TEST); // enables depth testing
gl.glEnable(GL_BLEND);
gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
gl.glDepthFunc(GL_LEQUAL); // the type of depth test to do
gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // best perspective correction
gl.glShadeModel(GL_SMOOTH); // blends colors nicely, and smoothes out lighting
gl.glEnable(GL_LINE_SMOOTH);
这是我的显示方法:
GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context
gl.glClearColor(0.55f, 0.55f, 0.55f, 1.0f);
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth buffers
gl.glLoadIdentity(); // reset the model-view matrix
gl.glTranslated(-3.2, -2.82, -10); // translate into the screen
gl.glBegin(GL_QUADS); // Start Drawing The Quad
gl.glColor4ub(r,g,b, alpha);
gl.glVertex3d(0, 0, 0);
gl.glVertex3d(0, 5.640, 0);
gl.glVertex3d(6.400, 5.640, 0);
gl.glVertex3d(6.400, 0, 0);
gl.glVertex3d(0, 0, 0);
gl.glVertex3d(0, 5.640, 0);
gl.glVertex3d(0, 5.640, 9.750);
gl.glVertex3d(0, 0, 9.750);
gl.glVertex3d(6.400, 0, 0);
gl.glVertex3d(6.400, 5.640, 0);
gl.glVertex3d(6.400, 5.640, 9.750);
gl.glVertex3d(6.400, 0, 9.750);
gl.glVertex3d(0, 0, 9.750);
gl.glVertex3d(0, 5.640, 9.750);
gl.glVertex3d(6.400, 5.640, 9.750);
gl.glVertex3d(6.400, 0, 9.750);
gl.glVertex3d(0, 0, 0);
gl.glVertex3d(0, 0, 9.750);
gl.glVertex3d(6.400, 0, 9.750);
gl.glVertex3d(6.400, 0, 0);
gl.glVertex3d(0, 5.640, 0);
gl.glVertex3d(0, 5.640, 9.750);
gl.glVertex3d(6.400, 5.640, 9.750);
gl.glVertex3d(6.400, 5.640, 0);
gl.glEnd(); // Done Drawing The Quad
gl.glLineWidth(2);
gl.glBegin(GL_LINES);
gl.glColor4ub((byte)0,(byte)0,(byte)0, (byte)255);
gl.glVertex3d(0, 0, 0);
gl.glVertex3d(0, 5.640, 0);
gl.glEnd();
谢谢您的帮助。