I’m just starting out with 3D graphics programming and I’ve got a nicely encapsulated Cube object. This class has a render()
method, which proceeds to push a new matrix, perform transformations, glBegin
, specify all the vertices and texture coordinates, glEnd
, and pop the matrix. Now, I have written this Cube class with methods for using different textures on different faces of the cube, but that isn't happening at runtime. I understood textures to be like colors, which I can easily change per face of the cube by making a call to glColor
before the appropriate vertices, but using texture.bind()
(from the slick-util library) seems to do nothing.
This is my render method:
public void render(){
glPushMatrix();
top.bind();
top.setTextureFilter(GL_NEAREST);
glColor4f(1, 1, 1, 0);
glTranslatef(x, y, z);
glRotatef(yaw, 0, 1, 0);
glBegin(GL_QUADS);
//Top
glTexCoord2f(0, 0); glVertex3f(0, size, 0);
glTexCoord2f(0, 1); glVertex3f(0, size, size);
glTexCoord2f(1, 1); glVertex3f(size, size, size);
glTexCoord2f(1, 0); glVertex3f(size, size, 0);
//Front
top.release();
side.bind();
glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
glTexCoord2f(0, 1); glVertex3f(0, size, 0);
glTexCoord2f(1, 1); glVertex3f(size, size, 0);
glTexCoord2f(1, 0); glVertex3f(size, 0, 0);
//Left
glTexCoord2f(0, 0); glVertex3f(0, 0, size);
glTexCoord2f(0, 1); glVertex3f(0, size, size);
glTexCoord2f(1, 1); glVertex3f(0, size, 0);
glTexCoord2f(1, 0); glVertex3f(0, 0, 0);
//Right
glTexCoord2f(0, 0); glVertex3f(size, 0, size);
glTexCoord2f(0, 1); glVertex3f(size, size, size);
glTexCoord2f(1, 1); glVertex3f(size, size, 0);
glTexCoord2f(1, 0); glVertex3f(size, 0, 0);
//Back
glTexCoord2f(0, 0); glVertex3f(0, 0, size);
glTexCoord2f(0, 1); glVertex3f(0, size, size);
glTexCoord2f(1, 1); glVertex3f(size, size, size);
glTexCoord2f(1, 0); glVertex3f(size, 0, size);
//Bottom
side.release();
bottom.bind();
glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
glTexCoord2f(0, 1); glVertex3f(0, 0, size);
glTexCoord2f(1, 1); glVertex3f(size, 0, size);
glTexCoord2f(1, 0); glVertex3f(size, 0, 0);
bottom.release();
glEnd();
glPopMatrix();
}
Variables top
, side
, and bottom
are the textures I want to put on the faces of the cube.
The result is that every face of the cube has the “top” texture.
The result is the same whether I call texture.release()
or not.