Get pixel Coordinates

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Get pixel Coordinates

elseine
Hello everybody.

I have a project where I am doing a simple graph. I have boxes and splines (Bezier curves) in it. Inside each box I need to put some text. I try with TextRenderer but uses pixel coordinates instead of canvas coordinates.

I am thinking in get the canvas coordinates for each box, and use it to put the text correctly.

How can I get the pixel coordinates from an object that I draw?

Thanks for your time!
Art
Reply | Threaded
Open this post in threaded view
|

Re: Get pixel Coordinates

Art
You can use project to translate scene coordinates to view coordinates (world to screen).  I thought I had project in a utility. But I only found the unproject ones. Which goes from view to scene (screen to world).

https://github.com/pnnl/svf/blob/master/svf/src/main/java/gov/pnnl/svf/util/SceneCoordsHelper.java 
Reply | Threaded
Open this post in threaded view
|

Re: Get pixel Coordinates

elseine
Sorry but I dont understand you :/
Reply | Threaded
Open this post in threaded view
|

Re: Get pixel Coordinates

elect
What do you mean by pixel and canvas coordinates?
Reply | Threaded
Open this post in threaded view
|

Re: Get pixel Coordinates

elseine
World and Screen coordinates.

I have a box that use World Coordinates (coordinates inside GL) in the draw. Now, I want to put text inside the box. To that I want to use TextRenderer. The problem is: TextRenderer use Screen Coordinates, not World Coordinates. I need to know: if the box is inside the screen; and the screen's coordinates of that box, not the world coordinates.

I dont know if I explain well.

Reply | Threaded
Open this post in threaded view
|

Re: Get pixel Coordinates

elect
This post was updated on .
elseine wrote
World and Screen coordinates.
You just need to perform the inverse of the multiplication by yourself: world space * camera/view matrix = camera/view space * projection = clip space / position.w = NDC space * glViewPort = window/screen coordinates

or follow Art suggest and google for unproject
Art
Reply | Threaded
Open this post in threaded view
|

Re: Get pixel Coordinates

Art
The link I posted has code that does unproject. Which is converting from screen to world coordinates. All you have to do is create methods, like the unproject ones, using glProject instead. They take a few different parameters, but are essentially the same.