Learn how to a build a cloud-first strategyRegister Now

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

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
Asked:
xRalf
  • 4
  • 3
1 Solution
 
_corey_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
 
xRalfAuthor Commented:
Sorry, I forgot to note that I'm programming in Unix
0
 
_corey_Commented:
Have you tried using something like: XGetGeometry ?  For parameter information type: 'man XGetGeometry'

corey
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
xRalfAuthor 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
 
_corey_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
 
xRalfAuthor 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
 
_corey_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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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