Beginning OpenGL programmer
Beginning OpenGL programmer
- Subject: Beginning OpenGL programmer
- From: "Halvor Kise jr." <email@hidden>
- Date: Thu, 4 Apr 2002 19:13:41 +0200 (CEST)
Hi,
I am trying to make a OpenGL enabled program for Mac OS X under Cocoa.
I have subclassed NSOpenGLView and I am trying to turn on dubble buffering
in my pixelformat.
I have read that the right place to do that is to override
initWithFrame:frameRect
But my program doesnt seem to work.
Being new to Cocoa, Obj-C _and_ OpenGL is not very promising...
I have added a bunch of NSLog's and have found out that my initWithFrame
function is not called at all. How come?
I have now used 4 days on this problem! (Guess it turns out I have forgot
a semicolon or something like it...argh!)
Can someone please help me out here?
Best,
- Halvor.
My .h file:
#import <Cocoa/Cocoa.h>
#import <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <OpenGL/glext.h>
#include <OpenGL/CGLRenderers.h>
@interface MyOpenGLView : NSOpenGLView
{
// Pixel format & context stuff
NSOpenGLPixelFormatAttribute pfAttribs[32];
NSOpenGLPixelFormat *nsglFormat;
NSOpenGLContext *glContext;
unsigned long bitsPerPixel, depthSize,
stencilSize, numAuxBuffs;
BOOL enableDepth, packedPixels, pause;
BOOL useDblBuffer, useAccel,
useNoRecover, useAux, useStencil, useAllRender;
}
// Overrides
- (void)drawRect:(NSRect)rect;
- (id)initWithFrame:(NSRect) frameRect;
- (id)initWithFrame:(NSRect) frameRect pixelFormat:(NSOpenGLPixelFormat*)format;
// Basic functions
-(void) SetPerspective:(int) width height: (int) height;
-(void) InitializeRContext;
@end
and initWithFrame from my MyOpenGLView.m :
//////////////////////////////////////////////////////////////////////////////////
// initWithFrame
//////////////////////////////////////////////////////////////////////////////////
- (id)initWithFrame:(NSRect) frameRect
{
// Basic pixel format with some default values
NSOpenGLPixelFormatAttribute attr[] =
{
NSOpenGLPFANoRecovery,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAAccelerated,
NSOpenGLPFAColorSize,
16, // bitsPerPixel,
NSOpenGLPFADepthSize,
16, // depthSize,
0 };
// Create our pixel format
nsglFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
NSLog(@"Tada!");
// If the format isn't valid...
if(!nsglFormat)
NSLog(@"Pixel format is nil");
else
NSLog(@"Worked!");
// Otherwise create the context...
self = [super initWithFrame:frameRect pixelFormat:nsglFormat];
// If we don't get a context...
if(!self)
NSLog(@"initWithFrame failed");
// Otherwise, make the context current and continue
[[self openGLContext] makeCurrentContext];
return self;
}
--
*** MEMENTO MORI ***
_______________________________________________
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.