Hello everyone,
I’m trying to render a 2D texture using glTexImage2D and an array of pixels but my problem is that just one color is rendering.
As you can see, I set the values of screenData (pixels) at random in order to see if the code is working but instead of drawing a lot of different color pixels
I get only the last code setted or something like that. Always one color only.
And for example, if I called glTexSubImage2D with screenData but one pixel modified, the whole texture color changed.
This is the code for the 2D texture:
srand(20312);
// Clear screen
for(int y = 0; y < SCREEN_HEIGHT; ++y)
for(int x = 0; x < SCREEN_WIDTH; ++x)
{
screenData[y][x][0] = rand() % 255;
screenData[y][x][1] = rand() % 255;
screenData[y][x][2] = rand() % 255;
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
//Generate a texture and holds the ID in blackboard
glGenTextures(1, &blackboard);
//Set the current texture in order to modify it
glBindTexture(GL_TEXTURE_2D, blackboard);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1280, 720, 0, GL_RGB, GL_UNSIGNED_BYTE, screenData);
I hope you can help me.