opengl-tutorials / ogl

http://www.opengl-tutorial.org
2.69k stars 925 forks source link

Tutorial 05: Texture incomplete on cube #106

Closed b1060t closed 3 years ago

b1060t commented 4 years ago

I pasted the buffer data and the uv data to make sure they were correct. However all of the numbers except '4' and '6' are missing with white background left. I am using third-party image loading library. So I tried again using stb_image to load texture, but the result is just the same. Also, I modified several data in uv array, and some parts of the other number appeared. Any idea where the problem is? Is it possible that my tga file was loaded with wrong coordinates?

temp

carlHR commented 3 years ago

Hi there,

So, I am going through the tutorials right now, implementing everything from scratch. I've seen that the cube using the textures I've also made myself was wrong as well.

The problem is actually with the common/texture.cpp script.

Line 61:

// Read the actual data from the file into the buffer
fread(data,1,imageSize,file);

Should have this command as well, to use the dataPos variable:

// Use the dataPos offset inside the file
fseek(file, dataPos, SEEK_SET);

// Read the actual data from the file into the buffer
fread(data,1,imageSize,file);

With this additional line, this issue should have been fixed.

Note: I tried this using the loadBMP_custom() given in the tutorial, to load BMP files only. Didn't tried anything with other texture loaders (DDS or TGA).

Carlos HR.

b1060t commented 3 years ago

Thanks. I'll try this later since I've turned to another opengl tutorial.

GabrielLins64 commented 8 months ago

Hi. I know this is already closed, but about the mentioned DDS texture issue, I came across a stack overflow answer where basically the contributor explains that "DDS has a different-D3D-based coordinate system compared to OpenGL, so we either invert the y component of the UV-coords in the fragment shader or invert the image before compressing it".

So, I solved by replacing, in the SimpleFragmentShader.glsl:

color = texture(myTextureSampler, UV).rgb;

by

color = texture(myTextureSampler, vec2(UV.x, 1.0-UV.y)).rgb;