At last,i´ve done it by texturizing 3D TRIANGLES, but using some modifications:
First I take real screen size by this function located at Surface class:
Using java Syntax Highlighting
onSizeChanged(int w, int h, int oldw, int oldh)
{
if(w != 0 && h != 0)
{
screenW = w;
screenH = h;
}
}
Parsed in 0.039 seconds, using
GeSHi 1.0.8.4
Then, once painted all 3D game, I can paint 2D INTERFACE setting up GL10:
Using java Syntax Highlighting
// Reset projection matrix:
gl.glMatrixMode (GL10.GL_PROJECTION);
gl.glLoadIdentity ();
// Then change render type to orthogonal to prevent perspective using real screen size (1 pixel = 1 unit)
gl.glOrthof (0f, screenW, screenH, 0f, 0f,1f);
// Reset modelview
gl.glMatrixMode (GL10.GL_MODELVIEW);
gl.glLoadIdentity ();
// And at last, I eliminate DEPH TEST to prevent triangle ordering
gl.glDisable(GL10.GL_DEPTH_TEST);
Parsed in 0.037 seconds, using
GeSHi 1.0.8.4
Now I can paint all 3D elements:
All elements have to had its own triangles to be texturized, but this triangles should be defined in 2D:
Using java Syntax Highlighting
// Points coords:
float[] coords =
{
// X, Y
20 , 10,
20 , 0,
0 , 0,
0 , 10
};
//Texture coords
float[] texturCoords = new float[]
{
1f , 1f,
1f , 0.005f,
0.005f , 0.005f,
0.005f , 1f
};
// Triangle Strip definition:
float[] vertex_strip = {1,0,2,3};
Parsed in 0.047 seconds, using
GeSHi 1.0.8.4
then you should create buffers (coordsBuffer,textureBuffer,triangleStripBuffer), and then you can call all paint functions.
This is an example to paint only a 2D image texturized BUT USING "real pixel" size.
Using java Syntax Highlighting
gl.glActiveTexture (GL10.GL_TEXTURE0);
gl.glBindTexture (GL10.GL_TEXTURE_2D, textureIndex);
gl.glFrontFace (GL10.GL_CW);
gl.glPushMatrix();
// Place element:
gl.glTranslatef (x, y, 0); // X and Y are real pixel coords
// Set VERTEX buffer (see that we specify 2 coords per element instead 3 because we have defined coords as 2 elements
gl.glVertexPointer (2, GL10.GL_FLOAT, 0, coordsBuffer);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer );
gl.glDrawElements (GL10.GL_TRIANGLE_STRIP, vertex_strip.length, GL10.GL_UNSIGNED_SHORT, triangleStripBuffer);
gl.glPopMatrix();
Parsed in 0.071 seconds, using
GeSHi 1.0.8.4
Thats all.