Hello everyone,
I want to use the sdk for an augmented reality project so I want to know how some things are done maybe someone can help me trough.
For the models I want to render I use a Java library to parse from a certain file format. This file will be somewhere on the internet just like the trackables will be. Since I'm not very familiar to cpp I want to use Java to render the models.
Later I want to use the virtual buttons to trigger some animations from the model. But for now I like to know how to get started with rendering a simple cube on a trackable.
For my project I use some code from a good tutorial written by Per-Erik Bergman http://blog.uncle.se/.
private Mesh root;
public OpenGLRenderer(MainActivity mainActivity) {
Group group = new Group();
Mesh mesh = new Mesh();
short[] indices = {0, 4, 5,
0, 5, 1, 1, 5, 6, 1, 6, 2, 2, 6, 7, 2, 7, 3, 3, 7, 4, 3, 4, 0, 4, 7, 6, 4, 6, 5, 3, 0, 1,3, 1, 2,};
float[] vertices = {-width, -height, -depth, // 0
1, -1, -1, // 1 1, 1, -1, // 2 -1, 1, -1, // 3 -1, -1, 1, // 4 1, -1, 1, // 5 1, 1, 1, // 6-1, 1, 1, // 7};mesh.setVertices(vertices);
mesh.setIndices(indices);
group.add(mesh);
root = group;
}
/*
* (non-Javadoc)
*
* @see
* android.opengl.GLSurfaceView.Renderer#onSurfaceCreated(javax.microedition
* .khronos.opengles.GL10, javax.microedition.khronos.egl.EGLConfig)
*/
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// Set the background color to black ( rgba ).
gl.glClearColor(0.224f, 0.224f, 0.224f, 0.0f);
// Enable Smooth Shading, default not really needed.
gl.glShadeModel(GL10.GL_SMOOTH);
// Depth buffer setup.
gl.glClearDepthf(1.0f);
// Enables depth testing.
gl.glEnable(GL10.GL_DEPTH_TEST);
// The type of depth testing to do.
gl.glDepthFunc(GL10.GL_LEQUAL);
// Really nice perspective calculations.
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
}
/*
* (non-Javadoc)
*
* @see
* android.opengl.GLSurfaceView.Renderer#onDrawFrame(javax.microedition.
* khronos.opengles.GL10)
*/
public void onDrawFrame(GL10 gl) {
// Clears the screen and depth buffer.
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
// Replace the current matrix with the identity matrix
gl.glLoadIdentity();
// Translates 4 units into the screen.
gl.glTranslatef(0, 0, -4);
// Draw our scene.
root.draw(gl);
}
/*
* (non-Javadoc)
*
* @see
* android.opengl.GLSurfaceView.Renderer#onSurfaceChanged(javax.microedition
* .khronos.opengles.GL10, int, int)
*/
public void onSurfaceChanged(GL10 gl, int width, int height) {
// Sets the current view port to the new size.
gl.glViewport(0, 0, width, height);
// Select the projection matrix
gl.glMatrixMode(GL10.GL_PROJECTION);
// Reset the projection matrix
gl.glLoadIdentity();
// Calculate the aspect ratio of the window
GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f,
100.0f);
// Select the modelview matrix
gl.glMatrixMode(GL10.GL_MODELVIEW);
// Reset the modelview matrix
gl.glLoadIdentity();
}
}
How do I get this cude rendered on the trackable? What cpp files and methods do I need to use to get this done if whe take the basic ImageTargets example? Can some one explain this to me? I think that I am not the only one who wants to know this.
Thanks in advance.