cocoa for nibbies [OpenGL context creation/ Initializing a PixelFormat]

Member
Posts: 63
Joined: 2005.04
Post: #1
What is the correct way to initialize an OpenGl Context, set a pixelFormat using

Code:
-(id)initWithAttributes:(NSOpenGLPixelFormat*)attribs

here is my *cough* source code :-\



/* aGameGLView */

#import <Cocoa/Cocoa.h>

@interface aGameGLView : NSOpenGLView
{

BOOL readyToDraw;
NSRect* myRect;
NSOpenGLPixelFormat* myPixelFormat;
NSOpenGLContext* myContext;
NSOpenGLPixelFormatAttribute* attribs;

}

-(void)awakeFromNib;
-(void)drawRect:(NSRect)rect;
-(id)initWithAttributes:(NSOpenGLPixelFormatAttribute *)attribs;




#import "aGameGLView.h"
#define kWindowHeight 400
#define kWindowWidth 300

@implementation aGameGLView

-(void)awakeFromNib
{
    readyToDraw = NO;
    myPixelFormat = [[NSOpenGlPixelFormat alloc] init];
    myContext =[[NSOpenGLContext alloc] init];
    attribs = [NSOpenGLPFAAllRenderers,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAStereo,
NSOpenGLPFAMinimumPolicy,
NSOpenGLPFAMaximumPolicy,
NSOpenGLPFAOffScreen,
NSOpenGLPFAFullScreen,
NSOpenGLPFASingleRenderer,
NSOpenGLPFANoRecovery,
NSOpenGLPFAAccelerated,
NSOpenGLPFAClosestPolicy,
NSOpenGLPFARobust,
NSOpenGLPFABackingStore,
NSOpenGLPFAWindow,
NSOpenGLPFAMultiScreen,
NSOpenGLPFACompliant,
NSOpenGLPFAPixelBuffer, 0];
    
    
}

-(void)drawRect:(NSRect)rect
{
    
    // Check to see if we're initialized
    if(!readyToDraw)
    {
    
        readyToDraw = YES;
    }
}

@end
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Quote this message in a reply
Member
Posts: 63
Joined: 2005.04
Post: #3
Thanks a lot for the help!!

oh, and kudos on the book!
Quote this message in a reply
Member
Posts: 63
Joined: 2005.04
Post: #4
I keep getting the build error : "too many filenames given. Type cc1obj --help for usage", what does this mean?
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #5
probably an xcode error—but then I'm usually wrong, so don't take my advice of doing it from the Terminal.

It's not magic, it's Ruby.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
Definitely sounds like an Xcode problem

Is this in your own project, or one of my example projects?
Quote this message in a reply
Member
Posts: 63
Joined: 2005.04
Post: #7
The error occurs in my project, I wasn't aware that you had sample projects with your book, I'm sure if I had those to compare to mine I could find the reason for the problem. Thanks again for the help guys!
Quote this message in a reply
Member
Posts: 63
Joined: 2005.04
Post: #8
If it was not clear OneSadCookie's mini book answered my question

thanks ^^
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Opengl/Cocoa text rendering tesil 15 17,392 Mar 20, 2012 11:16 AM
Last Post: OneSadCookie
  OpenGL Text Rendering (in Cocoa) daveh84 5 7,891 Feb 19, 2009 12:44 PM
Last Post: TomorrowPlusX
  OpenGL &amp; Cocoa - Improving frame rate daveh84 4 5,547 Feb 2, 2009 06:53 AM
Last Post: backslash
  bad depth sorting in Cocoa OpenGL aldermoore 2 4,641 Dec 30, 2008 03:07 PM
Last Post: ThemsAllTook
  Loading and using textures with alpha in OpenGL with Cocoa corporatenewt 4 6,391 Dec 8, 2007 02:06 PM
Last Post: Malarkey