• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: OpenGL -a success story and a question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OpenGL -a success story and a question


  • Subject: Re: OpenGL -a success story and a question
  • From: mathew <email@hidden>
  • Date: Thu, 15 May 2003 22:06:28 -0400

On Wednesday, May 14, 2003, at 23:02 US/Eastern, Christopher Henrich wrote:
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.

Well... if I recall correctly, the teapot is a GLUT application. GLUT handles creating a window and keeping track of which GL context belongs with which GLUT-generated window. When you select a window it selects the context for you.

When you create an NSOpenGLView yourself without using GLUT, you have to keep track of the context yourself and make sure you're drawing into the right one. The minus side is you have to remember to do it, the plus side is you get more flexibility.

[[self openGLContext] makeCurrentContext] is just saying "Set the current OpenGL context to whatever's necessary to send future OpenGL calls to self". I assume you're doing it in an NSOpenGLView, or you'll be getting errors in your syslog :-)

If you had two or more NSOpenGLView objects in your program, you might quite reasonably want to do something like

[[perspectiveview openGLContext] makeCurrentContext];
glBegin(GL_QUADS);
... GL calls to draw filled perspective view of object ...
glEnd();
glFlush();
[[topview openGLContext] makeCurrentContext];
glBegin(GL_LINES);
... GL calls to draw line view of object from top ...
glEnd();
glFlush();

and so on.

I also wonder if there is a missing document about OpenGL and Cocoa.

Oh, many. For starters, it would be nice if there was a comprehensive guide to OpenGL that didn't mix it with lots of Windows-only stuff, and didn't assume the reader has a degree in Computer Science or Mathematics.

You might be interested in joining the Mac OpenGL mailing list. It's another Apple-run list.


mathew
_______________________________________________
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.

References: 
 >OpenGL -a success story and a question (From: Christopher Henrich <email@hidden>)

  • Prev by Date: Re: iTangram Fury
  • Next by Date: WSMethodInvocationInvoke and Microsoft TerraServer?
  • Previous by thread: OpenGL -a success story and a question
  • Next by thread: NSPasteboard and MS Word
  • Index(es):
    • Date
    • Thread