Jump to content
  • Advertisement
Sign in to follow this  
EasyCoder

OpenGL How to translate relative position to pixel position

This topic is 2635 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there any way in OpenGL ES how to translate (convert) a relative position of the object (vertices) determined by glTranslatef to actual pixel position on the display ?

This could be very useful for selecting objects by touch.

Share this post


Link to post
Share on other sites
Advertisement
does glGetFloatv works? you can always get the modelview and world matrix yourself and multiply it with a 3d coordinate to get 2d projection.

Share this post


Link to post
Share on other sites

does glGetFloatv works? you can always get the modelview and world matrix yourself and multiply it with a 3d coordinate to get 2d projection.


Same as above - not in ES subset.

Share this post


Link to post
Share on other sites

[quote name='FXACE' timestamp='1316521276' post='4863785']
see gluProject.


gluProject isn't in OpenGL ES subset - any other ideas which I cannot use ? :D
[/quote]
I'm wondering what OpenGL ES has?.... only glBegin/glEnd?  :D

If glLoadMatrix supported in GL ES, so there is one way: to compute projection matrices by yourself (or get the source code of required functions of OpenGL from Mesa3D and try to put it to your application. It contains the implementation of glOrtho, gluPerspective, ...).

Share this post


Link to post
Share on other sites

[quote name='EasyCoder' timestamp='1316523863' post='4863791']
[quote name='FXACE' timestamp='1316521276' post='4863785']
see gluProject.


gluProject isn't in OpenGL ES subset - any other ideas which I cannot use ? :D
[/quote]
I'm wondering what OpenGL ES has?.... only glBegin/glEnd? :D

If glLoadMatrix supported in GL ES, so there is one way: to compute projection matrices by yourself (or get the source code of required functions of OpenGL from Mesa3D and try to put it to your application. It contains the implementation of glOrtho, gluPerspective, ...).
[/quote]

Actually ... OpenGL ES does not support glBegin/glEnd :lol:

But it has glLoadMatrix - could you please elaborate in more detail how you would go about doing it ?

Thanks.

Share this post


Link to post
Share on other sites

[quote name='FXACE' timestamp='1316540123' post='4863899']
[quote name='EasyCoder' timestamp='1316523863' post='4863791']
[quote name='FXACE' timestamp='1316521276' post='4863785']
see gluProject.


gluProject isn't in OpenGL ES subset - any other ideas which I cannot use ? :D
[/quote]
I'm wondering what OpenGL ES has?.... only glBegin/glEnd?  :D

If glLoadMatrix supported in GL ES, so there is one way: to compute projection matrices by yourself (or get the source code of required functions of OpenGL from Mesa3D and try to put it to your application. It contains the implementation of glOrtho, gluPerspective, ...).
[/quote]

Actually ... OpenGL ES does not support  glBegin/glEnd :lol:

[/quote]

:rolleyes: ................................





But it has glLoadMatrix - could you please elaborate in more detail how you would go about doing it ?



I mean to do matrix calculations by yourself (without using built-in GL ES functions like glMultiMatrix, glOrtho or other similar functions (if ES supports them  :))) (when you want to render the object with it's transformation set it by using glLoadMatrix for it):



MyMatrixClass my_matrix; // create your own class which works with GL standart matrices

my_matrix.loadIdentity(); // instead of using glLoadIdentity

my_matrix.ortho(0,0,250,250,-1,1); // instead of using next call glOrtho [src/mesa/math/m_matrix.c]

.......................................

glLoadMatrix(my_matrix.getData()); // put the (column-major order) matrix of "my_matrix" to GL

render_primitives();// bla bla



So, check out OpenGL Mesa (Software Driver with source code).

1. get gluProject from archive "src/sgi/libutil/project.c".

2. convert code syntax it to Java (because its C++ language)... (as how you like it)

3. and use it as how documentation shows.




- any questions?




Share this post


Link to post
Share on other sites
[quote name='FXACE']
:rolleyes: ................................
[/quote]

OpenGL ES, like Core profile, move away from the outdated immediate mode rendering style.

Share this post


Link to post
Share on other sites

So, check out OpenGL Mesa (Software Driver with source code).

1. get gluProject from archive "src/sgi/libutil/project.c".

2. convert code syntax it to Java (because its C++ language)... (as how you like it)

3. and use it as how documentation shows.



Looks like lot of work for such a simple thing, but thank you anyway. If nobody suggests anything simpler, I will try it.

What I am basically trying to achieve is to select objects by touching them.
There is another method (picking by colour), which seems to be easier and more straightforward, but I cannot get it working either :blink:
You seem to be quite good with OpenGL, Chris (I am just starting). Could you please have a look at this code, whether you don't see what I am doing wrong ?

http://www.gamedev.n...pixels-in-java/

Many thanks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!