简体   繁体   中英

Moving image on OpenGl using px?

I am using OpenGl to draw an image. Now when i try to move the image, it moves by too much. So if i say the following:

gl.glTranslatef(0, 1, -5.0f);
squirrel.draw(gl);

If i out one as a parameter, the image is now located half way of screen. How do i make it so i can say things like:

gl.glTranslatef(screen_width - image_width , 0);

Is there an alternative method for drawing images in OpenGl? I previously used canvas to draw images, and i had no problem positioning images on the screen. However with openGl i'm experiencing issues.

All you need to remember is, the screen space in OpenGL ranges from -1,-1 (top left), and 1,1 (bottom right). So you need to provide normalized values to OpenGL. To move a point along x direction from one end of the screen (-1.0) to another (1.0), left to right, you will have to Translate by 2.0 by using glTranslatef(2.0, 0, 0). This point is on the border, so you will have to adjust depending on the actual size of your object and its location.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM