Handling OpenGLViews in Cocoa

BlueAvian
Unregistered
 
Post: #1
I have been working with open gl for a while now and learned quite a bit. But unfortunetly I really haven't learned much about how to handle the view in OOP. I have a way that I'm doing now, but it is giving me alot of problems. I would like to use getTickCount(); to delay it and make a nice constant framerate, but I don't know how to draw things in other classes besides the view and still be able to see them. If someone could please either give me some info, or point me in the right direction I would appreciate it.
Quote this message in a reply
BobimusPrime
Unregistered
 
Post: #2
The way I've been dealing with drawing using a Cocoa NSOpenGLView is to setup a timer in the view that tells it to redraw every 1/60 of second. I usually have drawRect call some drawing routines in C++ source files. I'm kinda new to Cocoa so these might not be the best ways Smile. I uploaded the source code to a little program that loads and animates Coalesce model files that has the timing stuff and also integrates C++ files into the project.

The source can be found here:
http://www.bobbosoft.com/AnimateModel.sit

I guess my general answer to your question is that I don't do any drawing in the NSOpenGLView file directly. I'll usually call other routines in C++ files to do the drawing.

Hope that helps!

Robert
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #3
I may be misinterpreting your question, but to draw in objects other than the view, make a drawFrame method in the object and call it from the method that does the drawing in the view.
Also make sure you include all the opengl headers in your object.
I found this web site quite useful for cocoa opengl:

http://zerobyzero.ca/~ktatters/tutorials/index.html

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Member
Posts: 148
Joined: 2003.03
Post: #4
If you want to stay true to Cocoa, then use NSTimer, NSDate, and NSTimeInterval for variable frame rate control. However, the overhead for this intergrated with OpenGL probably won't maximize efficiency.
Quote this message in a reply
Feanor
Unregistered
 
Post: #5
BlueAvian, you are being a bit ambiguous: are the other things you are drawing vertices, or are they controls or other AppKit view objects?

If you want to draw other vertices, you have to both lock focus on the view they are to appear in, and ensure that the current context is the same one that is attached to the view. However it is more common, in single-threaded Cocoa OpenGL apps, to have the view call some controller object which will call model objects to draw themselves using OpenGL. Have a timer call the view's drawRect: method.
Quote this message in a reply
BlueAvian
Unregistered
 
Post: #6
"However it is more common, in single-threaded Cocoa OpenGL apps, to have the view call some controller object which will call model objects to draw themselves using OpenGL. Have a timer call the view's drawRect: method."

Ya, thats what I have been doing... just didn't know if there was a more efficient way or not.

And, no, i'm drawing my own stuff, not AppKit view objects.

Thx all,
Chase
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Handling DDS on a Mac tim42 3 2,778 Jul 20, 2008 05:18 PM
Last Post: tim42