PDA

View Full Version : Problem with setup glTexImage2D data with GL_UNSIGNED_BYTE and GL_NEAREST



balezin
03-13-2017, 06:30 PM
2345 2346

On the first image it is present the result when I am using GL_UNSIGNED_BYTE:



glVertexAttribPointer(texcoord_attrib_index, 2, GL_UNSIGNED_BYTE, GL_TRUE, 0, NULL);
...
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture.w, texture.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture.data);
glGenerateMipmap(GL_TEXTURE_2D);


When I am using UV coordinates with GL_FLOAT [0.0 - 1.0] - it is all ok (second image), and GPU cutting textures from the image correctly. But when I am using GL_UNSIGNED_BYTE format [0 - 255] I can't cut image textured fragment exactly at the pixel boundary. What is wrong?

mhagain
03-14-2017, 02:48 AM
Unsigned bytes don't go from 0...265, they go from 0...255.

balezin
03-14-2017, 04:09 AM
mhagain

Unsigned bytes don't go from 0...265, they go from 0...255.

Yes, 256 - it is first bit from the second byte. We have 256 digits from 0 to 255. Thank you.