How to translate relative position to pixel position

Started by
16 comments, last by EasyCoder 12 years, 6 months ago
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.
Advertisement
see gluProject.

see gluProject.


gluProject isn't in OpenGL ES subset - any other ideas which I cannot use ? :D
does glGetFloatv works? you can always get the modelview and world matrix yourself and multiply it with a 3d coordinate to get 2d projection.

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.

[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 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.

[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?




[quote name='FXACE']
:rolleyes: ................................
[/quote]

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

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.

This topic is closed to new replies.

Advertisement