Learn how to a build a cloud-first strategyRegister Now

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 554

# pixel operations

Hi,
can you advise me how to code this in C++ (opengl)?

1) I need to find out how many pixels are on the screen (what's the resolution)
2) I need to find out 3D coordinate of every pixel
3) I need to find out how to draw pixels of various colors on the screen.

// my pseudocode.
// I simplified it. This pseudocode looks a little strange. But if I know how to code this, I can continue with other things.
//Somewhere in the 3D space there is some 3D object. I want to determine the color of every pixel. This color is depending on the //distance between the pixelCoordinate and the point on the 3d object. (this two points have the same z coordinate).

determineTheNumberOfPixels;
for each pixel do {
if (distance() == infinity) pixelColor = black;
if (distance() > 20 ) pixelColor = red;
else pixelColor = blue;
} endfor

DrawPixelsOnTheScreen;

distance() returns the distance I described above, you don't have to concern with it. (black box for you, which do the correct thing).

thanks everybody for help
0
xRalf
• 4
• 3
1 Solution

Commented:
xRalf,

For the moment, just the resolution question.  This is determined outside of openGL by using the Win32 call http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsystemmetrics.asp ["GetSystemMetrics"]

corey
0

Author Commented:
Sorry, I forgot to note that I'm programming in Unix
0

Commented:
Have you tried using something like: XGetGeometry ?  For parameter information type: 'man XGetGeometry'

corey
0

Author Commented:
I found library Open Producer. (I want my program to be platform independent.) But I can't figure out how to code my pseudocode.
0

Commented:
Well. probably the best way to do cross-platform development with OpenGL is to use a library like Qt or something that does the window creation for you.

As for part 2 and 3 of your question, do you have any sort of engine at all?  You cannot just get 3D coordinates of random pixels without a 3D scene and engine running.

corey
0

Author Commented:
I'm using the osg library (www.openscenegraph.org). There's a function osgDB::readNodeFile(const std::string& str) where str is a file file.osg in which is defined the 3d scene.
0

Commented:
xRalf,

That osg library seems to support the cross-platform development you want, so you're probably good there.

Now, looking through their documentation for the appropriate projection data for you to take 2D screen coordinates into the 3D world.  You need to look at the osgUtil::SceneView class documentation for the methods like: projectWindowIntoObject, projectWindowXYIntoObject.

These will essentially unproject the 2D point back out into 3D space.

corey
0

## Featured Post

• 4
• 3
Tackle projects and never again get stuck behind a technical roadblock.