Home > C/C++ > Setting up a basic OpenGL project on Mac OS Leopard and XCode

Setting up a basic OpenGL project on Mac OS Leopard and XCode

I’ve recently setup a basic OpenGL project in XCode to have a black window.

In XCode select File->New Project. Select an Empty Project and name it whatever you want, screenie below:




newproject




Within XCode select Project->New Target again. Select Cocoa on the left then Application and name it whatever you’d like.




targetapp




You will now see a window with a whole bunch of settings. In the General tab press the + button in Linked Libraries. Add OpenGL.Framework and Glut.framework from the list of frameworks in the dialog that appears.




generalwindow




Next select Build in the tabs along the top and clear the bottom field GCC_PREFIX_HEADER so that its blank.




targetsettings




In the Groups and Files explorer right click on the top level project and select Add->New File. Choose C and C++ and select C file. Again choose whatever name you wish.




candc_





Paste the following code into the C file:

#include stdlib.h
#include GLUT/glut.h

void myCustomDisplay(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glutSwapBuffers();
}

void myCustomReshape(int width, int height)
{
    glViewport(0, 0, width, height);
}

void doSomethingWhenIdle(void)
{
    glutPostRedisplay();
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);

    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(800, 600);

    glutCreateWindow("My First Window");

    glutDisplayFunc(myCustomDisplay);
    glutReshapeFunc(myCustomReshape);
    glutIdleFunc(doSomethingWhenIdle);

    glutMainLoop();
    return EXIT_SUCCESS;
}

Next Build the application using ‘Build and Go’ and you’ll be presented with a 800×600 empty window with the title ‘My First Window’, easy! I won’t go into the explanation of the different functions, there are plenty of sites out there for that!

Categories: C/C++ Tags:
  1. No comments yet.
  1. No trackbacks yet.

Anti-Spam Protection by WP-SpamFree