To get colour from a 3Dcube

Hi, all!
Please, help me!
I have created 3D cube, using OpenGl. I can rotate and scale it.
When i click on any side of the cube, i need to get a color of this side. How can i make it?
Thx!!!

Since you have drawn the cube, you know what colors you have put on each side.
Just look at how much you have rotated the cube and figure out what side is facing the camera when the mouse button is pressed.

Example:
rotation_x = 0; rotation_y = 0; Front of cube facing user.
rotation_x = 90; rotation_y = 0; Left side of cube facing user.
rotation_x = 0; rotation_y = 90; Top of cube facing user.

You also may want to look at object picking, see nehe.gamedev.net for an example of that.

Originally posted by GMV:
Hi, all!
Please, help me!
I have created 3D cube, using OpenGl. I can rotate and scale it.
When i click on any side of the cube, i need to get a color of this side. How can i make it?
Thx!!!

[This message has been edited by nexusone (edited 05-16-2002).]

Thx.
What i must to do, to get colour of a point when i click mouse on the cube?

wouldn’t it be better to use selection?

How i can make it?

look up glReadPixels.

b

I think that you have not been clear on what you want to do?

Are you wanting to get the color of a pixel on the screen?
Or just the color of the side of the cube that is clicked on?
If you want to get the color of the side clicked on, then my last message explains that.

Originally posted by GMV:
[b]Thx.
What i must to do, to get colour of a point when i click mouse on the cube?

[/b]

He’s not assuming every side is a solid color. He wants to know how to click on any point on the cube and get the color there.

Which I suppose would be glReadPixels but he’d probably also need to use a bounding box to make sure he’s clicking on the cube and not the background or another object.

Ok, then check your mouse coordinates against a simple bounding box, provided the click is in the box, proceed to read the frame buffer within the bounding box into an array, then just use the mouse position to extract (I imagine) R G and B values.

Nothin’ but net.

Certainly not the only way to do it but one of the more direct ways.