Sunday, October 11, 2009

OpenGL: Gts Format, Lights and Cameras

During my work, I've found an interesting library GNU Triangulated Surface Library ( 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.
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);

      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);


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:

Post a Comment