Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: drawing individual pixels with opengl  (Read 2027 times)

0 Members and 1 Guest are viewing this topic.

genzm

  • Newbie
  • *
  • Posts: 26
    • View Profile
drawing individual pixels with opengl
« on: June 11, 2013, 05:13:47 pm »
Hy,
As the title suggests I wanted to draw individual pixels to the screen. I've come a long way, but this is the essential code I've got now:
int main() {
        glewExperimental=GL_TRUE;
        glewInit();
        GLuint BUFFER;
        glGenBuffers(1,&BUFFER);
        glBindBuffer(GL_PIXEL_UNPACK_BUFFER,BUFFER);
        glBufferData(GL_PIXEL_UNPACK_BUFFER,WIDTH*HEIGHT,NULL,GL_DYNAMIC_DRAW);
        unsigned char* buffer_map = (unsigned char*) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
        fill_buffer(buffer_map, WIDTH, HEIGHT,objects);
}

void fill_buffer(unsigned char* buffer, unsigned int width, unsigned int height) {
        for (unsigned int pixelX = 0; pixelX < width; ++pixelX) {
                for (unsigned int pixelY = 0; pixelY < height; ++pixelY) {
                        buffer[pixelX*height+pixelY] = 255;
                }
        }

        glDrawPixels(width,height,GL_RED,GL_UNSIGNED_BYTE,buffer);
}
 

It seems to work right. The buffer is intitialised correctly, plus it is loaded with the right values (as an test I just wanted to fill my screen with red). However though, the screen stays black, instead of being red.
Anyone a suggestion why this would be?

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: drawing individual pixels with opengl
« Reply #1 on: June 12, 2013, 06:59:52 pm »
You are filling the buffer but you aren't flipping the buffer to the screen.  I think there's a Swapbuffers() you want to call at the end.  Can't remember the exact name of it but it's something like that.

 

anything