示例#1
0
文件: fire.c 项目: crtc-demos/wobble
static void
init_effect (void *params)
{
  pvr_mem_print_list ();
  // pvr_mem_reset ();

  warp_texture[0] = pvr_mem_malloc (1024 * 512 * 2);
  warp_texture[1] = pvr_mem_malloc (1024 * 512 * 2);
  memset (warp_texture[0], 0, 1024 * 512 * 2);
  memset (warp_texture[1], 0, 1024 * 512 * 2);

  if (cooltmp)
    {
      cooling_texture = pvr_mem_malloc (COOL_X * COOL_Y * 2);
      pvr_txr_load_ex (cooltmp, cooling_texture, COOL_X, COOL_Y,
		       PVR_TXRLOAD_16BPP);
      free (cooltmp);
      cooltmp = 0;
    }

  flame_texture = pvr_mem_malloc (256 * 256 * 2);
  png_to_texture ("/rd/flametex.png", flame_texture, PNG_NO_ALPHA);
  
  backdrop_texture = pvr_mem_malloc (512 * 256 * 2);
  png_to_texture ("/rd/backdrop.png", backdrop_texture, PNG_NO_ALPHA);
  //printf ("memory free: %d bytes\n", pvr_mem_available ());
}
示例#2
0
文件: foe.c 项目: mpersano/protozoa
void
initialize_foes(void)
{
	int i;

	for (i = 0; i < NUM_FOE_TYPES; i++) {
		struct mesh *p;
		const struct mesh_settings *q = foe_mesh_settings[i];

#if 0
		struct matrix s;

		mat_make_scale(&s, foe_models[i].scale);
		p = mesh_load_obj(foe_models[i].name);
		mesh_transform(p, &s);
#else
		if (q == NULL)
			panic("foe %d not properly initialized!", i);

		p = mesh_load_obj(q->source);
		mesh_transform(p, q->transform);
#endif
		mesh_setup(p);

		foe_meshes[i] = p;
	}

	duck_trail = png_to_texture("duck-trail.png");
	ninja_trail = png_to_texture("ninja-trail.png");
	bomb_flash = png_to_texture("bomb-flash.png");
}
示例#3
0
void
initialize_explosions(void)
{
	int i;

	for (i = 0; i < NUM_EXPLOSION_TYPES; i++) {
		explosion_data[i].texture_id =
		  png_to_texture(explosion_data[i].texture_file_name);
	}
}
示例#4
0
void
initialize_main_menu(void)
{
	main_menu = menu_make("main", font_medium, 1.05, MA_LEFT, 20, 160);

	menu_add_action_item(main_menu, "Play", menu_play, NULL);
	menu_add_action_item(main_menu, "Credits", menu_credits, NULL);
	add_settings_menu(main_menu);
	menu_add_space_item(main_menu);
	menu_add_action_item(main_menu, "Quit", menu_quit, NULL);

	logo_texture_id = png_to_texture("intro-logo.png");
}
示例#5
0
void
initialize_in_game_state(void)
{
	int i;

	for (i = 0; i < 10; i++) {
		char s[2] = { i + '0', '\0' };
		digit_width[i] = string_width_in_pixels(font_medium, s);
	}

	crosshair_arrow_texture_id =
	  png_to_texture("crosshair-arrow.png");
}
示例#6
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;
}
示例#7
0
文件: water.c 项目: mpersano/protozoa
static void
initialize_env_texture(void)
{
	if (!env_texture_id)
		env_texture_id = png_to_texture("envmap.png");
}
示例#8
0
static void
preinit_skybox (void)
{
  static int initialised = 0;
  kos_img_t txr;
  
  if (initialised)
    return;

  printf ("Loading sky box texture");
  fflush (stdout);
#if 0
  skytex[0] = pvr_mem_malloc (512 * 512 * 2);
  png_to_texture ("/rd/sky23.png", skytex[0], PNG_NO_ALPHA);
  putchar ('.');
  fflush (stdout);
  skytex[1] = pvr_mem_malloc (512 * 512 * 2);
  png_to_texture ("/rd/sky24.png", skytex[1], PNG_NO_ALPHA);
  putchar ('.');
  fflush (stdout);
  skytex[2] = pvr_mem_malloc (512 * 512 * 2);
  png_to_texture ("/rd/sky27.png", skytex[2], PNG_NO_ALPHA);
  putchar ('.');
  fflush (stdout);
  skytex[3] = pvr_mem_malloc (512 * 512 * 2);
  png_to_texture ("/rd/sky28.png", skytex[3], PNG_NO_ALPHA);
  putchar ('.');
  fflush (stdout);
  skytex[4] = pvr_mem_malloc (512 * 512 * 2);
  png_to_texture ("/rd/sky25.png", skytex[4], PNG_NO_ALPHA);
  putchar ('.');
  fflush (stdout);
  skytex[5] = pvr_mem_malloc (512 * 512 * 2);
  png_to_texture ("/rd/sky26.png", skytex[5], PNG_NO_ALPHA);
  putchar ('.');
#elif 0
  skytex[0] = pvr_mem_malloc (512 * 512 * 2);
  jpeg_to_texture ("/rd/sky23.jpg", skytex[0], 512, 1);
  putchar ('.');
  fflush (stdout);
  skytex[1] = pvr_mem_malloc (512 * 512 * 2);
  jpeg_to_texture ("/rd/sky24.jpg", skytex[1], 512, 1);
  putchar ('.');
  fflush (stdout);
  skytex[2] = pvr_mem_malloc (512 * 512 * 2);
  jpeg_to_texture ("/rd/sky27.jpg", skytex[2], 512, 1);
  putchar ('.');
  fflush (stdout);
  skytex[3] = pvr_mem_malloc (512 * 512 * 2);
  jpeg_to_texture ("/rd/sky28.jpg", skytex[3], 512, 1);
  putchar ('.');
  fflush (stdout);
  skytex[4] = pvr_mem_malloc (512 * 512 * 2);
  jpeg_to_texture ("/rd/sky25.jpg", skytex[4], 512, 1);
  putchar ('.');
  fflush (stdout);
  skytex[5] = pvr_mem_malloc (512 * 512 * 2);
  jpeg_to_texture ("/rd/sky26.jpg", skytex[5], 512, 1);
  putchar ('.');
#else
  kmg_to_img ("/rd/sky23.kmg", &txr);
  skytex[0] = pvr_mem_malloc (txr.byte_count);
  pvr_txr_load_kimg (&txr, skytex[0], PVR_TXRLOAD_SQ);
  kos_img_free (&txr, 0);
  
  kmg_to_img ("/rd/sky24.kmg", &txr);
  skytex[1] = pvr_mem_malloc (txr.byte_count);
  pvr_txr_load_kimg (&txr, skytex[1], PVR_TXRLOAD_SQ);
  kos_img_free (&txr, 0);
  
  kmg_to_img ("/rd/sky27.kmg", &txr);
  skytex[2] = pvr_mem_malloc (txr.byte_count);
  pvr_txr_load_kimg (&txr, skytex[2], PVR_TXRLOAD_SQ);
  kos_img_free (&txr, 0);
  
  kmg_to_img ("/rd/sky28.kmg", &txr);
  skytex[3] = pvr_mem_malloc (txr.byte_count);
  pvr_txr_load_kimg (&txr, skytex[3], PVR_TXRLOAD_SQ);
  kos_img_free (&txr, 0);
  
  kmg_to_img ("/rd/sky25.kmg", &txr);
  skytex[4] = pvr_mem_malloc (txr.byte_count);
  pvr_txr_load_kimg (&txr, skytex[4], PVR_TXRLOAD_SQ);
  kos_img_free (&txr, 0);
  
  kmg_to_img ("/rd/sky26.kmg", &txr);
  skytex[5] = pvr_mem_malloc (txr.byte_count);
  pvr_txr_load_kimg (&txr, skytex[5], PVR_TXRLOAD_SQ);
  kos_img_free (&txr, 0);
#endif
  putchar ('\n');

  skybox = create_skybox (200, skytex, 512, 512, PVR_TXRFMT_RGB565
			  | PVR_TXRFMT_TWIDDLED | PVR_TXRFMT_VQ_ENABLE);

  initialised = 1;
}