Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Problems with initializing of a texture in JOGL

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2011
    Posts
    2

    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):


    Code :
        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

  2. #2
    Intern Contributor uruk's Avatar
    Join Date
    Dec 2004
    Location
    acasa :) sau la munca :(
    Posts
    66

    Re: Problems with initializing of a texture in JOGL

    Ahem...
    Code :
    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

    Code :
    gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, tex.getWidth(), tex.getHeight(), 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, tex.getPixels());
    Stat rosa pristina nomine, nomina nuda tenemus.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2011
    Posts
    2

    Re: Problems with initializing of a texture in JOGL

    Very cool. :-)

    Now it works - thank you very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •