Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 27, 2012, 11:57 PM   #1
Blakeasd
macrumors 6502a
 
Join Date: Dec 2009
Very Simple Explanation of glOrthof() in OpenGL ES

I saw some previous posts and explantations on the internet of glOrthof, but I just don't get it. I am watching the Stanford OpenGL ES lesson on Youtube and the following code came up:

Code:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0, backingWidth, 0, backingHeight, -1, 1);
This code draws a picture 1px by 1px in the bottom left hand corner of the screen. Why would it do this though? I thought this code would take the picture from (0,0) and stretch it across the entire screen because it specifies the plane as from 0 to the width of the screen and 0 to the height of the screen. Can someone please explain as simply as possible why it draws it as 1px by 1px in the bottom left hand corner. The full source code can be found on the Stanford website labeled as "openGLtransforms.zip":

http://www.stanford.edu/class/cs193p/cgi-bin/drupal/node/79

(The file where this code appears is ESRenderer1.m)

Thanks!
Blakeasd is offline   0 Reply With Quote
Old Dec 28, 2012, 01:46 PM   #2
szymczyk
macrumors regular
 
Join Date: Mar 2006
The arguments you pass to glOrtho define the boundaries of the projection. For 2D drawing, glOrtho defines the visible area of the screen in OpenGL units. In the code you listed, calling glOrtho sets the lower left corner of the screen to (0, 0) and the upper right corner of the screen to (backingWidth, backingHeight). Anything drawn in the range of (0, 0) to (backingWidth, backingHeight) will be visible on the screen. Assuming that backingWidth and backingHeight are the width and height of the screen in pixels, the code you listed sets a projection where one OpenGL unit equals one screen pixel.

Why does the example draw the picture with a size of one pixel? I haven't looked at the code, but my guess is the code draws from 0 to 1 in OpenGL units. Since you set up the projection so one OpenGL unit equals one pixel, the drawn picture is one pixel in size. If you modify the call to glOrtho by substituting 1 for backingWidth and backingHeight, the picture should fill the screen.
__________________
Mark Szymczyk
Author, Xcode Tools Sensei
http://www.meandmark.com

Last edited by szymczyk; Dec 29, 2012 at 12:41 PM.
szymczyk is offline   0 Reply With Quote
Old Dec 29, 2012, 09:23 AM   #3
Blakeasd
Thread Starter
macrumors 6502a
 
Join Date: Dec 2009
Great explanation! That makes a lot of sense. Thank You!
Blakeasd is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Need technical help/explanation kallisti Digital Photography 10 Mar 18, 2014 03:56 PM
OpenGL ES: #define BUFFER_OFFSET(i) ((char *)NULL + (i)) explanation Blakeasd iPhone/iPad Programming 4 Jul 4, 2013 05:38 PM
Explanation Liquinn Wasteland 6 Aug 21, 2012 08:09 PM
I want an explanation from someone MacMane iPad 5 Aug 17, 2012 05:02 PM
iTunes Match Explanation? marty1990 iCloud and Apple Services 2 Aug 2, 2012 09:34 PM

Forum Jump

All times are GMT -5. The time now is 09:38 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC