Archive for December, 2010

OpenGL blue ribbons

Wednesday, December 29th, 2010

Another trial with OpenGL + Verlet integration. It worked nicely considering the time I spent to code it (less than 1h while finishing two beer cans) but I’m not satisfied with the rendering quality and the lighting.


video on vemeo


String of fire, verlet integration

Tuesday, December 28th, 2010

Now I have reached the stage of experimenting with point sprites, which is a method to allocate bitmap images to points – not on the surfaces of objects – and quite useful when working with particle systems.
The merit of using Openframeworks is that it gets rid of the lengthy preparation to use openGL methods. Thanks to the example on memo.tv, it was just a matter of a few minutes to implement the bitmap texture to the existing code.

The movement of the string is done with Verlet integration. This is also a quite useful method with which you can simulate Newtonian physics focusing only on the coordinates of the things without caring so much about vectors and other complicated mathematics. A simple implementation of Verlet integration is available from my (quasi) math and physics site.


video on vimeo


Fluid particles

Saturday, December 25th, 2010

To test the performance of Openframeworks, I’ve made a movie of 40000 particles in motion. I’ve got a long way to go yet to get used to C++.

Video on Vimeo

OpenGL + Openframeworks

Thursday, December 23rd, 2010

I’ve started studying openGL on openframeworks, kinda overwhelmed with its gigantic specification (The most popular guide book weighs 3lbs!). Anyway, this is my first step. A rotating cube with blue and red lighting. Moving? Yes, both kinematically and emotionally.

void testApp::setup(){
 ofSetWindowTitle("OpenGL - test02");
 ofBackground(0, 0, 0);
 counter = 0.0;

 GLfloat light0pos[] = { 100.0, 300.0, 800.0, 1.0 };
 GLfloat light1pos[] = { 500.0, 300.0, 0.0, 1.0 };
 GLfloat blue[] = { 0.2, 0.4, 1.0, 0.8 };
 GLfloat red[] = { 1.0, 0.3, 0.4, 0.5 };

 glEnable(GL_LIGHTING);
 glEnable(GL_LIGHT0);
 glEnable(GL_LIGHT1);
 glLightfv(GL_LIGHT0, GL_DIFFUSE, red);
 glLightfv(GL_LIGHT1, GL_AMBIENT, blue);

 glLightfv(GL_LIGHT0, GL_POSITION, light0pos);
 glLightfv(GL_LIGHT1, GL_POSITION, light1pos);
}

void testApp::draw(){
 GLdouble vertex[][3] = {
 { -100.0, -100.0, -100.0 },
 { 100.0, -100.0, -100.0 },
 { 100.0, 100.0, -100.0 },
 { -100.0, 100.0, -100.0 },
 { -100.0, -100.0, 100.0 },
 { 100.0, -100.0, 100.0 },
 { 100.0, 100.0, 100.0 },
 { -100.0, 100.0, 100.0 }
 };
 int edge[][2] = {
 { 0, 1 },
 { 1, 2 },
 { 2, 3 },
 { 3, 0 },
 { 4, 5 },
 { 5, 6 },
 { 6, 7 },
 { 7, 4 },
 { 0, 4 },
 { 1, 5 },
 { 2, 6 },
 { 3, 7 }
 };
 int face[][4] = {
 { 0, 1, 2, 3 },
 { 1, 5, 6, 2 },
 { 5, 4, 7, 6 },
 { 4, 0, 3, 7 },
 { 4, 5, 1, 0 },
 { 3, 2, 6, 7 }
 };
 GLdouble normal[][3] = {
 { 0.0, 0.0,-1.0 },
 { 1.0, 0.0, 0.0 },
 { 0.0, 0.0, 1.0 },
 {-1.0, 0.0, 0.0 },
 { 0.0,-1.0, 0.0 },
 { 0.0, 1.0, 0.0 }
 };
 GLfloat red[] = { 0.8, 0.2, 0.2, 1.0 };
 GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 };
 ofPushMatrix();
 ofTranslate(ofGetWidth()/2.0, ofGetHeight()/2.0, 0.0);
 ofRotateY(counter);
 ofRotateZ(counter * 1.1);
 counter += 0.01;
 glEnable(GL_CULL_FACE);
 glCullFace(GL_BACK);
 glColor3d(1.0, 1.0, 1.0);
 glBegin(GL_QUADS);
 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red);
 for (int j = 0; j < 6; ++j) {
 glNormal3dv(normal[j]);
 for (int i = 0; i < 4; ++i) {
 glVertex3dv(vertex[face[j][i]]);
 }
 }
 glEnd();
 ofPopMatrix();
}
Related Posts with Thumbnails