glsl pixel position?

Started by
1 comment, last by user0 10 years, 11 months ago

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?

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.

Thanks I think I understand but now the issue of glOrtho on opengl es 2 lol

This topic is closed to new replies.

Advertisement