Problem with size of textures/quads

Started by Schnitter, October 10, 2007, 14:48:00

Previous topic - Next topic

Schnitter

Please take a look at this picture:
http://planschkuh.pl.ohost.de/error1.jpg

As you can see, the quad is bigger than the texture. It is important for the Mouse-support, that the texture is exactly on the quad.
My classes are all available in the internet. My sprite class works well, but here's the code:http://nopaste.info/8177c8182e.html
The TextureLoader/Texture class is as the one in the tutorial, in the LWJGL-wiki.

I'm out of ideas about this problem. I hope, you can give me some tips.

bitsNbytes

hi,

your texture looks like it wasn't a square (width != height). Perhaps the texture-loader fills the missing part of the texture with black color (i had this problem once). Clear your screen with a different color (red for example) and you might see what i mean.

i hope this helps

Schnitter

Ehm...now it looks like this: http://planschkuh.ohost.de/error2.jpg.
It isn't what I expected. And I can't imagine, how it can help me :(

bitsNbytes

hmm

could you post your texture-dimensions or try a valid sized texture (64x64)?

i looked at the textureloader on the wiki:
-the images are always loaded as rgba
-if the image size is not corret (non power of two), rest will be blank

  // get image attributes
  int width = IL.ilGetInteger(IL.IL_IMAGE_WIDTH);
  int height = IL.ilGetInteger(IL.IL_IMAGE_HEIGHT);
  int textureWidthSize = getNextPowerOfTwo(width);
  int textureHeightSize = getNextPowerOfTwo(height);
 
  // resize image according to poweroftwo
  if (textureWidthSize != width || textureHeightSize != height) {
    imageData = BufferUtils.createByteBuffer(textureWidthSize * textureHeightSize * 4);
    IL.ilCopyPixels(0, 0, 0, textureWidthSize, textureHeightSize, 1, IL.IL_RGBA, IL.IL_BYTE, imageData);
  } else {
    imageData = IL.ilGetData();
  }


BTW: i tested your code.. it works fine on my computer.. (i just use another texture loader and a 256x256 texture)

Schnitter

My texture is an   160*156 (so the width isn't a power-ot-two)*.tga-image.

Little question: When I switch my texture to an power-of-two-image, can I resize it on the quad, as I want?(Without loose so much quality?)

bitsNbytes

if you render the stretched powerOfTwo texture on a rectangle, the quality depends on the filter you are using.

you could also adjust the texture coordinates of the sprite
i guess your 160*256 image is written into a 256*256 texture
so you can write GL11.glTexCoord2f(0,0) .... GL11.glTexCoord2f(160.0f/256.0f, 256.0f/256.0f) and so on.. the aspect ratio of the rendered rectangle should be the same as the texture of course.

this way only the interesting part of the texture is drawn on the sprite without stretching