I'm working on a small pet project and I have a 1d array of RGB colours that are packed using this method:
int rgb = (((unsigned int)r) << 16) | (((unsigned int)g) << 8) | b
And the image data is stored in the array like this
int x, y;
for (x = 0; x < img->w; ++x) {
for (y = 0; y < img->h; ++y) {
img->buf[(y) * img->w + (x)] = color;
}
}
I don't understand OpenGL well enough to understand how to get the data into a texture buffer. This is what I use to get the data uploaded, but obvious this just results in a weird looking black and white mess.
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, test->w, test->h, 0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)test->buf);
I tried messing around with glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
and different texture format options for glTexImage2D
but nothing seems to work. I've seen this thread: Colour bit-wise shift in OpenGL shader GLSL which seems to be similar, I just don't understand how to get to that point.
Can anyone help?