c++openglgldrawpixels

glDrawPixels puts each RGB component in a different pixel


As the title says, Red Green And Blue values are put into different slots, making the screen have stripes of red green and blue. the code is pretty much: (w and h are width and height...)

unsigned int pixels[w * h * 3];
for (unsigned int i = 0; i < w * h * 3; i+=3) {
    pixels[i + 0] = 0xff // Red
    pixels[i + 1] = 0xff // Green
    pixels[i + 2] = 0xff // Blue
}
while(windowIsOpen()) {
    glClear(GL_COLOR_BUFFER_BIT);
    glDrawPixels(w, h, GL_RGB, GL_UNSIGNED_BYTE, pixels);
    glSwapBuffers();
}

But, this produces and image like this when it should be all white: Not what I want

Any help would be amazing! I know glDrawPixels is deprecated but I need an easy way to draw pixels on the screen, performance isn't an issue for this project.


Solution

  • Please note that you are using a buffer of ints (sizeof(int) = 4 ) while you are telling your opengl that you are sending UNSIGNED_BYTE (sizeof(char) = 1).

    Change your buffer from int to char and see if everything goes fine.