Discussion:
using pixel coordinates in opengl es 2
guich
2012-08-29 17:50:41 UTC
Permalink
Hi,

I downloaded and played with the opengl sample at
http://developer.android.com/training/graphics/opengl/draw.html

However, it uses the standard coordinate system for opengl, where 0,0
is at the center of the screen and -1,-1 at top-left and 1,1 at bottom-
right.

I want to use the screen's coordinate, where 0,0 is at top-left and
width,height is at bottom-right.

I already tried a dozen things, read about 30 articles, but since i'm
a newbie at opengl, i'm still stumped.

Can someone tell what it has to be done to change the coordinate so
that the given rectangle

static float squareCoords[] = { 10f, 10f, 0.0f, // top left
10f, 20f, 0.0f, // bottom left
20f, 20f, 0.0f, // bottom right
20f, 10f, 0.0f }; // top right

... is shown at screen?

thanks

guich
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Harri Smått
2012-08-29 17:53:47 UTC
Permalink
Hi,

I might be wrong but I think you can create an orthographic projection matrix for this purpose using Matrix.orthoM. Just provide it with top=0, bottom=height, left=0, right=width.

--
H
Post by guich
Hi,
I downloaded and played with the opengl sample at
http://developer.android.com/training/graphics/opengl/draw.html
However, it uses the standard coordinate system for opengl, where 0,0
is at the center of the screen and -1,-1 at top-left and 1,1 at bottom-
right.
I want to use the screen's coordinate, where 0,0 is at top-left and
width,height is at bottom-right.
I already tried a dozen things, read about 30 articles, but since i'm
a newbie at opengl, i'm still stumped.
Can someone tell what it has to be done to change the coordinate so
that the given rectangle
static float squareCoords[] = { 10f, 10f, 0.0f, // top left
10f, 20f, 0.0f, // bottom left
20f, 20f, 0.0f, // bottom right
20f, 10f, 0.0f }; // top right
... is shown at screen?
thanks
guich
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Latimerius
2012-08-29 18:46:47 UTC
Permalink
You could do that and set the matrix via glLoadMatrix(), however a
more usual way would be to call

glOrthof (0, w, h, 0, ...);

Check glOrhtof() docs and note I'm passing height for bottom and zero
for top which achieves the swap.

(Also note that GLES can't render quads directly. Your square has to
be rendered as two triangles.)
Post by Harri Smått
Hi,
I might be wrong but I think you can create an orthographic projection matrix for this purpose using Matrix.orthoM. Just provide it with top=0, bottom=height, left=0, right=width.
--
H
Post by guich
Hi,
I downloaded and played with the opengl sample at
http://developer.android.com/training/graphics/opengl/draw.html
However, it uses the standard coordinate system for opengl, where 0,0
is at the center of the screen and -1,-1 at top-left and 1,1 at bottom-
right.
I want to use the screen's coordinate, where 0,0 is at top-left and
width,height is at bottom-right.
I already tried a dozen things, read about 30 articles, but since i'm
a newbie at opengl, i'm still stumped.
Can someone tell what it has to be done to change the coordinate so
that the given rectangle
static float squareCoords[] = { 10f, 10f, 0.0f, // top left
10f, 20f, 0.0f, // bottom left
20f, 20f, 0.0f, // bottom right
20f, 10f, 0.0f }; // top right
... is shown at screen?
thanks
guich
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Loading...