PDA

View Full Version : Render ODE Objects With OpenGL ES 2.0



lovelyboy
08-09-2010, 04:10 AM
Hi group,

I am now trying to develop an app both with ODE and OpenGL ES2.0 libraries, which aims to build dynamic simulations on mobile devices.

While the very first problem is how to translate the attributes of ODE object such like a cube, to be represented by vertex, coordinates and normals arrays, which would be necessary for rendering with OpenGL ES 2.0 shading language.

I've got a sample code for explaination, for creating a cube in ODE world

Cube::Cube(dWorldID world, dSpaceID space, dReal width, dReal
height, dReal depth, dReal mass)
{
body = dBodyCreate(world);
geom = dCreateBox(space, width, height, depth);

dMass m;
dMassSetBox(&m, 1.0f, width, height, depth);
dMassAdjust(&m, mass);
dBodySetMass(body, &m);

dGeomSetBody(geom, body);

}

... ...

Cube *cube = new Cube(world, space, 0.3, 0.3, 0.3, 1);


For rendering an object in OpenGL ES 2.0

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,m_uiTexture);

GLfloat afVertices[]= //todo...vertex arrays
glVertexAttribPointer(vertexAttr2, 3, GL_FLOAT, GL_FALSE, 0, afVertices);
glEnableVertexAttribArray(vertexAttr2);

GLfloat afTexCoord[]=//todo...coordinates arrays
glVertexAttribPointer(texCoordAttr2, 3, GL_FLOAT, GL_FALSE, 0, afTexCoord);
glEnableVertexAttribArray(texCoordAttr2);

GLfloat afNormals[]=//todo...normal arrays
glVertexAttribPointer(normalAttr2, 3, GL_FLOAT, GL_FALSE, 0, afNormals);
glEnableVertexAttribArray(normalAttr2);

glUniform1i(textureUniform2, 0); //use texture unit 0

glDrawArrays(GL_TRIANGLES, 0, 36);

glDisableVertexAttribArray(vertexAttr2);
glDisableVertexAttribArray(normalAttr2);
glDisableVertexAttribArray(texCoordAttr2);

I think the point is how to complete the "todo..." in the code.

Thank you.

Alfonse Reinheart
08-09-2010, 09:58 AM
ODE is a physics and collision library. It's job is to decide where objects are at a particular point in time. In terms of rendering, the important information you need from it is the position and orientation of the object.

What the object looks like is up to you, not ODE or OpenGL.