Matteo Cavalleri <shiva.brahma.DeleteThis@tiscali.invalid> wrote:
> > Study the example:
> >
> > /Developer/Examples/OpenGL/Cocoa/UnderlaySurface/
Ok, I've studied it but I haven't still understood what I do wrong, but
I've another question now. The opengl view of this example is a subclass
of NSOpenGLView. AFAIK initWithFrame: is never called when you subclass
NSOpenGLView but in this example it is called. I suppose the author of
the demo used a NSView object when he built the interface with IB and
then assigned it to a subclass of NSOpenGLView instead of a subclass of
NSView. Is it possible? I tried to check with IB but I'm not sure if
this is correct.
Anyway, my program still shows nothing. I tried both a custom opengl
class (subclassing NSView) and a NSOpenGLView subclass. The only thing
that changed is that now I don't need to resize the window to see the
poligons disappear, I just never see them....
Here's my current code:
#import "MyOpenGLView.h"
@implementation MyOpenGLView
- (void) awakeFromNib
{
setupDone = NO;
}
- (void) drawRect:(NSRect)rect
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if (!setupDone) {
setupDone = YES;
[self setupGL];
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glTranslatef(-1.5f,0.0f,-6.0f);
glTranslatef(-1.5f,0.0f,0.0f);
glBegin(GL_TRIANGLES);
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glEnd();
glBegin(GL_QUADS);
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Lef
glEnd();
// i'm not using doublebuffering, so i should not need flushBuffer:
//if ([self inLiveResize])
glFlush();
//else
// [[self openGLContext] flushBuffer];
}
- (void) reshape
{
NSRect rect = [self bounds];
GLdouble aspect;
glViewport(0, 0, (GLsizei) rect.size.width, (GLsizei)
rect.size.height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
aspect = rect.size.width / rect.size.height;
gluPerspective(45.0f, aspect, 0.1f, 100.0f);
}
- (void) setupGL
{
// reshape: has already been called by os x and the modelview matrix
// has already been selected in drawRect
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
// do i need this? I already setup depth buffer within IB
//glEnable(GL_DEPTH_TEST);
//glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
@end
--
Questa firma e' frutto della tua immaginazione.<!-- ~MESSAGE_AFTER~ -->
>> Stay informed about: cocoa and opengl