MadcapLaugher
MadcapLaugher

Reputation: 583

Cocoa OpenGL always white

Everytime I run my Cocoa App with an OpenGL view I get a white window. What I expect to happen is a black window will show up.

I've verified with a breakpoint that my drawRect method gets called.

Code below.

.h

#import <Cocoa/Cocoa.h>
#import <OpenGL/OpenGL.h>
#import <GLUT/GLUT.h>

@interface OpenlGLTest : NSOpenGLView

- (void) drawRect:(NSRect)dirtyRect;
@end

.m

#include <OpenGL/gl.h>
#import "OpenlGLTest.h"

@implementation OpenlGLTest

- (void)drawRect:(NSRect)bounds
{
    glClearColor(0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT);
    glFlush();
    [self setNeedsDisplay:YES];
}
@end

My project builds without warnings and errors. I'm at a loss as to why my screen is white and not black.

Upvotes: 0

Views: 217

Answers (1)

badweasel
badweasel

Reputation: 2399

Try glClearColor(0.0, 0.0, 0.0, 1.0);. That last 0 in your code is the alpha coefficient, so it's just showing whatever is behind the GLView.

Upvotes: 3

Related Questions