简体   繁体   中英

GLSL renders texture as black and blue

I'm trying to render a texture with openGL and GLSL. The texture is supposed to be rendered on a floating cube.

texture: http://imgur.com/Actqtx1

result: http://imgur.com/MXIOEvS

The cube is a strange mix of blue and black. Even when I try other textures, the result is the same. In the screenshot above, I have rendered a plane using "fract(worldspace" to ensure that the shaders are working.

It is apparent that the "color = texture(myTextureSampler, UV).rgb;" is producing the wrong color, but I do not know why. The texture coordinates and texture data appear to be read and buffered correctly.

Has anyone seen this effect before? Does anyone know where my problem may lie? I can provide code snippets upon request.

You're looking in the wrong direction. It's not your shader that's wrong (well maybe it is). Your problems start much earlier in the texture loading process.

You see how your texture seems to be strangely skewed. That usually happens if the alignment and pixel row strides have not been properly set before calling glTexImage, see glPixelStorei(GL_UNPACK_…,) parameters.

The other problem I see is, that whatever you loaded into OpenGL has no resemblence of your original picture whatsoever. It looks like bitnoise. That is telling me, that you're probably feeding some compressed data, or maybe even a picture file as it is to OpenGL.

OpenGL does not know how to deal with image file formats. There are a few special compression formats it knows, but these are compression formats as used by GPUs to reduce memory bandwidth requirements, not something like PNG or JPEG.

If you don't have one of the special texture compression format at hand OpenGL expects a raw pixel array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM