简体   繁体   English

GLSL 将纹理渲染为黑色和蓝色

[英]GLSL renders texture as black and blue

I'm trying to render a texture with openGL and GLSL.我正在尝试使用 openGL 和 GLSL 渲染纹理。 The texture is supposed to be rendered on a floating cube.纹理应该在浮动立方体上渲染。

texture: http://imgur.com/Actqtx1质地: http : //imgur.com/Actqtx1

result: http://imgur.com/MXIOEvS结果: 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.在上面的屏幕截图中,我使用“fract(worldspace”) 渲染了一个平面,以确保着色器正常工作。

It is apparent that the "color = texture(myTextureSampler, UV).rgb;"很明显,“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.如果在调用 glTexImage 之前没有正确设置对齐和像素行步长,通常会发生这种情况,请参阅glPixelStorei(GL_UNPACK_…,)参数。

The other problem I see is, that whatever you loaded into OpenGL has no resemblence of your original picture whatsoever.我看到的另一个问题是,您加载到 OpenGL 中的任何内容都与您的原始图片没有任何相似之处。 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 提供一些压缩数据,甚至可能是图片文件。

OpenGL does not know how to deal with image file formats. OpenGL 不知道如何处理图像文件格式。 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.它知道一些特殊的压缩格式,但这些是 GPU 用来降低内存带宽要求的压缩格式,而不是像 PNG 或 JPEG 这样的压缩格式。

If you don't have one of the special texture compression format at hand OpenGL expects a raw pixel array.如果您手头没有一种特殊的纹理压缩格式,OpenGL 需要一个原始像素数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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