简体   繁体   中英

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM