After much gnashing of teeth, I finally figured out how OpenGL handles images and it, of course, makes perfect sense. I’m having a problem with getting texture information, though. Basically, I just want to use glGetTexParameter(…) to pull the width and height off a texture, but I need to use Buffers (In my case, FloatBuffers) to do it. These are things that I have never used and after spending several hours searching forums and the net, can’t find a simple tutorial on them. I currently have the error “FloatBuffer is not direct”. Here’s my 2D drawing method:
public static void drawSprite(int sprite, int xLocation, int yLocation)
{
org.lwjgl.opengl.GL11.glPushMatrix();
org.lwjgl.opengl.GL11.glBindTexture(org.lwjgl.opengl.GL11.GL_TEXTURE_2D, sprite);
org.lwjgl.opengl.GL11.glTranslatef(xLocation, yLocation, 0);
org.lwjgl.opengl.GL11.glColor3f(1, 1, 1);
org.lwjgl.opengl.GL11.glBegin(org.lwjgl.opengl.GL11.GL_QUADS);
float[] floats1 = new float[6];
floats1[0] = 0;
floats1[1] = 0;
java.nio.FloatBuffer floats;
floats = java.nio.FloatBuffer.wrap(floats1);
floats.position(0);
org.lwjgl.opengl.GL11.glGetTexParameter(org.lwjgl.opengl.GL11.GL_TEXTURE_2D,
org.lwjgl.opengl.GL11.GL_TEXTURE_WIDTH, floats);
floats.position(1);
org.lwjgl.opengl.GL11.glGetTexParameter(org.lwjgl.opengl.GL11.GL_TEXTURE_2D,
org.lwjgl.opengl.GL11.GL_TEXTURE_HEIGHT, floats);
floats.position(0);
float width = floats.get();
floats.position(1);
float height = floats.get();
org.lwjgl.opengl.GL11.glTexCoord2f(0, 0);
org.lwjgl.opengl.GL11.glVertex2f(0, 0);
org.lwjgl.opengl.GL11.glTexCoord2f(0, height);
org.lwjgl.opengl.GL11.glVertex2f(0, height);
org.lwjgl.opengl.GL11.glTexCoord2f(width, height);
org.lwjgl.opengl.GL11.glVertex2f(width, height);
org.lwjgl.opengl.GL11.glTexCoord2f(width, 0);
org.lwjgl.opengl.GL11.glVertex2f(width, 0);
org.lwjgl.opengl.GL11.glEnd();
org.lwjgl.opengl.GL11.glPopMatrix();
}
It gives me the same error if I try creating the buffer using the .allocate() method as well.
The texture will just get scaled. Are you at least getting a white quad on screen? Invalid texture state results in pure white instead of texture colour. Or do you not see any quad at all? (In which case your vertex positions and/or projection setup is wrong).