I want to render a unsigned integer texture with fragment shader using following code:
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8UI, width, height, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, data);
and part of the fragment shader code:
#version 330
uniform usampler2D tex;
void main(void){
vec3 vec_tex;
vec_tex = (texture(tex), TexCoordOut).r
}
It is written in OpenGL Programming Guide, that if I want to receive integers in shader, then I should use an integer sampler type, an integer internal format, and an integer external format and type. Here is us GL_R8UI
as internal format, GL_RED_INTEGER
as external format, GL_UNSIGNED_BYTE
as data type. I also use usampler2D
in shader. But when the program starts to render the file, always got error implicit cast from "int" to "uint". It seems that the texture data is stored as int, and the unsigned sampler can not convert that. But I did use GL_R8UI
as internal format, so the texture data should be stored as unsigned. why the unsigned sampler only get signed int? How can I solve this problem?
vec3
is floating-point, right? If you want to store the results of fetching from ausampler2D
, you should probably useuvec3
. Even then, if this is literally your shader it should be generating a more serious error than that.texture (...)
requires texture coordinates andTexCoordOut
is not even defined. – Andon M. Coleman