BlueAvian
2003.10.23, 09:40 AM
Ok, basically what I'm trying to do is make a full screen view in the main function of the main.m. Now I've been able to make the view, but when I draw a quad and flush the buffer, nothing shows up... here is the code, if you see any problems plz tell me, thx.
main.m -->
#import <Cocoa/Cocoa.h>
#import "OpenGLViewFS.h"
int main(int argc, const char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
OpenGLViewFS * view = [[OpenGLViewFS alloc] initWithFrame:NSMakeRect( 0, 0, 800, 600 )];
[[view openGLContext] makeCurrentContext];
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glColor3f( 0.0, 1.0, 0.0 );
glBegin( GL_QUADS );
{
glVertex2i( 0, 0 );
glVertex2i( 1, 0 );
glVertex2i( 1, 1 );
glVertex2i( 0, 1 );
}
glEnd();
[[view openGLContext] flushBuffer];
[pool release];
return 0;
}
OpenGLViewFS.m -->
#import "OpenGLViewFS.h"
@implementation OpenGLViewFS
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
colorBits = 32;
depthBits = 32;
NSOpenGLPixelFormatAttribute pixelAttribs[ 16 ];
int pixNum = 0;
NSDictionary *fullScreenMode;
NSOpenGLPixelFormat *pixelFormat;
pixelAttribs[ pixNum++ ] = NSOpenGLPFADoubleBuffer;
pixelAttribs[ pixNum++ ] = NSOpenGLPFAAccelerated;
pixelAttribs[ pixNum++ ] = NSOpenGLPFAColorSize;
pixelAttribs[ pixNum++ ] = colorBits;
pixelAttribs[ pixNum++ ] = NSOpenGLPFADepthSize;
pixelAttribs[ pixNum++ ] = depthBits;
pixelAttribs[ pixNum++ ] = NSOpenGLPFAFullScreen;
fullScreenMode = (NSDictionary *) CGDisplayBestModeForParameters(
kCGDirectMainDisplay,
colorBits, frame.size.width,
frame.size.height, NULL );
CGDisplayCapture( kCGDirectMainDisplay );
CGDisplayHideCursor( kCGDirectMainDisplay );
CGDisplaySwitchToMode( kCGDirectMainDisplay,(CFDictionaryRef) fullScreenMode );
pixelAttribs[ pixNum ] = 0;
pixelFormat = [ [ NSOpenGLPixelFormat alloc ]
initWithAttributes:pixelAttribs ];
[self setPixelFormat:pixelFormat];
[[self openGLContext] makeCurrentContext];
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluOrtho2D( 0, 2, 0, 2 );
glClearColor( 0.0, 0.0, 0.0, 1.0 );
//glShadeModel( GL_FLAT );
//glEnable( GL_TEXTURE_2D );
//glEnable( GL_CULL_FACE );
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
return self;
}
@end
main.m -->
#import <Cocoa/Cocoa.h>
#import "OpenGLViewFS.h"
int main(int argc, const char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
OpenGLViewFS * view = [[OpenGLViewFS alloc] initWithFrame:NSMakeRect( 0, 0, 800, 600 )];
[[view openGLContext] makeCurrentContext];
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glColor3f( 0.0, 1.0, 0.0 );
glBegin( GL_QUADS );
{
glVertex2i( 0, 0 );
glVertex2i( 1, 0 );
glVertex2i( 1, 1 );
glVertex2i( 0, 1 );
}
glEnd();
[[view openGLContext] flushBuffer];
[pool release];
return 0;
}
OpenGLViewFS.m -->
#import "OpenGLViewFS.h"
@implementation OpenGLViewFS
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
colorBits = 32;
depthBits = 32;
NSOpenGLPixelFormatAttribute pixelAttribs[ 16 ];
int pixNum = 0;
NSDictionary *fullScreenMode;
NSOpenGLPixelFormat *pixelFormat;
pixelAttribs[ pixNum++ ] = NSOpenGLPFADoubleBuffer;
pixelAttribs[ pixNum++ ] = NSOpenGLPFAAccelerated;
pixelAttribs[ pixNum++ ] = NSOpenGLPFAColorSize;
pixelAttribs[ pixNum++ ] = colorBits;
pixelAttribs[ pixNum++ ] = NSOpenGLPFADepthSize;
pixelAttribs[ pixNum++ ] = depthBits;
pixelAttribs[ pixNum++ ] = NSOpenGLPFAFullScreen;
fullScreenMode = (NSDictionary *) CGDisplayBestModeForParameters(
kCGDirectMainDisplay,
colorBits, frame.size.width,
frame.size.height, NULL );
CGDisplayCapture( kCGDirectMainDisplay );
CGDisplayHideCursor( kCGDirectMainDisplay );
CGDisplaySwitchToMode( kCGDirectMainDisplay,(CFDictionaryRef) fullScreenMode );
pixelAttribs[ pixNum ] = 0;
pixelFormat = [ [ NSOpenGLPixelFormat alloc ]
initWithAttributes:pixelAttribs ];
[self setPixelFormat:pixelFormat];
[[self openGLContext] makeCurrentContext];
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluOrtho2D( 0, 2, 0, 2 );
glClearColor( 0.0, 0.0, 0.0, 1.0 );
//glShadeModel( GL_FLAT );
//glEnable( GL_TEXTURE_2D );
//glEnable( GL_CULL_FACE );
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
return self;
}
@end