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;
}