Tuesday, January 26, 2010

OpenGL / GLES Picking Method in Poseidon

I will explain, how in Poseidon Picking method works.

First of all, the method of picking in OpenGL using glRenderMode(GL_SELECT) and co. are not available under OpenGL ES.

After googling, I found this solution :
  • When the mouse is pressed I make a quick render of the scene. The texture are disabled, color shading is disabled and other effects are also disabled.(fog, lights, dither ...)
    When a GLObject is rendered a color is associated to this object. Ex: (0A,05,00). As there is the GLWrapper, the color used for rendering is bypass here.
  • Once the scene is rendered, I read the pixel at the clicked position. Then, we can compare the read color and GLObject color. We look if color are similar, not exactly match. When you are in 16 bits color rendering, colors may be scaled. That's why when we assign a color to GLObject, we step the next color value of 32(edit : explaination after).
  • After that, we render the scene normaly and swap buffers.
Here a rendering using this 
picking method.(Not visible on screen)


And now the visible rendering.

Here the computation to select GLObject color :
  • Select a Red, Green and Blue unique value. Each channel value should be in  [0..32[
  • Left Shift Bit each channel by 3
NOTE : With this methods, 32x32x32 = 32768 objects are selectable !

When a color is read, compare each channel of read color(Cr) and object color(Co).
For each channel C :
if (abs(Cr-Co) < D)
{
    // Channel match !
}

Where is equal to 5 8. For each color you can have an error of 10 (Co +5 or -5).
EDIT : 
To sum up :
- each R/G/B values are in [0..32[
- After the bit shift of 3, the result R/G/B are in [0..256[


When you are in 24-bits colors :
- When you read back the pixel, you will get the exact same value.


But in 16-bits colors mode (for instance 565) :
- When you read back the pixel, R is coded on 5 bits, G on 6 and B on 5 bits.
Let's look on Red channel. The possibles values are limited to 2⁵ = 32.
So the red value is fitted from 256 to 32 ranged.
The way that the value is scaled is obscur for me but if you draw with
red value of 200 and you read back the value, it will be 206.
But anyway, this difference cannot exceed 8 = 256 / 32.




Impressive !!!

http://mi.eng.cam.ac.uk/~qp202/

And the video :




"The system works by calculating the Delaunay tetrahedralisation of a point cloud obtained from on-line structure from motion estimation which is then carved using a recursive and probabilistic algorithm to rapidly obtain the surface mesh."

When I was at University, I have worked on a project using Delaunay triangulation, A-Shape and Voronoï diagram. Our project was to rebuild A-Shape from a point cloud. We used the library CGAL (http://www.cgal.org/) to compute each shape.

Friday, January 22, 2010

A test application

Here my first test applications using Poseidon and running on Linux and on Android emulator :


for his tutorial on MD2 :) and his quake II model.

Poseidon on Android is not a full JAVA application. It was built using android NDK.
There is JAVA code, but only to start a GL rendering view. All the rest is the same code (except Poseidon porting layer) as linux application.
As you can notice, bitmap loading is not yet implemented ^^. As far as I know, there is 3 ways to load a bitmap on Android platform :


Any advice on this point is welcomed :)

For the moment, I will cheat :
  • serialize the Image object to a file from PC version
  • copy the file onto Android 
  • deserialize the image from this file on Android platform.

Here the result on another model :

As you can see there is no difference 
between applications


What is Poseidon ? What is it for ?

The goal of this project is to ease development of 3D applications and UI on multiple devices.

NOTE : All codes of this library was written from scratch.

Here a summary of this library (it could change in future) :



This library is written in C++ but it does not used STL. On severals embeded platforms, STL is not availabled (ex : Android).

  • It's designed to use easily system resources such as Thread, Mutexes, Semaphore, Inter-process communications, files and resources access. It also provides tools to make Inter-process API.
  • You can serialize objects and store them in a file and restore them later or send them serialized to another process. You can access an object using its URL and open it like a file.
  • It also try to simplify 3D programming by wrapping OpenGL to OpenGL ES. The library provides a "GLServer" that allows to make simple 3D scene. There is also an implementation of OGL picking methods that works with OGLES.
  • It will also provides basic tools to make 2D UI elements.
The main goal is to make something simple for developpers.
For the moment, current Poseidon implementation depends on :


Background

I was an employee of a French company (Digital Airways). We developped tools to make UI for mobile and embedded devices such as mobile phone, set-top box... Most of applications were 2D UI. But I have worked on 3D UI. Here a sample of project I've worked on :



And here a video of this application on a HTC Touch Diamond:
But these projects were left out :(
Moreover, the UI tool we used, was not designed to make 3D applications.
I left the company due to crisis.
Now, I decided to start my own project.