问题
Im trying to draw some quads in minecraft but this is the problem im having: http://imgur.com/DgnAqv1 but it should draw triangles on each sides so there should be 4 triangles in total, I dont know why this isnt working.
GL11.glPushMatrix();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDepthMask(false);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(0F, 0.5F, 0.8F, 1F);
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX, ep.posY + ep.height + 0.5D - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX + 1, ep.posY - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX, ep.posY - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ + 1);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX, ep.posY + ep.height + 0.5D - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ);
GL11.glEnd();
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX, ep.posY + ep.height + 0.5D - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX - 1, ep.posY - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX, ep.posY - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ - 1);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX, ep.posY + ep.height + 0.5D - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ);
GL11.glEnd();
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX, ep.posY + ep.height + 0.5D - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX - 1, ep.posY - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX, ep.posY - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ + 1);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX, ep.posY + ep.height + 0.5D - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ);
GL11.glEnd();
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX, ep.posY + ep.height + 0.5D - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX + 1, ep.posY - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX, ep.posY - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ - 1);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX, ep.posY + ep.height + 0.5D - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ);
GL11.glEnd();
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthMask(true);
GL11.glPopMatrix();
回答1:
You should probably disable face culling: GL11.glDisable(GL11.GL_CULL_FACE);
Your triangles might have the wrong orientation, so you only see the back faces. Another solution would be to reorient the triangles (e.g. by swapping the first and second vertex), but since you use transparency you probably want to render both front and back faces.
Side note: I don't know why you're using GL_QUADS if you want to render triangles. So here's the first quad you posted:
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX, ep.posY + ep.height + 0.5D - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX + 1, ep.posY - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX, ep.posY - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ + 1);
GL11.glVertex3d(ep.posX - RenderManager.renderPosX, ep.posY + ep.height + 0.5D - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ);
GL11.glEnd();
The equivalent code using glTranslate and GL_TRIANGLES would be:
GL11.glTranslated(ep.posX - RenderManager.renderPosX, ep.posY - RenderManager.renderPosY, ep.posZ - RenderManager.renderPosZ );
GL11.glBegin(GL11.GL_TRIANGLES);
GL11.glVertex3d(0, ep.height + 0.5D, 0);
GL11.glVertex3d(1, 0, 0);
GL11.glVertex3d(0, 0, 1);
GL11.glEnd();
Also note that you don't need to call glBegin/glEnd
for each triangle, you can simply call glVertex3d
3*n times to render n triangles.
来源:https://stackoverflow.com/questions/17252166/opengl-drawing-quads-in-minecraft-display-weirdly