Re: design question: OpenGL and cocoa
Re: design question: OpenGL and cocoa
- Subject: Re: design question: OpenGL and cocoa
- From: Graeme Nattress <email@hidden>
- Date: Fri, 11 Apr 2003 09:31:49 -0400
Hi,
How are you drawing your shapes? For speed I'd use vertex arrays.
Here's the code that I'm using in my OpenGL View to draw my surfaces:
if ([itsController isSurfaceOn]) {
glEnableClientState(GL_NORMAL_ARRAY);
for (counter = 0; counter < countObjects; counter++) {
theObject = [theObjectList objectAtIndex:counter];
if ([theObject getVisible]) {
glVertexPointer(3, GL_FLOAT, 0, (GLfloat*)theObject->Quads);
glNormalPointer(GL_FLOAT, 0, (GLfloat*)theObject->Normals);
glDrawArrays(GL_QUADS, 0, theObject->QuadVerts);
}
}
glDisableClientState(GL_NORMAL_ARRAY);
}
The objects all have boring old C arrays of the correct size to hold
all their polygon data and normals in them. They are all bicubic patch
surfaces, and they calculate the number of polys needed to draw
themselves when they are created, the arrays get malloced, and they
go to a C function that does the tessellation. Now we've our vertex
array and normals arrays that the GL view picks up when it iterates
over the objects in the scene that are flagged visible. We have the
data now in the exact format that the OpenGl need for drawing them at
top speed.
So, the shapes don't know how to draw themselves, they only know how to
produce arrays of valid OpenGl vertex arrays. The view knows about the
objects, and knows that they all have a couple of arrays that they can
access that have the data it needs in the format it wants to draw them.
Hope this helps,
Graeme
On Friday, April 11, 2003, at 04:23 am,
email@hidden wrote:
>
design question: OpenGL and cocoa
--
Graeme Nattress - VP R&D www.noitaminanimation.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.