PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

floating point data type to fixed point data type

I used Vincent implementation of OpenGL ES making some 3D graphic in PPC2003 emulator, but I want to do it in fixed point math. Can anyone help me to change a few line of the code for my reference? Besides, how can I show the FPS on the PPC emulator? Would it be no difference on and emulator using fixed point or floating or not because it is run on a desktop PC? Thousands of Thanks!! Here is what the code are:
Code:

#include <stdlib.h>
#include "ug.h"

#if 0
#define drawOneLine(x1,y1,z1,x2,y2,z2) glBegin(GL_LINES);
glVertex3f ((x1),(y1),(z1)); glVertex3f ((x2),(y2),(z2)); glEnd();
#else
static void drawOneLine(float x1, float y1, float z1, float x2, float y2, float z2) {
GLfloat v[6];
v[0] = x1; v[1] = y1; v[2] = z1; v[3] = x2; v[4] = y2; v[5] = z2;
glVertexPointer(2, GL_FLOAT, 0, v);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_LINES, 0, 2);
}
#endif

static int spin = 0, rot = 0;

/* Initialize material property, light source, lighting model,
* and depth buffer.
*/
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}

/* Here is where the light position is reset after the modeling
* transformation (glRotated) is called. This places the
* light at a new position in world coordinates. The cube
* represents the position of the light.
*/


void display(UGWindow uwin)
{
GLfloat position[] = { 5.0, 5.0, 5.0, 1.0 };
//GLfixed position[] = { 5, 5, 5, 1 };

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix ();
glTranslatef (0.0, -3.0, 0.0);
glScalef (30, 0.1, 30);
glDisable (GL_LIGHTING);
glColor4f (0.0, 1.0, 0.0, 0.0);
ugSolidCubef(2); //ground
glEnable (GL_LIGHTING);
glPopMatrix ();

glPushMatrix ();

glRotatef ((GLfloat) spin, 0.0, 1.0, 0.0);


glPushMatrix ();
glRotatef ((GLfloat) spin, 1.0, 0.0, 0.0);
glLightfv (GL_LIGHT0, GL_POSITION, position);

glTranslatef (5.0, 5.0, 5.0);
glDisable (GL_LIGHTING);
glColor4f (1.0, 0.0, 0.0, 1.0);
ugWireCubef(0.1); //the moving light
glEnable (GL_LIGHTING);
glPopMatrix ();

glPushMatrix (); //seat
glTranslatef (0.0, 0.1, -0.7);
ugSolidSpheref(0.6, 20, 16);
glPopMatrix ();

glPushMatrix (); //body
glTranslatef (0.0, 0.0, 0.0);
glScalef (0.5, 0.1, 3.5);
ugSolidCubef(2);
glPopMatrix ();

glPushMatrix (); //R wing
glTranslatef (2.0, 0.0, 1.8);
glRotatef (45.0, 0.0, 1.0, 0.0);
glScalef (0.5, 0.1, 2.5);
ugSolidCubef(2);
glPopMatrix ();

glPushMatrix ();
glTranslatef (2.0, 0.0, 2.8);
glRotatef (45.0, 0.0, 1.0, 0.0);
glScalef (0.5, 0.1, 2.5);
ugSolidCubef(2);
glPopMatrix ();

glPushMatrix (); //L wing
glTranslatef (-2.0, 0.0, 1.8);
glRotatef (-45.0, 0.0, 1.0, 0.0);
glScalef (0.5, 0.1, 2.5);
ugSolidCubef(2);
glPopMatrix ();

glPushMatrix ();
glTranslatef (-2.0, 0.0, 2.8);
glRotatef (-45.0, 0.0, 1.0, 0.0);
glScalef (0.5, 0.1, 2.5);
ugSolidCubef(2);
glPopMatrix ();




glPopMatrix ();

glFlush ();
ugSwapBuffers(uwin);
}

void reshape (UGWindow uwin, int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
ugluPerspectivef(80.0, (GLfloat) w/(GLfloat) h, 1.0, 400.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
ugluLookAtf(10.0, 10.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}

void animate(UGWindow uwin)
{
spin = (spin + 2) % 360;
ugPostRedisplay(uwin);
}


void mouse(UGWindow uwin, int button, int state, int x, int y)
{
switch (button) {
case UG_BUT_LEFT:
if (state == UG_BUT_DOWN) {
ugIdleFunc(ugCtxFromWin(uwin), animate);
}
break;
case UG_BUT_RIGHT:
if (state == UG_BUT_DOWN) {
ugIdleFunc(ugCtxFromWin(uwin), NULL);
}
break;
default:
break;
}
}

void keyboard(UGWindow uwin, int key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
}
}

int main(int argc, char** argv)
{
UGCtx ug = ugInit();
UGWindow uwin = ugCreateWindow (ug, "UG_DEPTH", argv[0], 500, 500, 100, 100);
init ();
ugDisplayFunc(uwin, display);
ugReshapeFunc(uwin, reshape);
ugPointerFunc(uwin, mouse);
ugKeyboardFunc(uwin, keyboard);
ugMainLoop(ug);
return 0;
}
jackeung wrote:I used Vincent implementation of OpenGL ES making some 3D graphic in PPC2003 emulator, but I want to do it in fixed point math. Can anyone help me to change a few line of the code for my reference? Besides, how can I show the FPS on the PPC emulator? Would it be no difference on and emulator using fixed point or floating or not because it is run on a desktop PC?

Here's an introduction to fixed point and OpenGL ES that was given at GDC: http://www.khronos.org/devu/library/sf_2005/opengles_general/Imagination_-_Real_Number_Abstraction.ppt
In general, to define a number as GLfixed you will need to shift the corresponding integer by 16 bits,
e.g. instead of
Code:

GLfixed position[] = { 5, 5, 5, 1 };

it is
Code:

GLfixed position[] = { 5 << 16, 5 << 16, 5 << 16, 1 << 16};


You might find this thread helpful: http://www.pocketmatrix.com/forums/viewtopic.php?t=20700

To show FPS, look at the car example for Vincent. It's really just using GDI to render the text. You can find it in CVS: http://cvs.sourceforge.net/viewcvs.py/ogl-es/ogles/test/paint.cpp?rev=1.8&view=auto
Look at the last 20 lines or so.

The implementation of the core rendering process is actually very different depending on whether you are using an emulator or a real device (former is just for debugging, the latter uses the JIT). So I wouldn't bother taking any benchmarks using the emulator.

Hope that helps,
HM
Thanks so much hm :)

I think I have no time to study all these thing clearly because I have to demo something(about fixed point) for my project :(

Is there anything I can add in fixed.cpp or fixed.h in Vincent to modify its fixed function? Any ideas or hints? Thanks.