Пример #1
0
int
main (int argc, char* argv[])
{
  int cable_type, quit = 0;
  float rot1 = 0.0, rot2 = 0.0, rot3 = 0.0;
  kos_img_t front_txr, back_txr, tmp_img;
  pvr_ptr_t texaddr;
  GLuint texture[8];
  int blendfunc = 2;
  float eye_rot = 0;

  cable_type = vid_check_cable ();
  
  if (cable_type == CT_VGA)
    vid_init (DM_640x480_VGA, PM_RGB565);
  else
    vid_init (DM_640x480_PAL_IL, PM_RGB565);
  
  init_pvr ();

  glKosInit ();

  sphere = mkspheredata (3, &nstrip, &stripl);

  glGenTextures (8, &texture[0]);

#if 1
  kmg_to_img ("/rd/sky1.kmg", &front_txr);
  texaddr = pvr_mem_malloc (front_txr.byte_count);
  pvr_txr_load_kimg (&front_txr, texaddr, PVR_TXRFMT_VQ_ENABLE);
  kos_img_free (&front_txr, 0);
  
  glBindTexture (GL_TEXTURE_2D, texture[0]);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, front_txr.w, front_txr.h,
	      texaddr);

  kmg_to_img ("/rd/sky2o.kmg", &back_txr);
  texaddr = pvr_mem_malloc (back_txr.byte_count);
  pvr_txr_load_kimg (&back_txr, texaddr, PVR_TXRFMT_VQ_ENABLE);
  kos_img_free (&back_txr, 0);

  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

  glBindTexture (GL_TEXTURE_2D, texture[1]);
  glKosTex2D (GL_ARGB4444_TWID | GL_VQ_ENABLE, back_txr.w, back_txr.h, texaddr);

  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  
  glBindTexture (GL_TEXTURE_2D, texture[2]);
  kmg_to_img ("/rd/sky3.kmg", &tmp_img);
  texaddr = pvr_mem_malloc (tmp_img.byte_count);
  pvr_txr_load_kimg (&tmp_img, texaddr, PVR_TXRFMT_VQ_ENABLE);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, tmp_img.w, tmp_img.h, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[3]);
  kmg_to_img ("/rd/sky4.kmg", &tmp_img);
  texaddr = pvr_mem_malloc (tmp_img.byte_count);
  pvr_txr_load_kimg (&tmp_img, texaddr, PVR_TXRFMT_VQ_ENABLE);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, tmp_img.w, tmp_img.h, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[4]);
  kmg_to_img ("/rd/sky5.kmg", &tmp_img);
  texaddr = pvr_mem_malloc (tmp_img.byte_count);
  pvr_txr_load_kimg (&tmp_img, texaddr, PVR_TXRFMT_VQ_ENABLE);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, tmp_img.w, tmp_img.h, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[5]);
  kmg_to_img ("/rd/sky6.kmg", &tmp_img);
  texaddr = pvr_mem_malloc (tmp_img.byte_count);
  pvr_txr_load_kimg (&tmp_img, texaddr, PVR_TXRFMT_VQ_ENABLE);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, tmp_img.w, tmp_img.h, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[6]);
  kmg_to_img ("/rd/sky7.kmg", &tmp_img);
  texaddr = pvr_mem_malloc (tmp_img.byte_count);
  pvr_txr_load_kimg (&tmp_img, texaddr, PVR_TXRFMT_VQ_ENABLE);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, tmp_img.w, tmp_img.h, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[7]);
  kmg_to_img ("/rd/sky8.kmg", &tmp_img);
  texaddr = pvr_mem_malloc (tmp_img.byte_count);
  pvr_txr_load_kimg (&tmp_img, texaddr, PVR_TXRFMT_VQ_ENABLE);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, tmp_img.w, tmp_img.h, texaddr);

#else  
  png_to_img ("/rd/sky1.png", PNG_MASK_ALPHA, &front_txr);
  texaddr = pvr_mem_malloc (front_txr.w * front_txr.h * 2);
  pvr_txr_load_kimg (&front_txr, texaddr, PVR_TXRLOAD_INVERT_Y);
  kos_img_free (&front_txr, 0);
  
  glBindTexture (GL_TEXTURE_2D, texture[0]);
  glKosTex2D (GL_ARGB1555_TWID, front_txr.w, front_txr.h, texaddr);

  png_to_img ("/rd/sky2o.png", PNG_MASK_ALPHA, &back_txr);
  texaddr = pvr_mem_malloc (back_txr.w * back_txr.h * 2);
  pvr_txr_load_kimg (&back_txr, texaddr, PVR_TXRLOAD_INVERT_Y);
  kos_img_free (&back_txr, 0);

  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

  glBindTexture (GL_TEXTURE_2D, texture[1]);
  glKosTex2D (GL_ARGB1555_TWID, back_txr.w, back_txr.h, texaddr);

  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  
  glBindTexture (GL_TEXTURE_2D, texture[2]);
  texaddr = pvr_mem_malloc (TEXSIZE * TEXSIZE * 2);
  png_to_texture ("/rd/sky3.png", texaddr, PNG_NO_ALPHA);
  glKosTex2D (GL_RGB565_TWID, TEXSIZE, TEXSIZE, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[3]);
  texaddr = pvr_mem_malloc (TEXSIZE * TEXSIZE * 2);
  png_to_texture ("/rd/sky4.png", texaddr, PNG_NO_ALPHA);
  glKosTex2D (GL_RGB565_TWID, TEXSIZE, TEXSIZE, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[4]);
  texaddr = pvr_mem_malloc (TEXSIZE * TEXSIZE * 2);
  png_to_texture ("/rd/sky5.png", texaddr, PNG_NO_ALPHA);
  glKosTex2D (GL_RGB565_TWID, TEXSIZE, TEXSIZE, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[5]);
  texaddr = pvr_mem_malloc (TEXSIZE * TEXSIZE * 2);
  png_to_texture ("/rd/sky6.png", texaddr, PNG_NO_ALPHA);
  glKosTex2D (GL_RGB565_TWID, TEXSIZE, TEXSIZE, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[6]);
  texaddr = pvr_mem_malloc (TEXSIZE * TEXSIZE * 2);
  png_to_texture ("/rd/sky7.png", texaddr, PNG_NO_ALPHA);
  glKosTex2D (GL_RGB565_TWID, TEXSIZE, TEXSIZE, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[7]);
  texaddr = pvr_mem_malloc (TEXSIZE * TEXSIZE * 2);
  png_to_texture ("/rd/sky8.png", texaddr, PNG_NO_ALPHA);
  glKosTex2D (GL_RGB565_TWID, TEXSIZE, TEXSIZE, texaddr);
#endif
  
  glEnable (GL_DEPTH_TEST);
  glEnable (GL_CULL_FACE);
  glEnable (GL_TEXTURE_2D);
  glShadeModel (GL_SMOOTH);
  glClearDepth (1.0f);
  glDepthFunc (GL_LEQUAL);
  
  glMatrixMode (GL_PROJECTION);
  glLoadIdentity ();
  gluPerspective (60.0,			/* Field of view in degrees.  */
		  640.0 / 480.0,	/* Aspect ratio.  */
		  1.0,			/* Z near.  */
		  50.0);		/* Z far.  */

  glMatrixMode (GL_MODELVIEW);
  
  while (!quit)
    {
      MAPLE_FOREACH_BEGIN (MAPLE_FUNC_CONTROLLER, cont_state_t, st)
        {
	  if (st->buttons & CONT_START)
	    quit = 1;
	  
	  eye_pos[0] = st->joyx / 25.0;
	  eye_pos[1] = st->joyy / 25.0;
	  eye_pos[2] = 5 * sin (eye_rot);
	  
	  if (st->buttons & CONT_A)
	    blendfunc = 0;
	  else if (st->buttons & CONT_B)
	    blendfunc = 1;
	  else if (st->buttons & CONT_X)
	    blendfunc = 2;
	}
      MAPLE_FOREACH_END ()
      
      draw_vectors = 10;
      
      glLoadIdentity ();
      gluLookAt (eye_pos[0], eye_pos[1], eye_pos[2],	/* Eye position.  */
		 0.0,   0.0,   0.0,			/* Centre.  */
		 0.0,   1.0,   0.0);			/* Up.  */

      glGetFloatv (GL_MODELVIEW_MATRIX, &camera[0][0]);

      invcamera[0][0] = camera[0][0];
      invcamera[0][1] = camera[1][0];
      invcamera[0][2] = camera[2][0];
      invcamera[0][3] = 0.0;

      invcamera[1][0] = camera[0][1];
      invcamera[1][1] = camera[1][1];
      invcamera[1][2] = camera[2][1];
      invcamera[1][3] = 0.0;

      invcamera[2][0] = camera[0][2];
      invcamera[2][1] = camera[1][2];
      invcamera[2][2] = camera[2][2];
      invcamera[2][3] = 0.0;

      invcamera[3][0] = 0.0;
      invcamera[3][1] = 0.0;
      invcamera[3][2] = 0.0;
      invcamera[3][3] = 1.0;

      /*dbgio_printf ("inverted camera orthogonality: %f %f %f\n",
		    (double) vec_dot (invcamera[0], invcamera[1]),
		    (double) vec_dot (invcamera[1], invcamera[2]),
		    (double) vec_dot (invcamera[2], invcamera[0]));*/

      /*dbgio_printf ("Inverted camera matrix:\n");
      for (i = 0; i < 4; i++)
	{
	  dbgio_printf ("[ %f %f %f %f ]\n",
                	(double) invcamera[0][i], (double) invcamera[1][i],
	        	(double) invcamera[2][i], (double) invcamera[3][i]);
	}*/

      glKosBeginFrame ();

      /*glPushMatrix ();
      glTranslatef (-camera[3][0], -camera[3][1], -camera[3][2]);*/
      render_cube (&texture[2]);
      /*glPopMatrix ();*/
      
      glPushMatrix ();
      
      #if 1
      glRotatef (rot1, 0.0, 1.0, 0.0);
      rot1 += 0.7;
      glRotatef (rot2, 1.0, 0.0, 0.0);
      rot2 += 0.29;
      #else
      glRotatef (rot1, 0.0, 0.0, 1.0);
      rot1 += 0.7;
      #endif
      
      if (rot1 >= 360)
        rot1 -= 360;

      if (rot2 >= 360)
        rot2 -= 360;
      
      eye_rot += 0.05;
      if (eye_rot >= 2 * M_PI)
        eye_rot -= 2 * M_PI;
      
      blob_phase += 0.05;
      if (blob_phase >= 24 * M_PI)
        blob_phase -= 24 * M_PI;
      
      /* Render front.  */
      glBindTexture (GL_TEXTURE_2D, texture[0]);
      glTexEnvi (GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);

      #if 1
      render_blob (sphere, nstrip, stripl, 1);
      #else
      render_torus (1.0, 0.6, 1);
      #endif
            
      glPushMatrix ();
      glRotatef (rot3, 1.0, 0.0, 0.0);
      glTranslatef (2.9, 0.0, 0.0);
      render_torus (0.8, 0.5, 1);
      glPopMatrix ();
      glPushMatrix ();
      glRotatef (-rot3, 1.0, 0.0, 0.0);
      glTranslatef (-2.9, 0.0, 0.0);
      render_torus (0.8, 0.5, 1);
      glPopMatrix ();
      
      glKosFinishList ();

      /* Render back.  */
      glBindTexture (GL_TEXTURE_2D, texture[1]);
      glTexEnvi (GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
      if (blendfunc == 0)
        glBlendFunc (GL_SRC_ALPHA, GL_ZERO);
      else if (blendfunc == 1)
        glBlendFunc (GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
      else
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
      #if 1
      //glDisable (GL_TEXTURE_2D);
      render_blob (sphere, nstrip, stripl, 0);
      //glEnable (GL_TEXTURE_2D);
      #else
      render_torus (1.0, 0.6, 0);
      #endif

      glPushMatrix ();
      glRotatef (rot3, 1.0, 0.0, 0.0);
      glTranslatef (2.9, 0.0, 0.0);
      render_torus (0.8, 0.5, 0);
      glPopMatrix ();
      glPushMatrix ();
      glRotatef (-rot3, 1.0, 0.0, 0.0);
      glTranslatef (-2.9, 0.0, 0.0);
      render_torus (0.8, 0.5, 0);
      glPopMatrix ();

      rot3 += 1;
      if (rot3 >= 360)
        rot3 -= 360;

      glPopMatrix ();
      
      glKosFinishFrame ();
    }
  
  glKosShutdown ();
  
  pvr_shutdown ();
  
  vid_shutdown ();
  /* Make dc-load look nicer.  */
  vid_init (DM_640x480_PAL_IL, PM_RGB565);

  return 0;
}
Пример #2
0
int main(int argc, char **argv) {
	cont_cond_t cond;
	uint8	c;
	GLboolean yp = GL_FALSE;

	/* Initialize KOS */
        pvr_init(&params);

	printf("nehe09 beginning\n");

	/* Get basic stuff initialized */
	glKosInit();

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f,640.0f/480.0f,0.1f,100.0f);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glEnable(GL_TEXTURE_2D);
	glShadeModel(GL_SMOOTH);
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
	glClearDepth(1.0f);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE);
	//glEnable(GL_BLEND);

	for (loop=0; loop<NUM_STARS; loop++)
	{
		star[loop].angle=0.0f;
		star[loop].dist=((float)(loop)/NUM_STARS)*5.0f;
		star[loop].r=rand()%256;
		star[loop].g=rand()%256;
		star[loop].b=rand()%256;
	}

	/* Set up the texture */
	loadtxr("/rd/Star.pcx", &texture[0]);

	c = maple_first_controller();
	while(1) {
		/* Check key status */
		if (cont_get_cond(c, &cond) < 0) {
			printf("Error reading controller\n");
			break;
		}
		if (!(cond.buttons & CONT_START))
			break;
		if (!(cond.buttons & CONT_DPAD_UP))
			tilt -= 0.5f;
		if (!(cond.buttons & CONT_DPAD_DOWN))
			tilt += 0.5f;
		if (!(cond.buttons & CONT_A))
			zoom -= 0.2f;
		if (!(cond.buttons & CONT_B))
			zoom += 0.2f;
		if (!(cond.buttons & CONT_Y) && !yp) {
			yp = GL_TRUE;
			twinkle = !twinkle;
		}
		if (cond.buttons & CONT_Y)
			yp = GL_FALSE;

		/* Begin frame */
		glKosBeginFrame();

		/* Switch to blended polygon list */
		glKosFinishList();

		/* Draw the GL "scene" */
		draw_gl();

		/* Finish the frame */
		glKosFinishFrame();
	}

	return 0;
}
Пример #3
0
int main(int argc, char **argv) {
	cont_cond_t cond;
	uint8	c;
	int     trans = 0;
	GLuint	texture1, texture2, texture3;

	/* Initialize KOS */
        pvr_init(&params);

	printf("texenv beginning\n");

	/* Get basic stuff initialized */
	glKosInit();
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glOrtho(0,640,0,480,0,-1);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	glEnable(GL_TEXTURE_2D);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glDepthMask(GL_FALSE);

	/* Set up the textures */
	loadtxr("/rd/checker.pcx", &texture1);
	loadtxr("/rd/crate.pcx", &texture2);
	loadtxr_tga("/rd/kgl.tga", &texture3);

	c = maple_first_controller();
	while(1) {
		/* Check key status */
		if (cont_get_cond(c, &cond) < 0) {
			printf("Error reading controller\n");
			break;
		}
		if (!(cond.buttons & CONT_START))
			break;
		if (!(cond.buttons & CONT_A)) {
			/* This weird logic is to avoid bouncing back
			   and forth before the user lets go of the
			   button. */
			if (!(trans & 0x1000)) {
				if (trans == 0)
					trans = 0x1001;
				else
					trans = 0x1000;
			}
		} else {
			trans &= ~0x1000;
		}

		/* Begin frame */
		glKosBeginFrame();

		glDisable(GL_KOS_AUTO_UV);
		glBindTexture(GL_TEXTURE_2D, texture1);
		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
		glColor4f(0,0,0,0);
		glBegin(GL_QUADS);
		glTexCoord2f(0,0);
		glVertex3f(0,0,0);
		glTexCoord2f(20,0);
		glVertex3f(640,0,0);
		glTexCoord2f(20,15);
		glVertex3f(640,480,0);
		glTexCoord2f(0,15);
		glVertex3f(0,480,0);
		glEnd();

		if (trans & 1) {
			glKosFinishList();
		}

		/* top row, non-alpha texture */
		glEnable(GL_KOS_AUTO_UV);
		glBindTexture(GL_TEXTURE_2D, texture2);
		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
		quad(5,250);

		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
		quad(165,250);

		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_DECAL);
		quad(325,250);

		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATEALPHA);
		quad(485,250);

		/* bottom row, alpha texture */
		glBindTexture(GL_TEXTURE_2D, texture3);
		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
		quad(5,50);

		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
		quad(165,50);

		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_DECAL);
		quad(325,50);

		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATEALPHA);
		quad(485,50);

		/* Finish the frame */
		glKosFinishFrame();
	}

	return 0;
}
Пример #4
0
int main(int argc, char **argv) {
	cont_cond_t cond;
	uint8	c;
	float	r = 0.0f;
	float	dr = 2;
	float	z = -14.0f;
	GLuint	texture;
	GLuint  dummy;
	int	trans = 0;
	pvr_stats_t	stats;

	/* Initialize KOS */

	/* Use this to test other video modes */
	/* vid_init(DM_320x240, PM_RGB565); */

	/* Normal init */
	pvr_init(&params);

	printf("gltest beginning\n");

	/* Get basic stuff initialized */
	glKosInit();
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f, 640.0f / 480.0f, 0.1f, 100.0f);
	glMatrixMode(GL_MODELVIEW);
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_KOS_AUTO_UV);

	/* Expect CW verts */
	glFrontFace(GL_CW);

        /* Enable Transparancy */
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	/* Load a texture and make to look nice */
	loadtxr("/rd/crate.pcx", &texture);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_FILTER, GL_FILTER_BILINEAR);
        glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATEALPHA);

	glClearColor(0.3f, 0.4f, 0.5f, 1.0f);

	while(1) {
		/* Check key status */
		c = maple_first_controller();
		if (c) {
			if (cont_get_cond(c, &cond) < 0) {
				printf("Error reading controller\n");
			}
			if (!(cond.buttons & CONT_START))
				break;
			if (!(cond.buttons & CONT_DPAD_UP))
				z -= 0.1f;
			if (!(cond.buttons & CONT_DPAD_DOWN))
				z += 0.1f;
			if (!(cond.buttons & CONT_DPAD_LEFT)) {
				/* If manual rotation is requested, then stop
				   the automated rotation */
				dr = 0.0f;
				r -= 2.0f;
			}
			if (!(cond.buttons & CONT_DPAD_RIGHT)) {
				dr = 0.0f;
				r += 2.0f;
			}
			if (!(cond.buttons & CONT_A)) {
				/* This weird logic is to avoid bouncing back
				   and forth before the user lets go of the
				   button. */
				if (!(trans & 0x1000)) {
					if (trans == 0)
						trans = 0x1001;
					else
						trans = 0x1000;
				}
			} else {
				trans &= ~0x1000;
			}
		}

		r += dr;

		/* Begin frame */
		glKosBeginFrame();

		/* Draw four cubes */
		glLoadIdentity();
		glTranslatef(0.0f, 0.0f, z);
		glRotatef(r, 0.0f, 1.0f, 0.5f);
		glPushMatrix();
		
		glTranslatef(-5.0f, 0.0f, 0.0f);
		cube(r);

		glPopMatrix();
		glPushMatrix();
		glTranslatef(5.0f, 0.0f, 0.0f);
		cube(r);

		/* Potentially do two as translucent */
		if (trans & 1) {
			glKosFinishList();
			glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
			glDisable(GL_CULL_FACE);
		}

		glPopMatrix();
		glPushMatrix();
		glTranslatef(0.0f, 5.0f, 0.0f);
		cube(r);

		glPopMatrix();
		glTranslatef(0.0f, -5.0f, 0.0f);
		cube(r);

		if (trans & 1) {
		        glEnable(GL_CULL_FACE);
		}

		/* Finish the frame */
		glKosFinishFrame();
	}

	pvr_get_stats(&stats);
	printf("VBL Count: %d, last_time: %f, frame rate: %f fps\n",
		stats.vbl_count, stats.frame_last_time, stats.frame_rate);

	return 0;
}
Пример #5
0
int
main (int argc, char *argv[])
{
  int cable_type;
  int quit = 0;
  float rot1 = 0.0, rot2 = 0.0, rot3 = 0.0;
  kos_img_t cubetxr;
  GLuint texture[2];
  pvr_ptr_t texaddr;
  pvr_ptr_t bumpmap;
  /* Consider this as the vector from the object to the light, for now.  */
  GLfloat light_position[3] = { 0.7, 0.7, 2.0 };
  
  vec_normalize (&light_position[0], &light_position[0]);
  
  cable_type = vid_check_cable ();
  
  printf ("KOS says M_PI is: %f\n", M_PI);
  
  if (cable_type == CT_VGA)
    vid_init (DM_640x480_VGA, PM_RGB565);
  else
    vid_init (DM_640x480_PAL_IL, PM_RGB565);
  
  init_pvr ();
  
  auto_orient ();
  
  png_to_img ("/rd/cube.png", PNG_NO_ALPHA, &cubetxr);
  
  texaddr = pvr_mem_malloc (cubetxr.w * cubetxr.h * 2);
  pvr_txr_load_kimg (&cubetxr, texaddr, PVR_TXRLOAD_INVERT_Y);
  kos_img_free (&cubetxr, 0);
  
  bumpmap = load_bumpmap ("/rd/bump.raw");
  
  vid_border_color (0, 0, 0);
  pvr_set_bg_color (0.0, 0.0, 0.0);
    
  glKosInit ();
  
  glEnable (GL_DEPTH_TEST);
  glEnable (GL_CULL_FACE);
  glEnable (GL_TEXTURE_2D);
  glShadeModel (GL_SMOOTH);
  glClearDepth (1.0f);
  glDepthFunc (GL_LEQUAL);

  glMatrixMode (GL_PROJECTION);
  glLoadIdentity ();
  gluPerspective (45.0,			/* Field of view in degrees.  */
		  640.0 / 480.0,	/* Aspect ratio.  */
		  1.0,			/* Z near.  */
		  50.0);		/* Z far.  */

  glMatrixMode (GL_MODELVIEW);
  glLoadIdentity ();
  gluLookAt (0.0,   0.0,  -4.5,		/* Eye position.  */
	     0.0,   0.0,   0.0,		/* Centre.  */
	     0.0,   1.0,   0.0);	/* Up.  */

  glGenTextures (2, &texture[0]);

  /* Ordinary texture.  */
  glBindTexture (GL_TEXTURE_2D, texture[0]);
  glKosTex2D (GL_RGB565_TWID, cubetxr.w, cubetxr.h, texaddr);

  /* Bump texture.  */
  glBindTexture (GL_TEXTURE_2D, texture[1]);

  /*pvr_poly_cxt_txr (cxt, PVR_LIST_OP_POLY,
                    PVR_TXRFMT_BUMP | PVR_TXRFMT_TWIDDLED,
                    128, 128, bumpmap, PVR_FILTER_BILINEAR);*/
  glKosTex2D (GL_BUMP_TWID, 128, 128, bumpmap);

  glTexEnvi (GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);

  /* Break the nice abstraction.  Tweak for bump mapping.  */
  /*cxt = (pvr_poly_cxt_t *) texture[1];
  cxt->gen.specular = PVR_SPECULAR_ENABLE;*/
  /*pvr_poly_compile (&bumphdr, cxt);*/
  
  printf ("objmatrix at %p\n", objmatrix);
  
  while (!quit)
    {
      int faces;
      GLfloat transformed_normals
        [sizeof (face_normals) / (3 * sizeof (GLfloat))][3];
      GLfloat transformed_orient
        [sizeof (face_orient) / (3 * sizeof (GLfloat))][3];
      
      MAPLE_FOREACH_BEGIN (MAPLE_FUNC_CONTROLLER, cont_state_t, st)
        if (st->buttons & CONT_START)
	  quit = 1;
      MAPLE_FOREACH_END ()
      
      glKosBeginFrame ();
      
      glPushMatrix ();
      
      glRotatef (rot1, 1.0, 0.0, 0.0);
      glRotatef (rot2, 0.0, 1.0, 0.0);
      glRotatef (rot3, 0.0, 0.0, 1.0);
      
      rot1 += 0.1;
      rot2 += 0.2;
      rot3 += 0.3;

      /* Get the object's transformation matrix.  */
      glGetFloatv (GL_MODELVIEW_MATRIX, &objmatrix[0][0]);
      /* We care only about rotation for now.  */
      objmatrix[0][3] = objmatrix[1][3] = objmatrix[2][3] = 0.0;
      objmatrix[3][0] = objmatrix[3][1] = objmatrix[3][2] = 0.0;
      objmatrix[3][3] = 1.0;

      /*printf ("Got matrix:\n");
      printf ("[ %f %f %f %f ]\n", objmatrix[0][0], objmatrix[0][1],
				   objmatrix[0][2], objmatrix[0][3]);
      printf ("[ %f %f %f %f ]\n", objmatrix[1][0], objmatrix[1][1],
				   objmatrix[1][2], objmatrix[1][3]);
      printf ("[ %f %f %f %f ]\n", objmatrix[2][0], objmatrix[2][1],
				   objmatrix[2][2], objmatrix[2][3]);
      printf ("[ %f %f %f %f ]\n", objmatrix[3][0], objmatrix[3][1],
				   objmatrix[3][2], objmatrix[3][3]);*/

      /* Do these all in one go.  */
      mat_load ((matrix_t *) &objmatrix[0][0]);

      /* Note: mat_transform is only for 3D->2D (perspective)
         transformations!  This won't be quite as quick, most likely.  */
      for (faces = 0; faces < 6; faces++)
        {
	  GLfloat x = face_normals[faces][0];
	  GLfloat y = face_normals[faces][1];
	  GLfloat z = face_normals[faces][2];
	  GLfloat w = 1.0;
	  mat_trans_nodiv (x, y, z, w);
	  transformed_normals[faces][0] = x;
	  transformed_normals[faces][1] = y;
	  transformed_normals[faces][2] = z;

	  x = face_orient[faces][0];
	  y = face_orient[faces][1];
	  z = face_orient[faces][2];
	  w = 1.0;
	  mat_trans_nodiv (x, y, z, w);
	  transformed_orient[faces][0] = x;
	  transformed_orient[faces][1] = y;
	  transformed_orient[faces][2] = z;
	}
      glKosMatrixDirty ();

      glDisable (GL_KOS_OFFSET_COLOR);
      glBindTexture (GL_TEXTURE_2D, texture[0]);
      glDisable (GL_TEXTURE_2D);
      //glBlendFunc (GL_DST_COLOR, GL_ZERO);
      glBlendFunc (GL_ONE, GL_ZERO);

      for (faces = 0; faces < 6; faces++)
        {
	  int strip;
	  	  
	  glBegin (GL_TRIANGLE_STRIP);

	  glColor4ub (colour[faces][0], colour[faces][1], colour[faces][2],
		      colour[faces][3]);

	  for (strip = 0; strip < 4; strip++)
	    {
	      glTexCoord2fv (texcoords[strip]);
	      glVertex3fv (points[tristrips[faces][strip]]);
	    }
	  
	  glEnd ();
	}

      /* Finish opaque list, start transparent list.  */
      glKosFinishList ();

      glBindTexture (GL_TEXTURE_2D, texture[1]);
      glEnable (GL_TEXTURE_2D);
      glEnable (GL_KOS_OFFSET_COLOR);
      glBlendFunc (GL_ZERO, GL_SRC_ALPHA);
      
      for (faces = 0; faces < 6; faces++)
        {
	  int strip, over_pi, over_2pi;
	  GLfloat s_dot_n, f[3], d[3], t, q;
	  GLfloat d_cross_r[3], dxr_len, d_len;

	  s_dot_n = vec_dot (&transformed_normals[faces][0],
			     &light_position[0]);
	  /* Elevation (T) angle:
	     s.n = |s| |n| cos T
	     T = acos (s.n / (|s| * |n|))
	     |s| and |n| are both 1.  */
	  t = M_PI / 2 - acosf (s_dot_n);
	  
	  if (t < 0)
	    t = 0;
	  
	  /* Rotation (Q) angle:
	     d x r = (|d| |r| sin Q) n
	     |d x r| / (|d| |r|) = sin Q.  */
	  vec_scale (&f[0], &transformed_normals[faces][0], s_dot_n);
	  vec_sub (&d[0], &light_position[0], &f[0]);
	  vec_cross (&d_cross_r[0], &d[0], &transformed_orient[faces][0]);
	  dxr_len = vec_length (&d_cross_r[0]);
	  d_len = vec_length (&d[0]);
	  q = asinf (dxr_len / d_len);
	  
	  over_pi = vec_dot (&d[0], &transformed_orient[faces][0]) < 0;
	  if (over_pi)
	    q = M_PI - q;

	  over_2pi
	    = vec_dot (&d_cross_r[0], &transformed_normals[faces][0]) < 0;
	  if (over_2pi)
	    q = 2 * M_PI - q;

	  /*printf ("length of n: %f\n",
		 length (&transformed_normals[faces][0]));
	  printf ("%d: [ %f %f %f ]\n", faces, transformed_normals[faces][0],
	    transformed_normals[faces][1], transformed_normals[faces][2]);

	  printf ("length of r: %f\n", length (&transformed_orient[faces][0]));
	  printf ("%d: [ %f %f %f ]\n", faces, transformed_orient[faces][0],
	    transformed_orient[faces][1], transformed_orient[faces][2]);*/

	  glBegin (GL_TRIANGLE_STRIP);

	  set_bump_direction (t, 2 * M_PI - q, 1.0);
	  glColor4ub (255, 255, 255, 255);

	  for (strip = 0; strip < 4; strip++)
	    {
	      glTexCoord2fv (texcoords[strip]);
	      glVertex3fv (points[tristrips[faces][strip]]);
	    }

	  glEnd ();
	}

      /* Finish opaque polygon list, start translucent polygon list.  */
     /* glKosFinishList ();*/

      glPopMatrix ();
                  
      glKosFinishFrame ();
    }

  glKosShutdown ();
  
  pvr_shutdown ();
  
  vid_shutdown ();
  
  return 0;
}
Пример #6
0
bool myWorld::Init(int perso)
{
	cont_cond_t cond;
  	uint8	c;
  	GLboolean xp = GL_FALSE;
  	GLboolean yp = GL_FALSE;
     Vehicle *vehicle;

	int i;
	int f=NEG;
	float d=0.0;
	int ft=f;
	int throttle=0;
	int brake=0;
	int ang=0;


	 ogg sultan("/rd/sons/ogg/sultanTribes.ogg");
  	 
	 
	 init();
	 
	//speed tabulation
	for(i=-NEG;i<0;i++)
	  aSpeed[i+NEG]=-(0.24*(float)7*i/(PLUS+NEG)+2)* log((float) -10*(float)7*i/(PLUS+NEG)+1)*3.6;
	for(i=NEG;i<PLUS+NEG;i++)
	  aSpeed[i]=(-0.11*(float)(7*(i-NEG))/(PLUS+NEG)+2)*5* log((float) 3*(float)7*(i-NEG)/(PLUS+NEG)+1)*3.6;
	
	/* Declaration des objets */
	
	SkyBox *skyBox = new SkyBox(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
	Landscape *cliff = new Landscape(JPEG, "/rd/terrain.jpg", "/rd/terrain.pcx", 256.0f, 32, 1, 1, 0);
	Landscape *sand = new Landscape(JPEG, "/rd/circuit.jpg", "/rd/circuit.pcx", 450.0f, 30, 4, 1/3.0f, -12.0f);
	PalmTree *palmier = new PalmTree("/rd/palmier.png", 69.0f, (sand->getYFromXZ(69,12)) + 10, 12.0f, 20.0f, 20.0f, 20.0f);
	PalmTree *cactus= new PalmTree("/rd/cactus.png", 10.0f, sand->getYFromXZ(10, 30) + 10, 30.0f, 40.0f, 40.0f, 40.0f);
	Landscape *sea = new Landscape(NJPEG, NULL, "/rd/eau.pcx", 700.0f, 7, 4, 0.0f, 3.0f, 0.5f, 0.6f, 0.8f);
	TheLittleHouseOnThePrairie *house = new TheLittleHouseOnThePrairie(-170.0f, 4.5f, -140.0f, 4.0f, 4.0f, 4.0f);
	StartPane *startPane = new StartPane(-155.0f,sand->getYFromXZ(69,12) , 35.0f, 25.0f, 50.0f, 50.0f);
	Caisse *caisse1 = new Caisse("/rd/decor/caisses/caisseGrande.png", -320.0f,  -5.0f, -280.0f, 15.0f, 15.0f, 15.0f);
	Caisse *caisse2 = new Caisse("/rd/decor/caisses/caisseCroix.png", 80.0f,  2.0f, -280.0f, 15.0f, 15.0f, 15.0f);
	/*Caisse *caisse3 = new Caisse("/cd/decor/caisses/explosif.png", 280.0f,  2.0f, -220.0f, 15.0f, 15.0f, 15.0f);*/
	
	/* Character creation */
	switch(perso + 2)
	{
	   case 2:
	   				vehicle = new OisisVehicle(-155.0f,    (sand->getYFromXZ (-155, 35)) + 1.25,       35.0f,
	        	                                           	                         -155.0f,     (sand->getYFromXZ (-155, 34.9)) + 1.25,       34.9f,
	            	                                        	                         6.25f,      	                                                        2.5f,         2.5f,
	            	                                        	                         1.5);  	            	 
	            	 break;
	    
	    case 3:
	    		vehicle  = new MomoVehicle(-155.0f,    sand->getYFromXZ (-155, 35) + 1.25,       35.0f,
	            	                                              -155.0f,     sand->getYFromXZ (-155, 34.9) + 1.25 - 0.5,       34.9f,
	                	                                             2.5f ,                                                              5.0f,          2.5f,
	                	                                             0.5);
	                break;
	    			
	    
	    case 4:   
	    			vehicle =  new NoelVehicle(-155.0f,    sand->getYFromXZ (-155, 35) + 7.5,       35.0f,
	            	                                              -155.0f,     sand->getYFromXZ (-155, 34.9) + 7.5 - 10,       34.9f,
	                	                                             3.25f ,                                                              15.0f,          13.0f,
	                	                                             10);
	                break;          	                                                	                                     
	         
	     default:
	     	        vehicle =  new NoelVehicle(-155.0f,    sand->getYFromXZ (-155, 35) + 7.5,       35.0f,
	            	                                              -155.0f,     sand->getYFromXZ (-155, 34.9) + 7.5,       34.9f,
	                	                                             3.25f ,                                                              15.0f,          13.0f,
	                	                                             10);
	                break;          	                                    	           	                                    	        
	}
	                                                    	        
	 
	sultan.play(1); 
	//vehicle->updateSlope(sand);
	//Vector3D tmp1= (vehicle->getPosition()) + (Vector3D (0, 10,17.5));
	/*Vector3D tmp1= (vehicle->getPosition()) + (Vector3D (0,  10 - vehicle->getOffset(), 17.5));
	Vector3D tmp2= Vector3D (0,1,0);
	Camera cam(tmp1, vehicle->getPosition(), tmp2);*/
	
	Vector3D tmp1= (vehicle->getPosition()) + (Vector3D (0, 10 - vehicle->getOffset(), 17.5));
	Vector3D tmp3= Vector3D (0,1,0);
	Vector3D tmp2 = vehicle->getPosition();
	tmp2.y -= vehicle->getOffset();
	Camera cam(tmp1, tmp2, tmp3);
	
	
	palmier->shape();
	cactus->setColor(0.0f, 0.6f, 0.2f);
	cactus->shape();
	cliff->shape();
	sand->shape();
	sea->shape();
	startPane->shape();
	house->shape();
	vehicle->shape();
	caisse1->shape();
	caisse2->shape();
	/*caisse3->shape();*/

	c = maple_first_controller();
	bool noRotatingThisFrame = false;
        		
	while(1)
  	{
  		noRotatingThisFrame = false;
  		
    	c = maple_first_controller();
    	ft=f;
    	if (c == 0)
      		continue;
    	if (cont_get_cond(c, &cond) < 0)
      		continue;
    
    	if (!(cond.buttons & CONT_START)) {
    		sultan.stop();
    		return false;
    	}
    	   
    	if (!(cond.buttons & CONT_DPAD_LEFT)){
	  		if(f!=NEG){
	    		vehicle->rotate(ROT_ANGLE, sand);
	    		cam.move(vehicle->getPosition(), vehicle->getDirection());
	  		}
    	}
    	if (!(cond.buttons & CONT_DPAD_RIGHT)) {
	  		if(f!=NEG){
	    		vehicle->rotate(-ROT_ANGLE, sand);
	    		cam.move(vehicle->getPosition(), vehicle->getDirection());
	  		}
    	}
    	
	brake=0;
    if (!(cond.buttons & CONT_B))
	  	brake=1;
	throttle=0;
    if (!(cond.buttons & CONT_A))
		throttle=1;
    if (!(cond.buttons & CONT_B )&&!(cond.buttons & CONT_X ))
    	screenShot();
    if (!(cond.buttons & CONT_Y)) {
    	wav klaxon ("/rd/Klaxon.wav");
    	klaxon.play();
	}
    if (cond.ltrig) {
    	noRotatingThisFrame = true;
 		cam.rotateAroundView(2);
	}
    if (cond.rtrig) {
    	noRotatingThisFrame = true;
		cam.rotateAroundView(-2);
	}
     
     if (!(cond.buttons & CONT_B)&&!(cond.buttons & CONT_X)&&!(cond.buttons & CONT_A)&&!(cond.buttons & CONT_Y)) {
    		return false;
    }
        
    	/* Begin frame */
    	
    	/* Draw the GL "scene" */

		Vector3D dir = vehicle->getDirection();
		Vector3D dirNoY (dir.x, 0, dir.z);
	if (!noRotatingThisFrame)
   		cam.updateRotation(vehicle->getPosition(), dirNoY);

    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	
    	glKosBeginFrame();
	
    	
    	/* Switch to the blended polygon list if needed */
		glKosFinishList();
      	glDepthMask(0);
    	/*******************************************/
    	
   
    	glLoadIdentity();
    	glPushMatrix();
    		cam.affiche(); 
 			glEnable(GL_KOS_NEARZ_CLIPPING);
			        glPushMatrix();
 				  glScalef(350.0f, 200.0f, 350.0f);
 					/* Paint the Sky Box */
 				  skyBox->shape();
 				glPopMatrix();
 				cliff->displayElement();
 				sea->displayElement();
 				glPushMatrix();
 					glScalef(2.0f, 2.0f, 2.0f);
 					house->displayElement();
 				glPopMatrix();
 				palmier->displayElement();
 				cactus->displayElement();
 				
 				/* Draw the second house on the Prairie */
 				glPushMatrix();
 				  glTranslatef(200.0f, 60.0f, 200.0f);
 				  house->displayElement();
 				glPopMatrix();
 				
 				/* Draw a second cactus */
 				glPushMatrix();
 				  glTranslatef(-320.0f, sand->getYFromXZ (120, 250), -120.0f);
 				  cactus->displayElement();
 				glPopMatrix();
 				
 				/* Draw a second palmtree */
 				glPushMatrix();
 				  glTranslatef(-125.0f, sand->getYFromXZ (-125, 10), 10.0f);
 				  cactus->displayElement();
 				glPopMatrix();
 				
 				
 				sand->displayElement();
			    startPane->displayElement();
			    caisse1->displayElement();
			    caisse2->displayElement();
			    /*caisse3->displayElement();*/

				/* Draw the vehicle */
				glPushMatrix();

				/* METTRE LA PENTE A LA PLACE DU PREMIER 0 */
				f=PhysicalEngine::speed(f,throttle,brake,0,0);
				float d=PhysicalEngine::distance(ft,f)*SCALE;

			 
				vehicle->moveRelatif(d,sand);
				cam.move(vehicle->getPosition(),vehicle->getDirection());

					glTranslatef(vehicle->getPosition().x, vehicle->getPosition().y, vehicle->getPosition().z);

					//1st rotation, in x and z
					float rotatefAngle = angleBetweenVectorsWithReference (Vector3D(0,0,1), Vector3D(1,0,0), dirNoY);
					//convert to degrees :
					rotatefAngle = radToDeg (rotatefAngle);
					Vector3D rotateUp = cam.getUpVector();
					glRotatef(rotatefAngle, rotateUp.x, rotateUp.y, rotateUp.z);

					//2nd rotation, in z and y
					Vector3D tF = vehicle->getFront();
					Vector3D tPos = vehicle->getPosition();
					Vector3D dir2 =  tF - tPos;
					rotatefAngle = asin (dir2.y / dir2.Magnitude());
					//convert to degrees :
					rotatefAngle = radToDeg (rotatefAngle);
					Vector3D rotateX (1,0,0);
					glRotatef(-rotatefAngle, rotateX.x, rotateX.y, rotateX.z);
					
					vehicle->displayElement();
				glPopMatrix();
 			glDisable(GL_KOS_NEARZ_CLIPPING);
 		glPopMatrix();
 
    	/* Finish the frame */
   	glKosFinishFrame();
	}
    
}