简体   繁体   中英

JOGL Confusion- How do textures work?

OpenGL is very confusing for me and I'm not used to a lot of graphic terminology, etc. which is very rampant in many tutorials. I understand how to draw triangles, circles, and quads, polygons, etc. but now I'm trying to understand how textures work.

Could someone point me in the right direction for understanding textures?

Since I could only get JOGL to work in Netbeans, I tried putting an image, entitled "Tiki Mask" into the build path. When I ran this, it had no exception thrown so I assume it found the image file?

gl.glGenTextures(1, glu, 0);
    gl.glBindTexture(gl.GL_TEXTURE_2D, glu[1]);



    try {

        Texture tex = TextureIO.newTexture(new File("tikimask.jpg"), true);
         gl.glBegin(GL.GL_POLYGON);
    gl.glNormal3f(0,0,1);
        gl.glTexCoord2d(-tex.getWidth(), -tex.getHeight());
        gl.glVertex2d(-25, -25);
        gl.glTexCoord2d(-tex.getWidth(), tex.getHeight());
        gl.glVertex2d(1.0f,0);
        gl.glTexCoord2d(tex.getWidth(), tex.getHeight());
        gl.glVertex2d(.05f, .05f);
        gl.glTexCoord2d(tex.getWidth(), -tex.getHeight());
        gl.glVertex2d(0, .05f);
    gl.glEnd();
    gl.glFlush();



    } catch (IOException ex) {
        Logger.getLogger(SimpleJOGLwee.class.getName()).log(Level.SEVERE, null, ex);
    } catch (GLException ex) {
        Logger.getLogger(SimpleJOGLwee.class.getName()).log(Level.SEVERE, null, ex);
    }

Your problem is that you never bound the texture that you loaded. Try adding these lines:

tex.enable();
tex.bind();

after you load the texture.

Also, I would recommend loading your texture in your init function, not your draw function, and then simply enable and bind them in your drawing function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM