lwjgl - screen sized background image

this seems like it must be way too obvious…

i want to display a 800x600 background image on an 800x600 screen. it appears that i will have to load it into a 1024x1024 texture since non power of 2 textures dont work properly. im used to working with arbitrary image sizes and this doesnt seem like a very tidy approach. am i missing something or do i just have to start thinking differently when using opengl?

LWJGL doesn’t force you to use POT images, I don’t know why you think that. You can load an 800x600 resolution image.

i think that because i was loading some 200x200 textures and they appeared with a black border around 2 sides, i assumed that it was increasing the texture size to 256x256 without scaling the texture, cos as soon as i changed my image file to 256x256 it was fine.

excuse me if im wrong, ive been sick in bed for 3 weeks and i still cant think straight :clue:

ill go and try to write the 5 lines of code it would take to verify lol

i had another go at testing it out and it still appears to be loading my 800x600 image file into the nearest POT sized texture that it will fit into…

im using this to load the textures:


InputStream in = getClass().getResourceAsStream("res/"+name);
Texture texture1 = TextureLoader.getTexture("PNG", in);

perhaps im loading the images in the wrong way?

my rendering code seems to function perfectly fine…


      glTexCoord2f(0.0f,1.0f); glVertex2f(0.0f,0.0f);
      glTexCoord2f(1.0f,1.0f); glVertex2f(800f,0.0f);
      glTexCoord2f(1.0f,0.0f); glVertex2f(800f,600f);
      glTexCoord2f(0.0f,0.0f); glVertex2f(0.0f,600f);

if i stretch the image file to 1024x1024 in my image editor, it appears as intended in my program, but if i load it from the 800x600 file it appears to be shrunk. this is why i think its a POT issue. i cant imagine its just my graphics card because i havnt noticed this problem when running anyone elses programs.

Well you’re texture coordinates seem a little flipped, although that shouldn’t matter. Can I see your TextureLoader.getTexture function?

the TextureLoader is from slickutil.

perhaps i should be using libgdx, i probably dont need the lower functionality of opengl at this point.

I believe in the texCoord you use texture.getWidth(); or texture.getHeight(); instead of 1.0f

OpenGL texture coordinates are “normalized” (0.0 - 1.0). texture.getWidth() would produce the same result though because OpenGL clamps the values, so anything over 1 would still be 1. I have a feeling that’s not what you’re talking about though and I sound like an idiot :stuck_out_tongue:

slickutils creates power of 2 size textures in your back, that’s why you have strange stretching/padding results :wink: I don’t remember if there is some kind of parameter to pass to the loader to disable this thing, you should check this.

OpenGL supports non POT textures for ages, so it’s not an OpenGL issue.

I think it’s texture.getImageWidth() / texture.getWidth() or something similar…

[quote]Note the differences:


1. Texture.getImageWidth() -> the width of the loaded image in pixels for glVertex2f (e.g. 384 px)
2. Texture.getTextureWidth() -> the converted power-of-two size (e.g. 512 px)
3. Texture.getWidth() -> the normalized width of the texture for glTexCoord2f (e.g. 0.75)

[/quote]

thanks everyone, now i have a much clearer idea of what to look into!