PDA

View Full Version : OpenGL ES?




ArtOfWarfare
Nov 2, 2008, 12:44 PM
Okay... so I've been going through this book OpenGL Programming Guide but I found you can't quite copy everything straight out of it for Mac OS X... it took me looking through the ADC documentation a bit to find out connect views and stuff to have it work.

This was very useful for finding how to use OpenGL in Mac OS X (http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_drawing/chapter_3_section_3.html)

Does anyone have anything similar for the iPhone now? I tried doing almost the same exact thing (except I added the OpenGLES framework instead of the OpenGL framework.)

So... most of the functions don't work. glOrtho, glBegin, glEnd, glVertex3f (and 2f), all got errors. What would be the proper OpenGL ES functions to use in their place?



SqueegyX
Nov 2, 2008, 06:52 PM
glOrtho, is glOrthof (or glOrthox) but it otherwise the same. Also see glFrustrumf and glFrustrumx.

Instead of glBegin and glEnd, you render arrays of data. This renders the content of a vertex array buffer identified by "modelBuffer":


// Load into buffer once
faceCount = 2;
GLfloat vertices[] = {
-0.71, -0.268587, -0.06608,
-0.71, -1.688587, -0.06608,
0.71, -1.688587, -0.06608,

0.71, -1.688587, -0.06608,
0.71, -0.268587, -0.06608,
-0.71, -0.268587, -0.06608,

};
glGenBuffers(1, &modelBuffer);
glBindBuffer(GL_ARRAY_BUFFER, modelBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

// later Render the buffer
glBindBuffer(GL_ARRAY_BUFFER, modelBuffer);
glVertexPointer(3, GL_FLOAT, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_TRIANGLES, 0, faceCount*3);

glVertex is gone with begin and end because vertices are rendered and declared with arrays, not one at a time. glDrawArrays() now becomes you primary method of rendering geometry.

ArtOfWarfare
Nov 2, 2008, 07:48 PM
...

is OpenGL Programming Guide worth reading then or is it so outdated that it would only teach me legacy/useless/ineffective techniques? Maybe the same basic concepts still apply...?

(I guess I can still read it just to figure out how to use OpenGL on Mac OS X... even though I don't have any applications I want to make right now on Mac OS X whereas I have two big apps I'm working on for the iPhone...)

DreamPod
Nov 2, 2008, 11:18 PM
A lot of standard OpenGL stuff is still applicable, so it's not bad to keep the book. Just note that most calls add an "f" or "x" to the end (for float, fixed point values respectively). The two biggest differences in OpenGL ES are what was already mentioned about how you set up your scenes, and ES doesn't support quads. ES supports triangles, lines, and pointsprites. If you don't mind it being a bit technical, you can get a full doc on OpenGL ES with links to example code and stuff from khronos.org.

SqueegyX
Nov 3, 2008, 12:05 PM
...

is OpenGL Programming Guide worth reading then or is it so outdated that it would only teach me legacy/useless/ineffective techniques? Maybe the same basic concepts still apply...?

(I guess I can still read it just to figure out how to use OpenGL on Mac OS X... even though I don't have any applications I want to make right now on Mac OS X whereas I have two big apps I'm working on for the iPhone...)

Definately still worth it. The other differences are pretty minor.

ArtOfWarfare
Nov 4, 2008, 10:43 AM
Can someone give me some instructions for how to go from starting a new project for the iPhone with a window or view template to having a program that simply clears the screen and draws a white square in the center?

Similar to the golden triangle example I gave the link to in my opening post. I can't seem to find any tutorials specifically for the iPhone on using OpenGL ES right now... I think if I can just make something that works on the iPhone in OpenGL ES it would help me significantly in making the other examples in OpenGL Programming Guide work.

SqueegyX
Nov 4, 2008, 01:35 PM
Use the OpenGLES application template in xcode. And check out all the OpenGLES sample code here: http://developer.apple.com/iphone/library/navigation/SampleCode.html

It sets up most of the hard stuff for you, like windows pixel formats and all that cryptic complicatedness.

DreamPod
Nov 5, 2008, 02:39 AM
Yeah, in Xcode just create a new project, and when it asks what type of project, choose OpenGL ES. The simple app it creates is exactly what you describe :)