Just starting out with OpenGL so this is a very simple problem,
I'm trying to load a 64x64 24-bit BMP (all pixel values are set to 235 [a light grey tone]) and access it in a fragment shader, however, all I seem to get are black pixels and not particularly sure why. Will keep investigating, but figured I'd ask the experienced if they know where I've gone wrong.
My basic program flow is as follows:
[source lang="cpp"]GLuint t;glGenTextures(1, &t);glBindTexture(GL_TEXTURE_2D, t);glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, data);glLinkProgram(obj); glUseProgram(obj);glActiveTexture(GL_TEXTURE0);glBindTexture(GL_TEXTURE_2D, t);GLint loc = glGetUniformLocation(obj, "_heightfield");glUniform1i(loc, 0);Render()[/source]
My fragment shader:
[source lang="cpp"]#version 400uniform sampler2D _heightfield;layout(location = 0) out vec4 _colorOut;void main(void){ vec4 h = texture(_heightfield, vec2(0.5, 0.5)); // trying to grab the center texel _colorOut = vec4(h[0]/255.0, h[1]/255.0, h[2]/255.0, 1.0); //_colorOut = vec4(235.0/255.0, 235.0/255.0, 235.0/255.0, 1.0);}[/source]
The image data in the "data" array is being loaded correctly. The shader program has linked successfully and the fragment shader produces the correct results if I hardcode in the color values, however, when I try to pull texels out of the texture as I mentioned the result is just black pixels as opposed to the 235 grayscale tone from my texture.
Did I forget a step in initializing my texture? Am I incorrectly accessing texels in my fragment shader?
[Solved] Simple GLSL Texture Troubleshoot
Started by notyourbuddy, Oct 17 2012 03:01 PM
4 replies to this topic
Sponsor:
#3 Members - Reputation: 1029
Posted 17 October 2012 - 06:38 PM
http://www.opengl.org/wiki/Common_Mistakes#Creating_a_complete_textureDid I forget a step in initializing my texture? Am I incorrectly accessing texels in my fragment shader?
And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
#5 Members - Reputation: 107
Posted 17 October 2012 - 08:47 PM
http://www.opengl.or...omplete_textureDid I forget a step in initializing my texture? Am I incorrectly accessing texels in my fragment shader?
Aye that did it. <facepalm>






