Saturday, October 17, 2009

OpenGL meets Blender: Meshes and Textures

As you can see from the bigger Screenshot below, Today is time to put some characters on the OpenGL stage. And the two guys below are two of the characters of Yo Frankie! (http://www.yofrankie.org/). Following the preview post I've extended my GLData Library adding support for Textures and using another source format as Input File, I've also made a simple Blender-Export Script that allows you to easily export blender meshes with textures, vertexes and faces.
If you are, as me, fan of black and white command lines, The result is stunning. And there're just few lines of code. The code can be downloaded from here: GLData Blender Source Code. It contains the source code, textures, meshes and the Blender Export Script.

Sunday, October 11, 2009

OpenGL: Gts Format, Lights and Cameras

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.
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.

Thursday, October 8, 2009

OpenCL is for Everyone!

Last night I had a terrible nightmare, where all the apple/mac bloggers says "This app cannot be use used with older macs because it uses OpenCL, so you need the newest NVidia…"

..Fortunately, was just a nightmare. Everyone can use OpenCL, old macs (as my macbook) cannot use GPU, and cannot run faster, but OpenCL code can run on every machine.

You (as developer) need just to keep in mind to get Device in this way. So, if you haven't the latest NVidia you can still use, as always, CPU.


err = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, 1, &device_id, NULL);
if (err != CL_SUCCESS)
  err = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_CPU, 1, &device_id, NULL);