OpenGL basecode in XCode/Snow Leopard

I have Mac 10.6 and XCode 3.2.6 and I have yet to find any tutorial on getting the base OpenGL code to work properly via XCode. Do i go into interface builder and drag an NSOpenGL view onto my main window or do i do the custom view? Do i still have to put the original glut code in my main program or is there an NS* equivalent? Do the NSEvents go into the main program or should they be defined somewhere else?

I got the Cocoa for Programming and have looked at various other tutorials but they all date back to Leopard or before and some the Next Step API has been changed throughout all MAC OSX releases.

as one example my initWithFrame code:

NSOpenGLPixelFormat *pixelFormat;
pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];

this doesn’t work as it gives me an error.

error: expected ‘:’ before ‘;’ token

I have successfully written an opengl application using GLUT specifically to handle all my events via the VI editor and a makefile which links up the opengl frameworks that i need but now i would like to move to XCode.

Any help, links or whatever else is appreciated. thanks!

Before you go any further, start looking at your code a bit harder. You have more ‘[’ than ‘]’! It’s nothing to do with OpenGL yet, just Objective C - although this would be an issue in every programming language.


thanks for the help - that worked and now I have a rotating red triangle! just been looking at the code too long. i have heard that integrating the Interface Builder for OpenGL can be aggravating because most people are used to doing everything from scratch so some of the concepts are difficult to pick up at first. I am definitely experiencing this. Just have to continue to push forward.

I haven’t even gone over the Quartz stuff yet or the Core Animator stuff; i guess maybe i should have.

thanks again.

@Bruce - it seems that I have some things working how i want in my basecode. I have subclassed NSOpenGLView and am drawing a simple triangle in Ortho mode(pixel space) but in the reshape function the triangle isnt being redrawn correctly within the scope of the viewport. I have heard from a couple of people now that even putting the projection code in the reshape is the wrong idea. I don’t know though. I also would like for the program to just quit and the Xcode debug window to close when i press the ESC key or what not. I know this is some sort of NSEvent but just now trying to figure out how to perform that task. It is getting cumbersome have to Apple + Q to quit every time and close the debug window manually.

Anyway any help on the resizing issue or any hints would be appreciated. thanks!

- (void)reshape
	//[[self openGLContext] makeCurrentContext];
	NSRect rectView = [self bounds];
	if( m_rectView.size.width != rectView.size.width || m_rectView.size.height != rectView.size.height )
		glViewport( 0, 0, rectView.size.width, rectView.size.height );
		m_rectView = rectView;
	glViewport(0, 0, NSWidth(rectView), NSHeight(rectView));
    glOrtho(0, rectView.size.width, 0, rectView.size.height, -1.0, 1.0);
	//glScalef(1.0, -1.0, 1.0);
	//glTranslatef(0, -rectView.size.height, 0);
	//[NSOpenGLContext clearCurrentContext];

-(void) drawRect:(NSRect)bounds{
	glClearColor(0, 0, 0, 0);
	glColor3f(1.0, 0.85, 0.35);
		glVertex3f(300.0, 300.0, 0);
		glVertex3f(450.0, 700.0, 0);
		glVertex3f(1850.0, 300.0, 0);

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.