views:

385

answers:

2

Hi, I am very new to OpenGL ES. I am implementing some demo app to load multiple textures on the screen. For demo purpose I have loaded 2 textures in 2 different locations on the screen using glTranslatef() and glBindTextures() twice.

Now I am able to see 2 different images on the screen. Now I want to move one particular texture across the screen using mouse.

I know it may be silly topic, but please help me in this..

Thanks in advance..

A: 

Hi,

You don't actually want to move the texture, but either you move your Scene point of view ( gluortho2d / glulookat / gltranslatef - or anything else ), or you move the vertices of the shape you're applying your texture to.

this is how im doing it in my 2D game :

gl.glTranslatef(-cameraPosX % 32, -cameraPosY % 32, 0);

Dullahx
thanks for the reply...but my requirement is like I am enabling dragging feature for this.means... If I press and hold one texture and move across the screen, that texture only has to move and other texture should stay at its current location and vise versa...For this I think I need to recognize the texture independently and transform the pixel location to Open GL coordinates.If my problem seems to be very basic and I need to really go through some opengl ES tutorial, then please direct me to that by providing some good link...Thanks in advance...
Andhravaala
I understand your point.i didn't dig deep enough into touchscreen handles, so i can't help you on that one. However, i must insist, you don't want to move the textures themselves, but rather the 'shape' you're applying your textures to (ie game object if you're designing a game) by changing his vertices coordinates.Please check nehe tutorials here : http://nehe.gamedev.net/ , and specially the android port here : http://insanitydesign.com/wp/projects/nehe-android-ports/
Dullahx
ok ...any way Thank you for the links ... :)
Andhravaala
welcome :) i will implement TouchScreen controls in my game sooner or later, maybe i'll drop and answer there when i figure out most of the useful stuff :)
Dullahx
A: 

As mentioned above you will need to translate the coordinates of the surface.

If you are using orthagonal (2D) projection, the pixel/coord ratio can be set to 1:1 easily by defining the projection to be the same size as the screen. For example:

 glOrthof(0.0f, screenWidth, -screenHeight, 0.0f, -1.0f, 1.0f);

should define a projection with (0,0) in the top left and the same size as your screen.

If you are using 3D projection, you may find this link helpful: http://www.mvps.org/directx/articles/rayproj.htm

Sam
Thank you very much for the reply... I think I better try with Ortho insteadof projection(I am using glFrustumF, I think it is for 3D).
Andhravaala