Solved

# pixel operations

Posted on 2005-04-17
548 Views
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
Question by:xRalf

LVL 8

Expert Comment

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

LVL 6

Author Comment

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

LVL 8

Expert Comment

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

corey
0

LVL 6

Author Comment

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

LVL 8

Expert Comment

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

LVL 6

Author Comment

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

LVL 8

Accepted Solution

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

### Suggested Solutions

USB HID read speed 3 580
Any Java JFrame panel advice? 1 404
Unity 3D Lighting 1 72
Recording what a camera sees for future playback. 5 29
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…