I’ll always give you guys a question to answer.
Generally most of my questions seem to stem from Nehe’s tutorials because, although they are nice, I think they are rather poor examples for converting into game code, simply because he never makes it easy to put them in with other stuff. Anyway.
I used tutorial number 6 to see how to draw a textured cube, then created a glCube method for accessing it. Nothing is drawn.
public static void glCube(String tex, int x, int y, int z, int w, int h, int d)
{
//store the current model matrix
GL11.glPushMatrix();
GL11.glTranslatef(0, 0, 0);
try
{
Texture texture = BestGameEver.textureLoader.getTexture(tex);
GL11.glEnable(GL11.GL_DEPTH_TEST); //Enable 3D depth testing
GL11.glTranslatef(0.0f, 0.0f, -5.0f); // Move Into The Screen 5 Units
texture.bind();
} catch (Exception e) {e.printStackTrace();}
ImageViewer.glColor(255,255,255,255);
GL11.glBegin(GL11.GL_QUADS);
// Front Face
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex3f(x,y+h,z); // Bottom Left Of The Texture and Quad
GL11.glTexCoord2f(1.0f, 0.0f);
GL11.glVertex3f(x+w,y+h,z); // Bottom Right Of The Texture and Quad
GL11.glTexCoord2f(1.0f, 1.0f);
GL11.glVertex3f(x+w,y,z); // Top Right Of The Texture and Quad
GL11.glTexCoord2f(0.0f, 1.0f);
GL11.glVertex3f(x,y,z); // Top Left Of The Texture and Quad
// Back Face
GL11.glTexCoord2f(1.0f, 0.0f);
GL11.glVertex3f(x+w,y+h,z-d); // Bottom Right Of The Texture and Quad
GL11.glTexCoord2f(1.0f, 1.0f);
GL11.glVertex3f(x+w,y,z-d); // Top Right Of The Texture and Quad
GL11.glTexCoord2f(0.0f, 1.0f);
GL11.glVertex3f(x,y,z-d); // Top Left Of The Texture and Quad
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex3f(x,y+h,z-d); // Bottom Left Of The Texture and Quad
// Top Face
GL11.glTexCoord2f(0.0f, 1.0f);
GL11.glVertex3f(x,y,z-d); // Top Left Of The Texture and Quad
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex3f(x,y,z); // Bottom Left Of The Texture and Quad
GL11.glTexCoord2f(1.0f, 0.0f);
GL11.glVertex3f(x+w,y,z); // Bottom Right Of The Texture and Quad
GL11.glTexCoord2f(1.0f, 1.0f);
GL11.glVertex3f(x+w,y,z-d); // Top Right Of The Texture and Quad
// Bottom Face
GL11.glTexCoord2f(1.0f, 1.0f);
GL11.glVertex3f(x+w,y+h,z-d); // Top Right Of The Texture and Quad
GL11.glTexCoord2f(0.0f, 1.0f);
GL11.glVertex3f(x,y+h,z-d); // Top Left Of The Texture and Quad
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex3f(x,y+h,z); // Bottom Left Of The Texture and Quad
GL11.glTexCoord2f(1.0f, 0.0f);
GL11.glVertex3f(x+w,y+h,z); // Bottom Right Of The Texture and Quad
// Right face
GL11.glTexCoord2f(1.0f, 0.0f);
GL11.glVertex3f(x+w,y+h,z); // Bottom Right Of The Texture and Quad
GL11.glTexCoord2f(1.0f, 1.0f);
GL11.glVertex3f(x+w,y,z); // Top Right Of The Texture and Quad
GL11.glTexCoord2f(0.0f, 1.0f);
GL11.glVertex3f(x+w,y,z-d); // Top Left Of The Texture and Quad
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex3f(x+w,y+h,z-d); // Bottom Left Of The Texture and Quad
// Left Face
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex3f(x,y+h,z-d); // Bottom Left Of The Texture and Quad
GL11.glTexCoord2f(1.0f, 0.0f);
GL11.glVertex3f(x,y+h,z); // Bottom Right Of The Texture and Quad
GL11.glTexCoord2f(1.0f, 1.0f);
GL11.glVertex3f(x,y,z); // Top Right Of The Texture and Quad
GL11.glTexCoord2f(0.0f, 1.0f);
GL11.glVertex3f(x,y,z-d); // Top Left Of The Texture and Quad
GL11.glEnd();
GL11.glPopMatrix();
}
One thing to note what I am trying to do specifically. The entirety of the game is 2D, so depth testing is most of the time disabled. When you start a dialogue or open an item window, however, the window is a 3D one that gently bobbles left and right slightly. Therefore, as you can see, I need to enable depth testing and then pop it back to the old matrix. The BestGameEver.textureLoader references the game’s TextureLoader, which is pretty much exactly Kev’s class from Space Invaders, aside from a few additions.
Nothing is drawn, and the texture is definitely found because the exact same image path is drawn correctly somewhere else.
In Nehe’s original source, he uses 0.0f or 1.0f or -1.0f in the coords, whereas I use actual points. This could be some problem. In any case, it woud be great if someone could point me in the right direction.
PS - Got text to work.