OpenGLES glOrtho question

Problems with Canvas, OpenGL, etc...

OpenGLES glOrtho question

Postby jojojoris » Thu Nov 04, 2010 2:55 am

Hello everyone on this forum.

I'm new to android development. I used to be a psp homebrew developer and 3D game programmer for PC games. I have quite some experience with a lot of programming languages and especially C/C++.

Now my question.

Te definition of glOrtho is:
void glOrthof(GLfloat left,
GLfloat right,
GLfloat bottom,
GLfloat top,
GLfloat near,
GLfloat far)

Most tutorials i find on the internet use it like this:
glOrthof(0.0f,width,height,0.0f,-100.0f,100.0f)
Unfortunately when i use this nothing is drawn in the screen.
But when i swap the 3rd and 4th argument like this:
glOrthof(0.0f,width,0.0f,height,-100.0f,100.0f)
My rectangle is drawn.

Can someone explain why the first is used in most tutorial (like the opengl tutorials from nehe) while the second one is actually working?

PS.
Does someone knows a good explanation of glFrustum? I can use gluPespective but i prefer understanding what i am doing/using.
jojojoris
Freshman
Freshman
 
Posts: 6
Joined: Thu Nov 04, 2010 12:52 am

Top

Re: OpenGLES glOrtho question

Postby SilverLogic » Thu Nov 04, 2010 4:04 am

You are correct on the second line, the left and top attributes will almost always be zero (unless you would like your origin to be in the center of the screen, which is useful in some cases, then these can be negative, usually equal to height and width). Also note that screen coordinates in most situations originate from the top left, unlike the opengl orthographic view which has its origin at the bottom left.

glFrustum and gluPerspective are essentially the same thing, except gluPerspective lets you assign a Field of view (how much of the world can actually be seen on the screen), by default you usually want about 45.0f (45 degrees out of the 360 degree world around you). You can go higher or lower, usually you will just end up with a fish-eye lense effect though. I believe this can be achieved with glFrustum, but I've never tried, I'm sure there are some matrix calculations involved, but easier just to stick to the GL utilities.

Sorry for the vague descriptions, I'm sure someone knows a little more about these than I do, but this is all I've ever really needed to know.
User avatar
SilverLogic
Junior Developer
Junior Developer
 
Posts: 10
Joined: Thu Oct 21, 2010 10:31 pm

Re: OpenGLES glOrtho question

Postby jojojoris » Thu Nov 04, 2010 1:40 pm

SilverLogic wrote:You are correct on the second line, the left and top attributes will almost always be zero (unless you would like your origin to be in the center of the screen, which is useful in some cases, then these can be negative, usually equal to height and width). Also note that screen coordinates in most situations originate from the top left, unlike the opengl orthographic view which has its origin at the bottom left.


But i only see things when left and bottom are zero and top equals height.
Why???
jojojoris
Freshman
Freshman
 
Posts: 6
Joined: Thu Nov 04, 2010 12:52 am

Re: OpenGLES glOrtho question

Postby SilverLogic » Thu Nov 04, 2010 6:35 pm

I am sorry, It is the left and <b>bottom</b> that will always be zero, I think i was reading too fast :)
User avatar
SilverLogic
Junior Developer
Junior Developer
 
Posts: 10
Joined: Thu Oct 21, 2010 10:31 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 4 guests