A quick Q

BlueAvian
Unregistered
 
Post: #1
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 -->

Code:
#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 -->

Code:
#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
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #2
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.
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #3
Quote: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 Wink
Quote this message in a reply
Member
Posts: 268
Joined: 2005.04
Post: #4
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.
Quote this message in a reply
Member
Posts: 145
Joined: 2002.06
Post: #5
Quote: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.

"He who breaks a thing to find out what it is, has left the path of wisdom."
- Gandalf the Gray-Hat

Bring Alistair Cooke's America to DVD!
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #6
Quote: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.
Quote this message in a reply
Member
Posts: 145
Joined: 2002.06
Post: #7
Quote:Originally posted by jabber
Right. I said that later on.

Doh, I misread your original post.

"He who breaks a thing to find out what it is, has left the path of wisdom."
- Gandalf the Gray-Hat

Bring Alistair Cooke's America to DVD!
Quote this message in a reply
Post Reply