OpenGL: Meshes and PNG Textures

October 25, 2009 | Filed Under OpenGL | No Comments

Still experimenting with OpenGL, I’ve played just few games in my life Formula 1 and Tomb Raider. The second one, is more interesting to “reproduce” to learn something of OpenGL, meshes and how all of this world works. Following the latest posts, I’ve added the PNG support to the GLData Sample, so you can now load BMP and PNG Textures.

OpenGL Meshes

The Source Code is available here: GL Data Source Code.

OpenGL meets Blender: Meshes and Textures

October 17, 2009 | Filed Under OpenGL | No Comments

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.

OpenGL Blender Yo Frankie Chars

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.

OpenGL: Gts Format, Lights and Cameras

October 11, 2009 | 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.

OpenCL is for Everyone!

October 8, 2009 | Filed Under OpenCL | No Comments

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