I want to have textures, but I think I'm doing something wrong.
My initiation
public void init(GLAutoDrawable drawable) { GL gl = drawable.getGL(); gl.glShadeModel(GL.GL_SMOOTH); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glClearDepth(1.0f); gl.glEnable(GL.GL_DEPTH_TEST); gl.glDepthFunc(GL.GL_LEQUAL); gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); gl.glEnable(GL.GL_CULL_FACE); gl.setSwapInterval(1); drawable.addKeyListener(this); drawable.addKeyListener(thread); gl.glEnable(GL.GL_NORMALIZE); gl.glEnable(GL.GL_COLOR_MATERIAL); loadTextures(); }
Loading texture:
private void loadTextures(){ try{ InputStream stream = getClass().getResourceAsStream("bricks.png"); TextureData data = TextureIO.newTextureData(stream, false, "png"); wallTexture = TextureIO.newTexture(data); } catch (IOException ex){ ex.printStackTrace(); System.exit(1); } }
and drawing the wall (code for one, others almost the same)
private void addWalls(GL gl, float x, float z, int dir){ gl.glPushMatrix(); gl.glBegin(GL.GL_QUADS); wallTexture.enable(); wallTexture.bind(); gl.glNormal3f(-1.0f, 0.0f, 0.0f); gl.glTexCoord2f(0, 0); gl.glVertex3f(x, 0.0f, z+1); gl.glTexCoord2f(1, 0); gl.glVertex3f(x, 1.0f, z+1); gl.glTexCoord2f(1, 1); gl.glVertex3f(x, 1.0f, z); gl.glTexCoord2f(0, 1); gl.glVertex3f(x, 0.0f, z); (...)//other walls wallTexture.disable(); gl.glEnd(); gl.glPopMatrix(); }
wallTexture is opengl.util.texture.Texture
When I run it walls aren't textured, they are just white.
What I am doing wrong?