Jump to content
  • Advertisement
Sign in to follow this  
jeff8j

glsl pixel position?

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

I have old opengl1/1.5 immediate mode code im trying to get updated into opengl es 2 using glsl. I have some code that creates 2d box using glVertex3i to set the location in pixels. I have a box drawing in glsl but its in the center using

 

gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

How can I set it using pixels? Im not concerned about passing the values yet just changing the gl_Position to say put it 100px from the bottom and 100px in from the left that would be a great starting point. Thanks

 

 

I figure I might be able to (havent tried) make a box that takes up the whole screen then use the frag shader to only set the pixels I want but then it would have to run over per every pixel on screen but thats got to be inefficient I would think theres a better way?

Edited by jeff8j

Share this post


Link to post
Share on other sites
Advertisement

You need to set your projection matrix from inside your program so that 0,0 is one corner of the screen (top left, for instance) and some other values X/Y are the opposite corner (eg: resolution_x, resolution_y, or some fixed values that are independent of resolution)..

 

The reality is that as long as your projection matrix is unknown, you won't be setting *anything* "by pixels" even if you use glVertex3i - which is just glVertex3f, but takes integers instead of floats, but it doesn't mean that it takes coordinates in the form of pixels..

 

glOrtho() is the key to your success.

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!