Jump to content
  • Advertisement
Sign in to follow this  
afkboard

OpenGL OpenGL ES setPosition

This topic is 2804 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

Hi,

I have simple 2D textured rects on which I want to put other textured rect as button. I tried to write something like:


void setPosition(float x, float y)



method, so that when the user sets the points as:


mButton1.setPosition(240, 120);



the button to be drawn at this point. Now, setting x and y in the opengl world via gluUnProject never works correctly, there are always some incorrect values. Any other simpler way to do this? I tried this: http://steinsoft.net/index.php?site=Programming/Code%20Snippets/OpenGL/no8

Thanks

Share this post


Link to post
Share on other sites
Advertisement
You should not need to use gluUnProject for this.

What projection matrix are you using? If you want to work on a pixel level, than you should just use an orthographic projection matrix that matches your screen dimensions.

glOrtho(0,WIDTH, 0,HEIGHT, -1, 1);

Then your vertex positions will match your pixel coordinates. Then if you want to draw a button at 240, 120, you just transform it right 240 units and up/down 120 units.

Share this post


Link to post
Share on other sites
Quote:
Original post by karwosts
You should not need to use gluUnProject for this.

What projection matrix are you using? If you want to work on a pixel level, than you should just use an orthographic projection matrix that matches your screen dimensions.

glOrtho(0,WIDTH, 0,HEIGHT, -1, 1);

Then your vertex positions will match your pixel coordinates. Then if you want to draw a button at 240, 120, you just transform it right 240 units and up/down 120 units.


But what when I have 3D ? glOrtho AFAIK is for 2D only, isn't it?

Share this post


Link to post
Share on other sites
But you're asking about buttons, which is a 2D GUI, I would imagine. If you have a GUI you should be rendering it with glOrtho on top of your 3D world.

-me

Share this post


Link to post
Share on other sites
Quote:
Original post by Palidine
But you're asking about buttons, which is a 2D GUI, I would imagine. If you have a GUI you should be rendering it with glOrtho on top of your 3D world.

-me


Well I want to make it general, buttons currently are 2D - yes, but then, there is a Z-rotated plane which I should make something similar for it too.

Share this post


Link to post
Share on other sites
Quote:
Original post by Palidine
But you're asking about buttons, which is a 2D GUI, I would imagine. If you have a GUI you should be rendering it with glOrtho on top of your 3D world.

-me


Hm. Ok. Is there any example for using glOrtho ? I.e. I am drawing a button like this:


glPushMatrix()
glTranslate(x, y, 0);
glScale(.5, .5, 0);
mButton.draw(gl);
glPopMatrix();



What should I do to make the matrix translate to (i.e.) 240, 120 ?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!