Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ArtOfWarfare

macrumors G3
Original poster
Nov 26, 2007
9,560
6,059
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

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

macrumors regular
Mar 24, 2008
108
1
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":

Code:
// 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

macrumors G3
Original poster
Nov 26, 2007
9,560
6,059
...

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

macrumors 65816
Mar 15, 2008
1,265
188
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

macrumors regular
Mar 24, 2008
108
1
...

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

macrumors G3
Original poster
Nov 26, 2007
9,560
6,059
Can I have a tutorial that does nothing please?

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.
 

DreamPod

macrumors 65816
Mar 15, 2008
1,265
188
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 :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.