OpenGL: Walk Around Camera

November 1, 2009 | Filed Under OpenGL | No Comments

Again, another week spent on OpenGL. I don’t know why but I cannot stop to experiment with Meshes, Vertexes, Faces and Textures. It’s too amusing! But Todays, post it’s just an update of GLData, the small gl data library that I use for my experiments.

OpenGL Walk Around

The new features, for this update are: Speed-up in GL throughput, and Camera. I’ve adjusted data structure to use directly glVertexPointer() and related gl*Pointer() functions. The main.c file was adjusted to handle direction keys (Up, Down, Left, Right) to allows you to walk in your 3d world, like any First-Person shooter video game.

You can download the GLData Walk Around Source Code it. (Mesh not Included)

PS: For my Qt followers, and for those which they are waiting for my File-System/Distributed Computational System: I haven’t forget Qt and the lovely memset(); I’m just exploring a bit (give me some week), a world that I’ve completely ignored.

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.

OpenGL: 3D Cube, Rotation, Translation and Texts

July 14, 2009 | Filed Under OpenGL | No Comments

Second hour with OpenGL, last time I’ve written a simple 2D example to learn what Vertex are, and now a little step forward using 3D, Rotation, Translation and Texts.

OpenGL 3D Cube

Using GLUT writing 2D texts is really simple, and here is how to do it. Setup Text Color, X and Y Location, pick up a font and set your string, and it’s done.

glColor3f(1.0, 0.0, 0.0);
glRasterPos2f(-4.6, 2.3);
glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, 'Hello Text');


To handle left, right, up, down keys to move the cube use the glutSpecialFunc() that allows you to handle GLUT_KEY_LEFT, GLUT_KEY_RIGHT, GLUT_KEY_UP, GLUT_KEY_DOWN keys and others. Translation and rotation are made using glTranslatef() and glRotatef().

The source code is available here: Python OpenGL 3D Cube Source Code.

OpenGL: First Test – 2D Example

July 12, 2009 | Filed Under OpenGL | No Comments

I’m not a Computer Graphics fan, but I’ve spent my the last year working on Report Engine, and User Interfaces… drawLine, drawRect.. setLocation… (I don’t know.. I’m a malloc/memset boy).

But I need to learn more about Computer Graphics for the future, and today I’ve started playing with OpenGL… No more 2D points!!! :D

OpenGL 2d 1st Test

Below you can see a couple of lines of code that draws the example above…

static void drawTriangle (void) {
    glColor3f(0.0f, 0.0f, 1.0f);
    glBegin(GL_TRIANGLES);

   glVertex3f( 0.0f,  0.6f, 0.0f);
   glVertex3f(-0.2f, -0.3f, 0.0f);
   glVertex3f( 0.2f, -0.3f, 0.0f);

   glEnd();
}

static void drawSquare (void) {
    glColor3f(1.0f, 0.0f, 0.0f);
    glBegin(GL_TRIANGLE_FAN);

    glVertex3f(0.0f, 0.0f, 0.0f);
    glVertex3f(0.5f, 0.0f, 0.0f);
    glVertex3f(0.5f, 0.5f, 0.0f);
    glVertex3f(0.0f, 0.5f, 0.0f);

    glEnd();
}

static void drawSquareMode2 (void) {
    const GLfloat squareVertices[] = {
        -0.2,  0.2, 0.2,
        -0.2, -0.2, 0.2,
         0.2, -0.2, 0.2,
         0.2,  0.2, 0.2
    };

    glColor3f(0.0f, 1.0f, 0.0f);
    glVertexPointer(3, GL_FLOAT, 0, squareVertices);
    glEnableClientState(GL_VERTEX_ARRAY);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}


I’ve used NSOpenGLView to display the GL, so the drawing code is inside a drawRect method.

- (void)drawRect:(NSRect)bounds {
    glClearColor(0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT);

    glTranslatef(-0.2f, 0.0f, 0.0f);
    drawTriangle();

    glTranslatef(0.2f, 0.0f, 0.0f);
    drawSquare();
    drawSquareMode2();

    glFlush();
}