Hello Guest

Texture Not Sampling Properly. Least I think it is

  • 4 Replies
  • 4127 Views
Texture Not Sampling Properly. Least I think it is
« on: February 08, 2016, 06:53:19 »
Hi, so yesterday I got to texture loading and honestly thanks to STBImage that's very easy but while testing I noticed something.
When drawring a 16x16 texture to a 200x200 surface/rect t's not sampling properly (atleast I think that's the term for it) like here
http://imgur.com/ovO445w
Notice the texture on the bottom left and the pixels that should be somewhere and are somewhere else
This is the code used for loading the textures https://gist.github.com/MasterAbdoTGM50/a2cfacf6a1228282a4ac
And this is the texture I'm using https://drive.google.com/file/d/0B2yLjDX_QRq9akVTUlFUaEhKbU0/view?usp=sharing
Thanks you for reading and sorry if I wasted your time

*

Kai

Re: Texture Not Sampling Properly. Least I think it is
« Reply #1 on: February 08, 2016, 09:45:54 »
Looks correct to me. Texture is displayed as it is. How do you want it to look like?
And what pixels are you referring to "that should be somewhere and are somewhere else?"

If you want the texture to be displayed over your whole viewport, then you likely just have an issue with your viewport and/or projection transformation.
First, whenever the window gets resized, make sure to also update the viewport transformation via a call to GL11.glViewport().
Next, remember that every vertex within x = [-1..+1] and y = [-1..+1] is going to be mapped to the viewport.
So when you simply want to draw a fullscreen rectangle, the simplest thing you can do is to specify two triangles using -1.0 and +1.0 for their corners.
In case you use Matrix4f.ortho/setOrtho/ortho2D/setOrtho2D() then remember that all those methods do is creating a transformation matrix that scales and translates the specified range of x and y values to the range [-1..+1].

Re: Texture Not Sampling Properly. Least I think it is
« Reply #2 on: February 08, 2016, 15:05:16 »
Sorry for not being so clear. The problem isn't in the projection matrix or the viewport but in weird pixels appearing this is the rendered texture. If you look at it it has some weird pixels appearing
This is a better view http://imgur.com/ZbRUeXJ
It only happened when I rendered it to a 200x200 rect. Even weird sized like 369 and 247 look right but not this one
It's a silly and weird question and probably unnecessary but it's driving me crazy to know

*

Offline abcdef

  • ****
  • 335
Re: Texture Not Sampling Properly. Least I think it is
« Reply #3 on: February 08, 2016, 16:17:24 »
Because of the odd sizes maybe try and set your texture property to

glPixelStorei(GL_UNPACK_ALIGNMENT, 1)

Re: Texture Not Sampling Properly. Least I think it is
« Reply #4 on: February 11, 2016, 15:06:36 »
GL11.glTexParameteri(int, int); Should fix this.

Code: [Select]
glBindTexture(GL_TEXTURE_2D, tid);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, bb);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glBindTexture(GL_TEXTURE_2D, 0);