LTRB in pixels

Aug 18, 2007 at 10:25am

LTRB in pixels

This seems like an extremely simple idea to me but I cant figure it out at all

if I have a desired left, top, right, bottom in pixes. how do I get the GL space position/scale for it?

I can be in ortho 2 if you need me to be… (the hook to my next pop tune)

sorry in advance for asking for something stupid

documentation
forums
net

#33310
Aug 18, 2007 at 11:25am

On 8/18/07, Matthew Aidekman

wrote:
>
>
>
> if I have a desired left, top, right, bottom in pixes. how do I get the
> GL space position/scale for it?
>
>
>
Hi Matt,

You can set up the opengl projection so that you can draw things using
integer pixel coordinates, and omitting whatever rotation or scaling is
going on in the rest of you scene. This is my code using Lua, but its
straightforward to convert it to JS or jit.gl.sketch commands:

function uSetOrtho2D()
gl.MatrixMode(“PROJECTION”)
gl.PushMatrix()
gl.LoadIdentity()
gl.Ortho(0, 640, 480, 0, 0, 1) — window dimensions in pixels
gl.MatrixMode(“MODELVIEW”)
gl.PushMatrix()
gl.LoadIdentity()
end

function uResetOrtho2D()
gl.PopMatrix()
– restore previous projection
gl.MatrixMode(“PROJECTION”)
gl.PopMatrix()
gl.MatrixMode(“MODELVIEW”)
end

Whatever you draw in between those function calls will appear in 2D. (0,0)
is the top left corner in this example, but you can choose whatever corner
you prefer to be your origin by changing the arguments to glOrtho(). Note
that this example uses a fixed 640×480 context.

Cheers,
Thijs

http://www.nano-soundworks.com

#110816
Aug 18, 2007 at 6:21pm

very sneaky… me liky!

sorru I havent been on the board more. hofstadter’s rule applies

#110817
Aug 18, 2007 at 6:41pm

>From a Jitter object, you can use @transform_reset 2 to get
coordinates from [-1, 1] across both dimensions and then scale/bias
approproately to get pixels. I belielve all jit.gl objects have a
dest_dim attribute (or something similarly named). You can use this
to figure out the window size.

wes

On 8/18/07, Matthew Aidekman

wrote:
>
> very sneaky… me liky!
>
> sorru I havent been on the board more. hofstadter’s rule applies
>

#110818

You must be logged in to reply to this topic.