I trying TextureMapping with JOGL(didn’t use com.sun.opengl.util.texture package , just use opengl method)
i use this method to create a texture:
private boolean LoadTexture() {
gl.glGenTextures(1,texture,0);
gl.glBindTexture(gl.GL_TEXTURE_2D,texture[0]);
try {
BufferedImage bi = ImageIO.read(new File("./NeHe.png"));
byte[] data = ((DataBufferByte) bi.getRaster().getDataBuffer()).getData();
ByteBuffer bb = ByteBuffer.allocateDirect(data.length);
bb.order(ByteOrder.nativeOrder());
bb.put(data,0,data.length);
bb.rewind();
gl.glTexImage2D(GL.GL_TEXTURE_2D,0,3,bi.getWidth(),bi.getHeight(),0,GL.GL_RGB,GL.GL_UNSIGNED_BYTE,bb);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);
gl.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_MIN_FILTER,GL.GL_LINEAR); // Linear Filtering
gl.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_MAG_FILTER,GL.GL_LINEAR); // Linear Filtering
}
catch(Exception e) {
e.printStackTrace();
}
return true;
}
texture[] is a variable of class
then i draw a quad with texture
gl.glBindTexture(GL.GL_TEXTURE_2D, texture[0]);
gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
gl.glEnd();
But the texture isn’t look like as i thought, the buttom and top is reverse.
i must change my code like
gl.glBindTexture(GL.GL_TEXTURE_2D, texture[0]);
gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
gl.glEnd();
any hint to solve this problem~?
Thanks.