Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/dfmoore/notes.binarytree.org/textpattern/lib/txplib_db.php on line 14
Notes: Using OpenGL in a LibDC1394/Xcode project

Notes

 
 

Using OpenGL in a LibDC1394/Xcode project

May 13, 12:17 PM

1. Include OpenGL related files at the top of Main:

//OpenGL related stuff:
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#include <OpenGL/glu.h>
#include <OpenGL/glext.h>

2. Include the OpenGL and GLUT frameworks into your project:

- Right click on the project file list, and choose “Add>Existing frameworks”

- Navigate to /System/Library/Frameworks/ and find “OpenGL.framework”

- Also add “GLUT.framework” in the same way.

3. Create a few callback functions for GLUT:

void display(void)
{
//Drawing commands to go here later...
    glutSolidCube(1.0f);
    std::cout<<"Hello, World!\n"; //print every frame.
    glutSwapBuffers();
    glutPostRedisplay();
}
void reshape(int w, int h)
{
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(40.0, (GLfloat) w/ (GLfloat) h, .2, 1500.0); 
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(5,5,5, 0, 0, 0, 0, 1,0); 
}

4. Set up main() to work with GLUT:

int main (int argc, char * argv[]) 
{
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    glutInitWindowSize(640,480); 
    glutCreateWindow ("FACE!");
    glutReshapeFunc (reshape);
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}

NB: I’ve changed what main expects as parameters.

Compiling at this point will give you a blank, rendering 640×480 window with a camera set up and a unit cube sitting on the origin.

Next article, I’ll show you how to bring OpenCV into this project and work with the images coming from a pair of cameras.

Comments