Problems with initializing of a texture in JOGL

Dear OpenGL Community,

I have problems with initializing a texture. I do glGenTextures and then bind the the received id with glBindTexture to GL_TEXTURE_2D. However, after that, glIsTexture(id) returns false, and where the texture should be white is displayed - imho this shows me that the texture wasn’t properly initialized. I have to use the old net.java.games.jogl.* because of legacy issues. The loaded image is a power of 2 (256x256). glGenTextures is only called once as far as I could grep in the code. Here is the main part for showing the texture. The whole code is zipped here for further information - the shown code is part of the methode sitchOnTex in OBJLoader::Materials.java (main class ModelLoader, Argument 1 the model to load, here roman):

    gl.glDisable(GL.GL_LIGHTING);
    gl.glShadeModel(GL.GL_SMOOTH);
    gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); 
    gl.glEnable(GL.GL_TEXTURE_2D);
    usingTexture = true;
	final int[] tmp = new int[1];
	gl.glGenTextures(1, tmp);
    gl.glBindTexture(GL.GL_TEXTURE_2D, tmp[0]);
    gl.glTexImage2D(tmp[0], 0, GL.GL_RGB, tex.getWidth(), tex.getHeight(), 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, tex.getPixels());
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); 
    gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE); 
    System.out.println("Texture : "+ gl.glIsTexture(tmp[0]));

I would be very glad, if you could help me, why the texture doesn’t load

Ahem…


gl.glTexImage2D(tmp[0], 0, GL.GL_RGB, tex.getWidth(), tex.getHeight(), 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, tex.getPixels());

it should be


gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, tex.getWidth(), tex.getHeight(), 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, tex.getPixels());


Very cool. :slight_smile:

Now it works - thank you very much