drawRect in NSOpenGLView help

fakeOne
Unregistered
 
Post: #1
Description: I'm a beginner for trying to learn OpenGL and am trying the Nehe tutorials: http://nehe.gamedev.net/lesson.asp?index=01

Unforunately their Mac OS X setup tutorial for OpenGL didn't quite work well for me, so I decided to use Objective C methods thinking it'd be a better idea anywho, instead.

I'm on the rotating shapes tutorial ( http://nehe.gamedev.net/data/lessons/les...?lesson=04 ) and can't quite get it to work.

Part of my current code: http://paste.lisp.org/display/25183

The problem is that drawRect only gets called when the program starts, and I can't call it again or I couldn't really figure out how, which is the problem. And [self setNeedsDisplay:YES] isn't working really either.

If I resize the window and the view reshapes/resizes, drawRect does get called and the shapes do rotate, though. But I want it to get called automatically.

I've also tried setting up a timer in awakeFromNib, to perform a method called drawGLScene and put my drawing stuff there, along with letting the Timer calling the method every 0.001 seconds. That hasn't really worked well for me though Sad.

Any help would be appreciated Smile

[EDIT]: Oops.. I thought I put it in the "Game Programming - Cocoa API (Objective-C)" section.. Sorry about that.
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #2
Take a look at these tutorials. It should help.
Quote this message in a reply
Member
Posts: 87
Joined: 2006.08
Post: #3
You need to post a bit more code.

Is your display function called again when you resize the window? It should be.

Anyhow, the proper way to redraw the window is to set up a timer (running at 1/60'th a second), and call setNeedsDisplay:YES when the timer fires.
Quote this message in a reply
Apprentice
Posts: 13
Joined: 2006.09
Post: #4
fakeOne,

Did you download the Mac OS X/Cocoa version of the Lesson04? I was able to download it and, after conversion to the new Xcode project file, was able to compile and run it with no errors and 2 warnings.

The one I am referring to is at the bottom of the Lesson04 web page. The link to the .zip file is:

http://nehe.gamedev.net/data/lessons/mac...sson04.zip

The way that I started with these was to download the lesson code and follow through it while reading the lesson.

Also, the 2 warnings I mentioned early are warning about not calling the [super dealloc]; in the dealloc methods of the lesson code. You will get this on every lesson. I just add them in whenever I first get a new lesson.

And, the fullscreen code in these lessons will not work. At least on my Mac is did not. I had to add two additional attributes to the NSOpenGLPixelFormat. They were:

1. NSOpenGLPFAFullScreen
2. NSOpenGLPFAScreenMask

One more thing, some of the images in these lessons are in ARGB format, so they are not going to display correctly on your machine. The way I got around this was to look through some of the other platforms code for images that were in the correct format (RGBA).

Hope that helps.

EDIT:
Wanted to add that the second NSOpenGLPixelFormat attribute up top (NSOpenGLPFAScreenMask) requires a value. This value should directly follow it in your attributes array. The value should be:

CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay)
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  drawRect not being called IckyThump 4 7,222 Aug 13, 2009 06:48 AM
Last Post: IckyThump
  NSOpenGLView subclass not overriding super? mahalis 6 5,465 Sep 12, 2006 07:46 PM
Last Post: OneSadCookie
  Problems with rendering using NSOpenGLView wyrmmage 3 3,422 Aug 24, 2006 08:27 AM
Last Post: wyrmmage
  drawRect: is not executed after setNeedsDisplay:YES Moridin 7 8,342 Oct 19, 2005 12:42 AM
Last Post: Moridin
  drawRect before awakeFromNib unknown 4 4,819 Aug 25, 2005 04:17 PM
Last Post: unknown