Jump to content

  • Log In with Google      Sign In   
  • Create Account

[Solved] Simple GLSL Texture Troubleshoot


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 notyourbuddy   Members   -  Reputation: 111

Like
0Likes
Like

Posted 17 October 2012 - 03:01 PM

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?

Sponsor:

#2 beans222   Members   -  Reputation: 1169

Like
2Likes
Like

Posted 17 October 2012 - 05:25 PM

You can set _colorOut directly to the results of the texture call. An rgb texture made of unsigned bytes is a normalized format and will return 0.0-1.0 in the shader.

New C/C++ Build Tool 'Stir' (doesn't just generate Makefiles, it does the build): https://github.com/space222/stir

 


#3 Geometrian   Crossbones+   -  Reputation: 1601

Like
2Likes
Like

Posted 17 October 2012 - 06:38 PM

Did I forget a step in initializing my texture? Am I incorrectly accessing texels in my fragment shader?

http://www.opengl.org/wiki/Common_Mistakes#Creating_a_complete_texture
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.

#4 notyourbuddy   Members   -  Reputation: 111

Like
0Likes
Like

Posted 17 October 2012 - 08:46 PM

You can set _colorOut directly to the results of the texture call. An rgb texture made of unsigned bytes is a normalized format and will return 0.0-1.0 in the shader.


Ah cool. Did not know that. Good to know.

#5 notyourbuddy   Members   -  Reputation: 111

Like
0Likes
Like

Posted 17 October 2012 - 08:47 PM

Did I forget a step in initializing my texture? Am I incorrectly accessing texels in my fragment shader?

http://www.opengl.or...omplete_texture


Aye that did it. <facepalm>

Posted Image




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS