PDA

View Full Version : A quick Q


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

DoG
2003.10.23, 12:24 PM
Can you post the running app & PB project? Would make it much easier, if I could just download it and play with the source.

I don't see anything wrong right away, but you might wanna try glViewPort() in the setup function.

Josh
2003.10.23, 12:41 PM
gluOrtho2D( 0, 2, 0, 2 );That seems kind of weird to me. I believe it should use the width and height of the window. Once you do that, your polygon will only be a 1x1 pixel which is mighty hard to see ;)

Bachus
2003.10.23, 01:30 PM
As jabber said, try changing the gluOrtho2D call to gluOrtho2D(0, 800, 600, 0); Also try adding: glMatrixMode(GL_MODELVIEW); and glLoadIdentity(); after the ortho call. If that still doesn't work, try using larger numbers in your glVertex2i calls, and add glFrontFace(GL_CW); before glBegin.

If that doesn't work, beats me.

inio
2003.10.23, 02:34 PM
Originally posted by jabber
That seems kind of weird to me. I believe it should use the width and height of the window.
As it is right now the pixel would fill an area of about 1/4 of the screen. Setting the width and height as you say would make the pixel fill only one pixel.

The parameters to gluOrtho2D are the world-space coordinates that map to the left, right, bottom, and top edges of the viewport (respectively). Increasing right-left or top-bottom will make objects smaller.

Josh
2003.10.23, 06:54 PM
Originally posted by inio
As it is right now the pixel would fill an area of about 1/4 of the screen. Setting the width and height as you say would make the pixel fill only one pixel.Right. I said that later on.

inio
2003.10.23, 10:46 PM
Originally posted by jabber
Right. I said that later on.

Doh, I misread your original post.