Hy,
First of all, I just want to say that am very new to opengl programming…
I want to be able to write and read 8bit integer colors, but I can’t get it to work
I have a very simple scene with no lights, textures, etc… just objects in color… if that makes sense… but so far I can only get float color with this:
# Position
glEnableVertexAttribArray(0) # position
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 24, ctypes.c_void_p(0))
# Color
glEnableVertexAttribArray(1) # color
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 24, ctypes.c_void_p(12))
and this:
layout (location=0) in vec3 vertexPos;
layout (location=1) in vec3 vertexColor;
uniform mat4 model;
uniform mat4 projection;
out vec3 fragmentColor;
void main()
{
gl_Position = projection * model * vec4(vertexPos, 1.0);
fragmentColor = vertexColor;
}
and then in the vertex shader I just add 1.0 to “vec4 fragmentColor”.
When I want to use 8bit color as this:
glVertexAttribPointer(1, 1, GL_BYTE, GL_FALSE, 13, ctypes.c_void_p(12))
or
glVertexAttribIPointer(1, 1, GL_BYTE, 13, ctypes.c_void_p(12))
it doesnt work, and I don’t understand why.
I assume that the stride should be just 13 because the GL_BYTE is just one byte more… is this correct?
If I use glVertexAttribIPointer() and not glVertexAttribPointer(), can I still use vec3 in the shader, assuming that then I use 8 bits for each component, or do I have to use int or uint in the shaders?
would then I have to do this:
glVertexAttribIPointer(1, 3, GL_BYTE, 15, ctypes.c_void_p(12))
If I could write 8bit color, how can I read back the same 8bit color with glReadPixels() … is that even posible? or no matter what you use for color it will always be converted to float, and you wont be able to read it as it was?
I want to use this for picking/selecting objects. Is there maybe another way to store some data and read it back with glReadPixels(). It should be at least 8bits of data