I use JOGL (Java OpenGL). I have a parallelepiped spinning with glRotatef
. I draw it like this:
private void drawCenteredCube(GL2 gl) { int height = (int) SizeUtil.getHeight(); int width = (int) SizeUtil.getWidth(); int depth = (int) SizeUtil.getDepth(); gl.glColor4f(0.4f, 0.3f, 0.3f, 0); drawSquareFace(gl, height, depth, width); // бок gl.glColor4f(0.09f, 0.095f, 0.095f, 0); gl.glRotatef(90, 1, 0, 0); drawSquareFace(gl, height, width, depth); // зад gl.glColor4f(0.61f, 0.05f, 0.1f, 0); gl.glRotatef(90, 0, 1, 0); drawSquareFace(gl, depth, width, height); // низ gl.glRotatef(90, 0, 1, 0); ForegroundUtil.paint(gl, 0, 0, depth / 2); // лицо gl.glColor4f(0.4f, 0.3f, 0.3f, 0); gl.glRotatef(90, 1, 0, 0); drawSquareFace(gl, height, depth, width); // бок gl.glColor4f(0.61f, 0.05f, 0.1f, 0); gl.glRotatef(90, 0, 1, 0); drawSquareFace(gl, width, depth, height); // верх gl.glColor3f(0.0f, 0.0f, 0.0f); }
The problem is that I constantly have some parts of the figure drawn on top of others, although in fact they should not be visible at a specific point in time. How to understand when some face to draw?