Framebuffer Sizes

I am currently working on determining the color of a point where the mouse clicks at, by reading a given point in the color buffer.

The problem I’m having, is I can’t seem to find any reference anywhere as to how to determine the size of the color buffer… i.e. what the width and height of the buffer are to know by what degree to adjust the mouse coordinates.

Any suggestions on where to find / calculate this value would be appreaciated… Thanks!

  • Bryon

The size is in pixels, and the left-bottom corner is 0, 0.

Just plug your coordinate in glReadPixels.

The color buffer size is the same as for your opengl window.

V-man

I know how to read bytes and all, but is there a way to test for the actual size of the buffer, or do we just assume the buffer re-sizes itself automatically…

I’m thinking that perhaps the glViewport() command is what sets the buffer sizes, but I never actually call the command, and the window resizes itself automatically when I change window size… unless the library I’m using calls glViewport() for me (I’m using the wxWindows library, and their wxOpenGL built-in support)…

Thinking that it may do this, I was really looking for a way to know for sure what the height and width of the color buffer I’m reading from was, or if I try and read a point that’s outside that buffer, will I get an error of some type, or a perdictable constant return?

Thanks

glViewport just tells OpenGL to what part of the of the window you want to draw. The frame buffer is as large as the window, and is resized when the window is resized.

I don’t think it’s possible to as OpenGL the dimensions of the frame buffer, only the viewport, but you usually get the dimensions from the window handler when you resize the window. Just put these values in some variables and read them from there when you need them.