OpenGL -a success story and a question
OpenGL -a success story and a question
- Subject: OpenGL -a success story and a question
- From: Christopher Henrich <email@hidden>
- Date: Wed, 14 May 2003 23:02:31 -0400
I recently got my OpenGL project to work for the first time. It's
nothing earth-shaking (as yet)... I draw a polyhedron and display it.
The last obstacle was a stubborn one: no matter what I did, the depth
discrimination didn't work. Whatever was drawn last appeared on top,
whether it deserved to or not. The result was a mess.
I suppose that OpenGL beginners generally learn by following examples;
this is definitely how I did it. The examples from Apple's web site
were helpful, particularly the teapot.
(See
http://developer.apple.com/samplecode/Sample_Code/Graphics_3D.htm).
Through several frustrating days, it gave me hope that 3D graphics
could actually be done with OpenGL.
But it didn't give me the crucial instructions.
Those I got from
http://zerobyzero.ca/~ktatters/. (K. Tatters, thank
you! Take a bow.)
I had been obsessively scanning the OpenGL calls in Apple's examples
and those of K. Tatters, but the real key was not properly an OpenGL
call at all, it was an invocation of a Cocoa method:
[[self openGLContext] makeCurrentContext]
(Here, "self" is an instance of a class derived from OpenGLView.) When
I put this line into my code at a reasonable place, it all started to
work.
Nobody told me I had to do this. In retrospect, it seems entirely
reasonable, even obvious. But that's only in retrospect; to me as a
newbie OpenGL programmer, even as to a newborn infant, almost nothing
was obvious.
By the way, the teapot example does not contain this call.
Nevertheless the teapot program works beautifully. I have to wonder
how it possibly can.
I also wonder if there is a missing document about OpenGL and Cocoa.
Now I am not without documents. I have the Red Book (OpenGL
Programming Guide) and the blue Book (OpenGl Reference Manual), and
they are fine, but obviously they do not say anything about Cocoa. I
have Aaron Hillegass's book (very fine) and the grand ol' doorstopper
by Anguish, Buck and Yaktman. But neither of these says much about
OpenGL. There is useful on-line documentation, but somehow it doesn't
explain why "makeCurrentContext" is necessary for me, but not for the
teapot example.
So I feel that I just lucked in to something that works, or seems to.
There may be other rules about OpenGL that I haven't learned about. I
wish I could find out what they are.
Chris Henrich
_______________________________________________
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.