OpenGL: Gts Format, Lights and Cameras

October 11, 2009 Matteo Bertozzi | Filed Under OpenGL | No Comments

During my work, I’ve found an interesting library GNU Triangulated Surface Library (http://gts.sourceforge.net/) that does, some nice things, like Constrained Delaunay triangulations. But what I was really searching today are just meshes to use in my OpenGL experiments. And there’re a some GTS samples available on the GTS website.

GlData Gts Sample

The screenshot above represents a GTS sample shape with a simple light effect. Just few lines of code to do it. But what I’m interested in, is create a simple way to load GTS file format, and below you can see the code.

void drawObject (const char *gts_shape_filename) {
    GLDataGts *gts;

    gts = glDataGtsAlloc();
    if (glDataGtsRead(gts, gts_shape_filename)) {
        GLDataSurface *surface;
        GLDataUInt i, count;
        GLDataTriangle *t;

        /* The Surface is an array of Triangles */
        surface = glDataGtsSurface(gts, NULL);
        count = glDataSurfaceCount(surface);
        for (i = 0; i < count; ++i) {
            t = glDataSurfaceGet(surface, i);

            glBegin(GL_LINE_LOOP);
            glVertex3f(t->p1->x, t->p1->y, t->p1->z);
            glVertex3f(t->p2->x, t->p2->y, t->p2->z);
            glVertex3f(t->p3->x, t->p3->y, t->p3->z);
            glEnd();
        }
    }

    glDataGtsRelease(gts);
}


The Source code is available here GLDataGts Source Code, and main.c contains a few comment lines that explain how to compile and run. Check the keyboardHandler() function to learn how to interact with the OpenGL camera and lights.

No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>