Apple OpenGL (AGL) Question

Started by
3 comments, last by blueshogun96 11 years, 8 months ago
I have a casual game I started developing for Windows and I would like to port the game to Mac OS X using AGL or CGL (a C based OpenGL implementation). I've never written an app for Mac OS X, but I have written a complete game for iOS. Since I personally don't like Objective-C, I prefer to avoid using it when possible and integrate C/C++ code for the aspects that don't require Cocoa, etc. So what I'd like to do is find some starting point to writing a basic but functional app for Mac OS X's app store.

I opened up a Cocoa based template project in XCode, but I'm not sure where to start. I tried searching Google for answers, but it was not my friend, and I'm quite confused as to where I should add my game loop, etc. Any ideas? Thanks.
Advertisement
ObjC approach is based on subclassing NSOpenGLView:
http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_drawing/opengl_drawing.html#//apple_ref/doc/uid/TP40001987-CH404-SW8

If you don't like ObjC you should check this
http://ttjcrew.com/2009/06/27/beginning-opengl-on-os-x/
You should also check this one (correctly setting target)
http://www.autofasurer.net/wp/?p=106
I couldn't get the first one to work (the code) and the other two links are things I've already gotten to work. Will Apple allow you to release an app built as a console application on their app store? If that's true, I'll stick with that.
Sorry for the double post, but I can't get OpenGL to work to save my life, and drawRect never gets called! I've also searched google, but I can't find any clear results.


#import <Cocoa/Cocoa.h>
#include "OpenGL/OpenGL.h"
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <OpenGL/glext.h>

@interface AppDelegate : NSOpenGLView
{
NSWindow *window;
}
- (void) drawFirstOpenGLFrame;
- (void) drawRect:(NSRect)dirtyRect;
@property (assign) NSWindow *window;
@end

#import <Cocoa/Cocoa.h>
#include "OpenGL/OpenGL.h"
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <OpenGL/glext.h>

@interface AppDelegate : NSOpenGLView
{
NSWindow *window;
}
- (void) drawFirstOpenGLFrame;
- (void) drawRect:(NSRect)dirtyRect;
@property (assign) NSWindow *window;
@end





#import "AppDelegate.h"
@implementation AppDelegate
@synthesize window;

- (void) drawFirstOpenGLFrame
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f (0.25, 0.25, 0.0);
glVertex3f (0.75, 0.25, 0.0);
glVertex3f (0.75, 0.75, 0.0);
glVertex3f (0.25, 0.75, 0.0);
glEnd();
glFlush();
}
- (void) drawRect:(NSRect)dirtyRect
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f (0.25, 0.25, 0.0);
glVertex3f (0.75, 0.25, 0.0);
glVertex3f (0.75, 0.75, 0.0);
glVertex3f (0.25, 0.75, 0.0);
glEnd();
glFlush();
}
- (void) keyUp:(NSEvent *)theEvent
{

}
- (void) keyDown:(NSEvent *)theEvent{

}
- (void)dealloc
{
[window release];
[super dealloc];
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
// [self drawFirstOpenGLFrame];
}
@end


I'm still lost, and it looks like Apple requires you to use Cocoa to release anything on their app store (I hate obj-C!).
Okay, I figured it out. I had to set some options in my .xib file. Now my only problem is resizing. When I try to do so, it causes my window contents to become distorted.

This topic is closed to new replies.

Advertisement