I've been trying to write a simple subclass of NSOpenGLView. However, the view never redraws unless I resize the window containing it. This has been driving me crazy for about a week and I've tried everything I can think of. My drawRect in my NSOpenGLView is below. I've set double buffer for the view in IB.
My createScene method simply creates a scenegraph "node" that contains VBO's to make a triangle. [myRenderer renderTree: rootNode] just draws the node:
Cocoa is supposed to be so easy, but it's starting to seems like it just obscures things that shouldn't be obscured, and without thorough explanation in the API.
Anyway, many thanks if you can give me some suggestions to fix this problem.
-Tobey
Code:
-(void) drawRect: (NSRect) rect {
NSLog(@"%@", @"Draw Rect");
if(rootNode == nil) {
rootNode = [ self createScene ];
}
[[self openGLContext] makeCurrentContext];
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
id<NSObject> myRenderer = [ [ Renderer alloc ] init ];
[ myRenderer renderTree: rootNode ];
[ [ self openGLContext ] flushBuffer ];
}
My createScene method simply creates a scenegraph "node" that contains VBO's to make a triangle. [myRenderer renderTree: rootNode] just draws the node:
Code:
-(void) renderLeaf: (id<NSObject>) leaf {
glPushMatrix();
glTranslatef(((float) rand())/(RAND_MAX), 0.5f, 0.0f);
glColor3f(((float) rand())/(RAND_MAX), 0.06f, 0.35f);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, [ leaf vboIDv ]);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, [ leaf vboIDp ]);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, 0);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);
glDisableClientState(GL_VERTEX_ARRAY);
// bind with 0, so, switch back to normal pointer operation
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
glPopMatrix();
}
Cocoa is supposed to be so easy, but it's starting to seems like it just obscures things that shouldn't be obscured, and without thorough explanation in the API.
Anyway, many thanks if you can give me some suggestions to fix this problem.
-Tobey