Log in or register to post comments

Pls explain..

March 15, 2012 - 8:25am #2

Can som 1 pls explain imagetarget.cpp....
If not whole file atleast a method such as renderframe in brief...

Re: Pls explain..

March 15, 2012 - 7:48pm #1

Sure, I'll explain the renderFrame method in brief. Let's focus on the OpenGL ES 2.0 code, ignore everything surround by #ifdef USE_OPENGL_ES_1_1.

renderFrame is called each frame (as the name suggests). It acquires the tracking info (state) for this frame via the QCAR::Renderer::getInstance().begin() call. It then renders the camera image via the QCAR::Renderer::getInstance().drawVideoBackground() call.

Then, it iterates through all of the visible trackables for the frame. For each of these, it gets the pose matrix and converts it into a modelview matrix usable by OpenGL. This matrix can be used to place 3D objects on the trackable.

Then it checks the name of the target and chooses a texture to render with.

Then it scales and translates the 3D object so it sits correctly on the target plane. It also multiplies the modelview matrix by the projection matrix. These are basic OpenGL concepts, the modelview matrix places the 3D content and the projection matrix describes how the camera renders the scene.

It binds the shader that will be used to render the object. OpenGL ES 2.0 always uses shaders, which are programs that run on the GPU. It binds the vertex, normal, and texture coordinate arrays so the shader can access them. It enables these arrays. It binds the texture, and binds the modelViewProjection matrix created earlier. Finally it draws the model with the call to glDrawElements.

That's it! Working knowledge of OpenGL will help a lot here, as you can see.

- Kim

Log in or register to post comments