Placing pixels in 3D space and user rotation

I just started learning a bit of OpenGL yesterday and learned how to make a box and rotate in 3D space.

Lets say I have a (x,y,z) of every pixel in a 640x480 picture. I then want it to have a certain RGB color.
What would be the function to put a pixel in 3D space?

After placing all the pixels, I want the user to be able to rotate and zoom. How would I be able to implement this?

I just got the 4th and 5th edition of the opengl superbible. Where would I be able to find it in the book?


Pixel cannot be in 3D space! You can arrange objects, lines or points in 3D space, but not pixels. Pixels are “survived” fragments that even don’t have depth. Just screen coordinates and the color.

Start from the very beginning. You need to learn some very important concepts used in 3D graphics first.

Hmm, if I have the (x,y) coordinates of the pixel, can’t I place it in a 3D space by placing it in some z direction?

something like this:

or more advanced like this:

Just posting in case someone googles this.

Haven’t tried it yet but
glDrawPixels() allows you to draw pixels from given data.

Then glRasterPos() allows you to set the 3D coordinate of where glDrawPixels will be drawn.


Don’t even try. If you just take a look at the specification of those function you’ll find they cannot satisfy your needs.

glDrawPixels() writes a block of pixels to the frame-buffer. How do you think you can access those pixels after being written into the frame-buffer?

glRasterPos() specifies the raster position for pixel operations, like glBitmap(). It was useful long time ago to draw text in OpenGL. But it was impractical since it was subjected to model-view/projection transformations. glWindowPos() came with GL 1.4 and enabled expressing positions in screen coordinates, and made life much easier.

My friendly advice: Please, take some good OpenGL book and grab some of the fundamental concepts of 3D graphics and OpenGL.

A quick tip: Use VBO to draw your points (NOT pixels, BUT points), and draw them with glDrawArrays(GL_POINT,…). Define color of the points by using their z-value, or you won’t see anything recognizable. After mastering this, go forth and generate a mesh using those points. I saw similar questions on this forum, so take a look at them.

Thanks for the help Alexsandar.

I’m doing a project and have been trying to skip fundamental 3D concepts to get certain parts done. I really should start from the beginning of the book but I’ll read the chapter on “Faster Geometry Output” and if I am completely lost, which I probably will be, I’ll start from the beginning.