NSOpenGLView displays all white inside view

Discussion in 'Mac Programming' started by bahlquist, Nov 4, 2010.

  1. macrumors member

    I have managed to get an NSOpenGLView subclass to work and have played around with it a bit. When I try to do the same in a new project, it doesn't work. Here is what I have done. I have a subclass of NSOpenGLView called BACubes. In interface builder, I drag an NSOpenGLView object from the palette into my window. I set its class to BACubes. Here is the code for BACubes:


    #import <Cocoa/Cocoa.h>

    @interface BACubes NSOpenGLView {}

    #import "BACubes.h"
    #include <OpenGL/gl.h>
    @implementation BACubes
    I expect to see a black view screen. The console shows that drawRect has been called. Can you tell me what's wrong?
  2. macrumors 68030


    See if you get an error after glClear
    You should probably set the 0's to 0.0's or 0.0f's
  3. macrumors member

    Thanks for your reply. This is not the problem. Whole numbers as arguments seem to be ok in general (I would be curious if it ever resulted in a problem).
  4. macrumors newbie

    Try adding this:

    -(id) initWithFrame: (NSRect) frameRect
            NSOpenGLPixelFormatAttribute attribs[] =
    		kCGLPFAColorSize, 24,
    		kCGLPFADepthSize, 16,
    	NSOpenGLPixelFormat * pf = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
    	self = [super initWithFrame: frameRect pixelFormat: pf];
        return self;
  5. macrumors 68030


    I didn't expect it to be the problem. But if you know the type of the argument, you should type in the right type. It's just my defensive programmer sense.
  6. macrumors member

    I added this to my implementation, but it never gets called (I noticed this with my other projects and so I omitted any "init" method.)

    Isn't it true that Interface Builder takes care of the initialization (as far as "double buffer" and such goes)?
  7. macrumors 68030


  8. macrumors member

    I implemented initWithCoder instead of initWithFrame. The method is called, but I still get only a white rectangle.
  9. ncl
    macrumors member

    Try adding [[self openGLContext] flushBuffer]; at the end of -drawRect

Share This Page