コード例 #1
0
ファイル: dialog.c プロジェクト: AntonLanghoff/whitecatlib
static void run_demo (void)
{
	set_color_depth (16);
	if (set_gfx_mode(GFX_OPENGL, width, height, 0, 0) < 0) {
		allegro_message ("Error setting OpenGL graphics mode:\n%s\nAllegro GL error : %s\n", allegro_error, allegro_gl_error);
		return;
	}

	install_keyboard();

	LOCK_FUNCTION(secs_timer);
	LOCK_VARIABLE(secs);

	glClearColor (0, 0, 0, 0);
	glShadeModel (GL_FLAT);
	glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
	glPolygonMode (GL_BACK, GL_POINTS);
	glEnable (GL_DEPTH_TEST);
	glCullFace (GL_BACK);
	glEnable (GL_CULL_FACE);

	install_int (secs_timer, 1000);

	do {
		keyboard();
		rest(2);
	} while (!key[KEY_ESC]);

	remove_int (secs_timer);

	remove_keyboard();
}
コード例 #2
0
ファイル: wgdi.c プロジェクト: dodamn/pkg-allegro4.2
/* gfx_gdi_lock:
 */
static void gfx_gdi_lock(struct BITMAP *bmp)
{
   /* to prevent the drawing threads and the rendering proc
    * from concurrently accessing the dirty lines array
    */
   _enter_gfx_critical();

   /* arrange for drawing requests to pause when we are in the background */
   if (!_win_app_foreground) {
      /* stop timer */
      remove_int(render_proc);

      _exit_gfx_critical();

      if (GFX_CRITICAL_RELEASED)
         _win_thread_switch_out();

      _enter_gfx_critical();

      /* restart timer */
      install_int(render_proc, RENDER_DELAY);
   }

   lock_nesting++;
   bmp->id |= BMP_ID_LOCKED;
}
コード例 #3
0
ファイル: fig15_21.c プロジェクト: AlterTiton/bcit-courses
int main( void )
{
   /* first, set up Allegro and the graphics mode */
   allegro_init(); /* initialize Allegro */
   install_keyboard(); /* install the keyboard for Allegro to use */
   install_sound( DIGI_AUTODETECT, MIDI_AUTODETECT, NULL );
   install_timer(); /* install the timer handler */
   set_color_depth( 16 ); /* set the color depth to 16-bit */
   set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0 ); /* set graphics mode */
   buffer = create_bitmap(SCREEN_W, SCREEN_H);/* create buffer */
   pongData = load_datafile( "pongdatafile.dat" ); /* load the datafile */
   ball_x = SCREEN_W / 2; /* give ball its initial x-coordinate */
   ball_y = SCREEN_H / 2; /* give ball its initial y-coordinate */
   barL_y = SCREEN_H / 2; /* give left paddle its initial y-coordinate */
   barR_y = SCREEN_H / 2; /* give right paddle its initial y-coordinate */
   scoreL = 0; /* set left player’s score to 0 */
   scoreR = 0; /* set right player’s score to 0 */
   srand( time( NULL ) ); /* seed the random function ... */
   direction = rand() % 4; /* and then make a random initial direction */
   /* add timer that calls moveBall every 5 milliseconds */
   install_int( moveBall, 5 );
   /* add timer that calls respondToKeyboard every 10 milliseconds */
   install_int( respondToKeyboard, 10 );
   
   while ( !key[KEY_ESC] ) /* until the escape key is pressed ... */
   {
      /* now, perform double buffering */
      clear_to_color( buffer, makecol( 255, 255, 255 ) );
      blit( pongData[BALL].dat, buffer, 0, 0, ball_x, ball_y, 40, 40 );
      blit( pongData[BAR].dat, buffer, 0, 0, 0, barL_y, 20, 100 );  
      blit( pongData[BAR].dat, buffer, 0, 0, 620, barR_y, 20, 100 );
      line( buffer, 0, 30, 640, 30, makecol( 0, 0, 0 ) );
      /* draw text onto the buffer */
      textprintf_ex( buffer, pongData[PONGFONT].dat, 75, 0, makecol( 0, 0, 0 ),
                     -1, "Left Player Score: %d", scoreL );             
      textprintf_ex( buffer, pongData[PONGFONT].dat, 400, 0, makecol( 0, 0, 0 ),
                     -1, "Right Player Score: %d", scoreR );            
      blit( buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h );    
      clear_bitmap( buffer );                                      
   } /* end while */
 
   remove_int( moveBall ); /* remove moveBall timer */
   remove_int( respondToKeyboard ); /* remove respondToKeyboard timer */
   destroy_bitmap( buffer ); /* destroy the buffer bitmap */
   unload_datafile( pongData ); /* unload the datafile */
   return 0;
} /* end function main */
コード例 #4
0
//---------------------------------------------------
void initAllegroTimer()
{
	if(isInit)
		return;
	LOCK_VARIABLE(speed_counter);
	LOCK_VARIABLE(milliSec);  
	LOCK_VARIABLE(fps);
	LOCK_VARIABLE(frame_counter);

	LOCK_FUNCTION(inc_milliSec);
	LOCK_FUNCTION(increment_speed_counter); 
	LOCK_FUNCTION(fps_proc);
	
	install_int(inc_milliSec, 10);// every second    //ever 10 of a sec 
	install_int_ex(increment_speed_counter, BPS_TO_TIMER(60));
	install_int(fps_proc, 1000); 

	isInit = true;
}
コード例 #5
0
ファイル: wgdi.c プロジェクト: dodamn/pkg-allegro4.2
/* gfx_gdi_init:
 */
static struct BITMAP *gfx_gdi_init(int w, int h, int v_w, int v_h, int color_depth)
{
   /* virtual screen are not supported */
   if ((v_w!=0 && v_w!=w) || (v_h!=0 && v_h!=h))
      return NULL;
   
   _enter_critical();

   gfx_gdi.w = w;
   gfx_gdi.h = h;

   if (adjust_window(w, h) != 0) {
      _TRACE(PREFIX_E "window size not supported.\n");
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Resolution not supported"));
      goto Error;
   }

   /* the last flag serves as an end of loop delimiter */
   gdi_dirty_lines = _AL_MALLOC_ATOMIC((h+1) * sizeof(char));
   ASSERT(gdi_dirty_lines);
   memset(gdi_dirty_lines, 0, (h+1) * sizeof(char));
   gdi_dirty_lines[h] = 1;

   /* create the screen surface */
   screen_surf = _AL_MALLOC_ATOMIC(w * h * BYTES_PER_PIXEL(color_depth));
   gdi_screen = _make_bitmap(w, h, (unsigned long)screen_surf, &gfx_gdi, color_depth, w * BYTES_PER_PIXEL(color_depth));
   gdi_screen->write_bank = gfx_gdi_write_bank; 
   _screen_vtable.acquire = gfx_gdi_lock;
   _screen_vtable.release = gfx_gdi_unlock;
   _screen_vtable.unwrite_bank = gfx_gdi_unwrite_bank; 

   /* create render timer */
   vsync_event = CreateEvent(NULL, FALSE, FALSE, NULL);
   install_int(render_proc, RENDER_DELAY);

   /* connect to the system driver */
   win_gfx_driver = &win_gfx_driver_gdi;

   /* set the default switching policy */
   set_display_switch_mode(SWITCH_PAUSE);

   /* grab input devices */
   win_grab_input();

   _exit_critical();

   return gdi_screen;

 Error:
   _exit_critical();

   gfx_gdi_exit(NULL);

   return NULL;
}
コード例 #6
0
ファイル: mouse.c プロジェクト: AntonLanghoff/whitecatlib
/* show_os_cursor:
 *  Tries to display the OS cursor. Returns 0 if a cursor is displayed after the
 *  function returns, else -1. This is similar to calling show_mouse(screen)
 *  after calling enable_hardware_cursor and checking gfx_capabilities for
 *  GFX_HW_CURSOR, but is easier to use in cases where you don't need Allegro's
 *  software cursor even if no os cursor is available.
 */
int show_os_cursor(int cursor)
{
   int r = -1;
   if (!mouse_driver)
      return r;

   remove_int(mouse_move);

   gfx_capabilities &= ~(GFX_HW_CURSOR|GFX_SYSTEM_CURSOR);
   if (cursor != MOUSE_CURSOR_NONE) {

      if (mouse_driver->enable_hardware_cursor) {
         mouse_driver->enable_hardware_cursor(TRUE);
      }

      /* default system cursor? */
      if (cursor != MOUSE_CURSOR_ALLEGRO) {
         if (mouse_driver->select_system_cursor) {
            if (mouse_driver->select_system_cursor(cursor) != 0) {
               gfx_capabilities |= (GFX_HW_CURSOR|GFX_SYSTEM_CURSOR);
               r = 0;
               goto done;
            }
         }
         goto done;
      }
      else {
         /* set custom hardware cursor */
         if (gfx_driver) {
            if (gfx_driver->set_mouse_sprite) {
               if (gfx_driver->set_mouse_sprite(mouse_sprite, mouse_x_focus, mouse_y_focus))
                  goto done;
            }
            if (gfx_driver->show_mouse) {
               if (gfx_driver->show_mouse(screen, mouse_x, mouse_y))
                  goto done;
            }
            gfx_capabilities |= GFX_HW_CURSOR;
            r = 0;
            goto done;
         }
      }
   }
   else {
      if (gfx_driver && gfx_driver->hide_mouse)
         gfx_driver->hide_mouse();
   }

done:
   if (mouse_driver->timer_poll) 
      install_int(mouse_move, 10);
   return r;
}
コード例 #7
0
ファイル: timers.c プロジェクト: Jheengut/gmerlin
/*following functions are architecture dependent */
void
tl_update_time (void)
{
#ifdef __BEOS__
  currenttime = system_time ();
#else
#ifdef _WIN32
  QueryPerformanceCounter (&currenttime);
#else
#ifdef USE_ALLEGRO
  if (allegromode)
    {
      if (counter == -1)
	{
	  LOCK_VARIABLE (counter);
	  LOCK_FUNCTION (timer);
	  install_int (timer, 1000 / TICKSPERSEC);
	  ainstalled = 1;
	  counter = 0;
	}
      currenttime = counter;
      return;
    }
#endif
#ifdef HAVE_UCLOCK
  currenttime = uclock ();
#else
#ifdef USE_CLOCK
  currenttime = clock ();
#else
#ifdef HAVE_GETTIMEOFDAY

  do
    {
      gettimeofday (&currenttime, &tzp);
    }
  while (currenttime.tv_usec > 999999);
#else
#ifdef HAVE_FTIME
  ftime (&currenttime);
#endif
#endif
#endif
#endif
#endif
#endif
#ifdef _plan9_
  currenttime = plan9_msec ();
#endif
}
コード例 #8
0
ファイル: test.c プロジェクト: AntonLanghoff/whitecatlib
int main ()
{
	allegro_init();

	install_allegro_gl();
	
	allegro_gl_clear_settings();
	allegro_gl_set (AGL_COLOR_DEPTH, 32);
	allegro_gl_set (AGL_Z_DEPTH, 24);
	allegro_gl_set (AGL_FULLSCREEN, TRUE);
	allegro_gl_set (AGL_DOUBLEBUFFER, 1);
	allegro_gl_set (AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_Z_DEPTH
	              | AGL_DOUBLEBUFFER | AGL_FULLSCREEN);

	if (set_gfx_mode(GFX_OPENGL, 640, 480, 0, 0) < 0) {
		allegro_message ("Error setting OpenGL graphics mode:\n%s\n"
		                 "Allegro GL error : %s\n",
		                 allegro_error, allegro_gl_error);
		return -1;
	}

	install_keyboard();
	install_timer();

	LOCK_FUNCTION(secs_timer);
	LOCK_VARIABLE(secs);

	glShadeModel (GL_FLAT);
	glEnable (GL_DEPTH_TEST);
	glCullFace (GL_BACK);
	glEnable (GL_CULL_FACE);

	install_int (secs_timer, 1000);

	do {
		keyboard();
	} while (!key[KEY_ESC]);

	set_gfx_mode (GFX_TEXT, 0, 0, 0, 0);

	allegro_message("Frames: %i, Seconds: %i, FPS: %f\n",
	                frames, secs, (float)frames / (float)secs);

	return 0;
}
コード例 #9
0
ファイル: main.c プロジェクト: evktalo/lacewing
void init_at_startup(void)
{

   allegro_init();

   install_keyboard();
   install_timer();

   three_finger_flag = 0;
   key_led_flag = 0;

//   LOCK_FUNCTION (framecount);
   LOCK_FUNCTION (tickover);
   LOCK_VARIABLE (ticked);
//   LOCK_VARIABLE (tick_counter);
//   LOCK_VARIABLE (frames_per_second);
//   LOCK_VARIABLE (framecounter);
   LOCK_VARIABLE (turns_per_second);
   LOCK_VARIABLE (turncounter);
//   LOCK_VARIABLE (inputs_per_second);
//   LOCK_VARIABLE (inputcounter);

//   install_int (framecount, 1000);
   install_int (tickover, 30);

   set_color_depth(8);
   init_config();

   if (set_gfx_mode((options.windowed == 1) ? GFX_AUTODETECT_WINDOWED : GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0) != 0)
   {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Unable to set 640x480 mode\n%s\n", allegro_error);
      exit(1);
   }

   init_palette();

   init_display();
   init_menus_once_only();

   init_sound(); // must come after init_menus_once_only, as that's where
    // options.sound_enabled is set.

}
コード例 #10
0
int initialize(){
    allegro_init();
    install_timer();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode(MODE,WIDTH,HEIGHT,0,0);
    srand(time(NULL));
    buffer=create_bitmap(SCREEN_W,SCREEN_H);
    clear(buffer);
    if(install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,"")!=0){
        allegro_message("Error initializing sound system");
        return 0;
    }
    welcome=load_bitmap("welcome.bmp",NULL);
     instruction1=load_bitmap("instruction1.bmp",NULL);
     instruction2=load_bitmap("instruction2.bmp",NULL);
      instruction3=load_bitmap("instruction3.bmp",NULL);
       gameoverscreen=load_bitmap("gameover.bmp",NULL);
       if(!welcome || !instruction2 || ! instruction3 || !instruction1 || ! gameoverscreen){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("WELCOME BMPS MISSING");
        return 0;
       }
    //level1=load_sample("stage1.wav");
    /*if(!level1){
        allegro_message("No sound file");
        return 0;
    }*/
        if(MapLoad("level1.fmp")){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't find level1.fmp");
        return 0;
    }
    LOCK_FUNCTION(timer1);
    LOCK_VARIABLE(ticks);
    LOCK_VARIABLE(framerate);
    LOCK_VARIABLE(counter);
    install_int(timer1,100);
    return 1;
}
コード例 #11
0
ファイル: bsp_3d_test.c プロジェクト: omer4d/SuperOldCode
int main()
{
 int i, exit_flag = 0;

 int vnum, pnum;
 VEC3F *map_vertex;
 POLY3D *map_poly;
 BSP_NODE *root, *node;

 convert_map_to_3d("map.txt", &map_vertex, &map_poly, &vnum, &pnum);

 add_bsp_root(&root, &map_poly[0]);
 for(i = 1; i < pnum; i++)
  add_bsp_node(root, &map_poly[i], &map_vertex, &vnum);

 init();

 LOCK_VARIABLE(fps);
 LOCK_VARIABLE(frame_count);
 LOCK_FUNCTION(update_fps);
 install_int(update_fps, 1000);

 while(!exit_flag)
  {              
   if(key[KEY_ESC]) { exit_flag = 1; }

   clear_bitmap(buffer);
   blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
   frame_count++;
  }

 free(map_vertex);
 for(i = 0; i < pnum; i++)
  free(map_poly[i].vind);
 free(map_poly);

 destroy_bsp_tree(root);
 destroy_bitmap(buffer);
 return 0;
}
コード例 #12
0
ファイル: EX_bsp2.c プロジェクト: omer4d/SuperOldCode
int main()
{
    int exit_flag = 0, i, j;
    MAT16F tmat;

    int vnum, node_num;
    VERTEX *map_vertex;
    STATIC_BSP_NODE *tree;

    init();

    load_static_bsp("map.bsp", &map_vertex, &vnum, &tree, &node_num);
    printf("Vertex Number: %d.\nNode Number: %d.\n", vnum, node_num);

    LOCK_VARIABLE(fps);
    LOCK_VARIABLE(frame_count);
    LOCK_FUNCTION(update_fps);
    install_int(update_fps, 1000);

    float frame = 0.0;

    VEC3F view_volume[5];
    VEC3F cam_pos = vec3f(0.0, 3.0, 0.0), cam_dir, cam_dir_normal, cam_ang = vec3f(0.0, 0.0, 0.0);

    while(!exit_flag)
    {
        int mx, my;
        get_mouse_mickeys(&mx, &my);
        position_mouse(SCREEN_W / 2, SCREEN_H / 2);

        cam_ang.x += my * 0.001;
        cam_ang.y -= mx * 0.001;
        cam_dir.x = CAM_SPEED * cos(0.5 * M_PI + cam_ang.y);
        cam_dir.y = CAM_SPEED * cos(0.5 * M_PI + cam_ang.x);
        cam_dir.z = CAM_SPEED * sin(0.5 * M_PI + cam_ang.y);
        cam_dir_normal = vec3f(-cam_dir.z, 0.0, cam_dir.x);

        if(key[KEY_ESC]) {
            exit_flag = 1;
        }
        if(key[KEY_W]) {
            cam_pos = VEC3F_SUM(cam_pos, cam_dir);
        }
        if(key[KEY_S]) {
            cam_pos = VEC3F_DIFF(cam_pos, cam_dir);
        }
        if(key[KEY_A]) {
            cam_pos = VEC3F_SUM(cam_pos, cam_dir_normal);
        }
        if(key[KEY_D]) {
            cam_pos = VEC3F_DIFF(cam_pos, cam_dir_normal);
        }

        set_fov(90.0);
        if(mouse_b > 1)
            set_fov(30.0);

        build_view_volume(view_volume);

        reset_mat16f(tmat);
        rotate_x_mat16f(tmat, cam_ang.x);
        rotate_y_mat16f(tmat, cam_ang.y);
        rotate_z_mat16f(tmat, 0.0);
        translate_mat16f(tmat, cam_pos.x, cam_pos.y, cam_pos.z);

        for(i = 0; i < 5; i++)
            transform_vec3f(&view_volume[i], view_volume[i], tmat);

        reset_mat16f(tmat);
        translate_mat16f(tmat, -cam_pos.x, -cam_pos.y, -cam_pos.z);
        rotate_z_mat16f(tmat, 0.0);
        rotate_y_mat16f(tmat, -cam_ang.y);
        rotate_x_mat16f(tmat, -cam_ang.x);

        for(i = 0; i < vnum; i++)
        {
            transform_vec3f(&map_vertex[i].trans, map_vertex[i].object, tmat);
            project_vertex(&map_vertex[i]);
        }

        for(i = 0; i < node_num; i++)
            tree[i].flag = 0;
        int checks = 0;
        mark_nodes_inside_volume(tree, 0, map_vertex, view_volume, 5, &checks);
        int count = 0;
        for(i = 0; i < node_num; i++)
            if(tree[i].flag == 1)
                count++;

        clear_to_color(buffer, 0);
        clear_to_color(BASE_INT_z_buffer, BASE_INT_z_buffer_precision);
        traverse_tree(tree, 0, cam_pos, map_vertex, -1);

        textprintf_ex(buffer, font, 10, 10, makecol(255, 255, 255), 0, "FPS: %d", fps);
        textprintf_ex(buffer, font, 10, 10, makecol(255, 255, 255), 0, "FPS: %d", fps);
        textprintf_ex(buffer, font, 10, 20, makecol(255, 255, 255), 0, "Rendered: %d of nodes, %d of faces.",
                      (int)((float)checks / (float)node_num * 100.0), (int)((float)count / (float)node_num * 100.0));
        //textprintf_ex(buffer, font, 10, 20, makecol(255, 255, 255), 0, "%d", checks);
        blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
        frame_count++;
    }

    deinit_engine();

    for(i = 0; i < node_num; i++)
        free(tree[i].poly.vind);
    free(tree);
    free(map_vertex);

    return 0;
}
コード例 #13
0
ファイル: exsub.c プロジェクト: stefanhendriks/dune2themaker
int main() {
	
	BITMAP *mysha = NULL, *buffer = NULL;
	PARTICLE *particle[NUM_PARTICLES];
	int old_time = 0, old_time2 = 0;
	int i;
	int count = 0;
	int use_alleg = FALSE;
	int depth = 16;
	
	allegro_init();
	
	install_keyboard();
	install_timer();
	
	set_config_file("examples.cfg");
	depth = get_config_int("examples", "depth", 16);

	set_color_depth(depth);	
	if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
		set_color_depth(16);
			if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
			set_color_depth(15);
			if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
				set_color_depth(32);
				if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
					allegro_message("Unable to set 640x480 screen mode!\n");
					return -1;
				}
			}
		}
	}
	
	mysha = load_bitmap("mysha.pcx", NULL);
	
	if (!mysha) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to load mysha.pcx. Copy it from the allegro examples directory.\n");
		return -2;
	}
	
	TRACE("Got here!\n");
	
	for (i = 0; i < NUM_PARTICLES; i++)
		particle[i] = NULL;
		
	TRACE("Still here!\n");
	
	for (i = 0; i < NUM_PARTICLES; i++) {
		int j;
		int r, g, b;
		
		TRACE("Going for particle: %i\n", i);
	
		particle[i] = malloc(sizeof(PARTICLE));		
		if (!particle[i]) {
			TRACE("Out of memory while creating particle!\n");
			goto Error;
		}
		
		TRACE("Clearing particle\n");
		
		memset(particle[i], 0, sizeof(PARTICLE));
		
		TRACE("Creating bitmap\n");
		
		particle[i]->bmp = create_bitmap(64, 64);		
		if (!particle[i]->bmp) {
			TRACE("Out of memory while creating particle bitmap!\n");
			goto Error;
		}
		
		TRACE("Clearing bitmap\n");
			
		clear(particle[i]->bmp);
			
		TRACE("Setting up coordinates\n");
			
		particle[i]->x = rand() % SCREEN_W;
		particle[i]->y = rand() % SCREEN_H;
		particle[i]->vx = rand() % 10 - 5;
		particle[i]->vy = rand() % 10 - 5;
		particle[i]->a = rand() & 255;
		particle[i]->a_dir = 1;
		
		TRACE("Setting up colors\n");
		hsv_to_rgb(rand() % 360, 1, 1, &r, &g, &b);
		
		TRACE("Drawing circles\n");
		
		for (j = 1; j < 31; j++) {
			circle(particle[i]->bmp, 31, 32, j, makecol(r*2/(j+1), g*2/(j+1), b*2/(j+1)));
			circle(particle[i]->bmp, 32, 32, j, makecol(r*2/(j+1), g*2/(j+1), b*2/(j+1)));
		}
	}
	
	LOCK_FUNCTION(the_timer);
	LOCK_VARIABLE(chrono);
		
	buffer = create_bitmap(SCREEN_W, SCREEN_H);
	
	if (!buffer) {
		TRACE("Out of memory while creating back buffer!\n");
		goto Error;
	}
	
	clear(buffer);

	TRACE("Starting...\n");
	
	install_int(the_timer, 1);
	old_time = chrono;
	
	text_mode(0);
	
	do {
		int chrono2;
	
		/* Tile mysha over the screen */
		#ifndef COMPARE_WITH_ALLEGRO
		blit(mysha, buffer, 0, 0, 0, 0, mysha->w, mysha->h);
		blit(mysha, buffer, 0, 0, 320, 0, mysha->w, mysha->h);
		blit(mysha, buffer, 0, 0, 0, 200, mysha->w, mysha->h);
		blit(mysha, buffer, 0, 0, 320, 200, mysha->w, mysha->h);
		blit(mysha, buffer, 0, 0, 0, 400, mysha->w, mysha->h);
		blit(mysha, buffer, 0, 0, 320, 400, mysha->w, mysha->h);
		#endif
		
		if (use_alleg) {		
			for (i = 0; i < NUM_PARTICLES; i++) {
				set_difference_blender(0, 0, 0, particle[i]->a);
				draw_trans_sprite(buffer, particle[i]->bmp, particle[i]->x - particle[i]->bmp->w/2, particle[i]->y - particle[i]->bmp->h/2);
			}
		}
		else {
			for (i = 0; i < NUM_PARTICLES; i++)
				fblend_sub(particle[i]->bmp, buffer, particle[i]->x - particle[i]->bmp->w/2, particle[i]->y - particle[i]->bmp->h/2, particle[i]->a);
		}
		
		if (key[KEY_SPACE]) {
			use_alleg = !use_alleg;
			key[KEY_SPACE] = 0;
			chrono = 0;
			count = 0;
			old_time = 0;
			old_time2 = 0;
		}
		count++;			

		#ifdef COMPARE_WITH_ALLEGRO			
		textprintf(screen, font, 0, 0, makecol(255, 255, 255), "%s  %.2f fps (%.3f avg)", use_alleg ? "Using Allegro" : "Using new", (chrono - old_time2) == 0 ? 1000.0 : 1000 / ((double)chrono - old_time2), count * 1000.0 / chrono);
		#else
		textprintf(buffer, font, 0, 0, makecol(255, 255, 255), "%s  %.2f fps (%.3f avg)", use_alleg ? "Using Allegro" : "Using new", (chrono - old_time2) == 0 ? 1000.0 : 1000 / ((double)chrono - old_time2), count * 1000.0 / chrono);
		#endif
							
		old_time2 = chrono;
	
		
		#ifndef COMPARE_WITH_ALLEGRO
		
		/* Draw the buffer */
		blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		
		#endif

		chrono2 = chrono / 40;		
		for (i = old_time/40; i < chrono2; i++) {
			int j;
			for (j = 0; j < NUM_PARTICLES; j++) {
				particle[j]->x += particle[j]->vx;
				particle[j]->y += particle[j]->vy;
				
				if (particle[j]->x <= 0 || particle[j]->x >= SCREEN_W)
					particle[j]->vx = -particle[j]->vx;
				if (particle[j]->y <= 0 || particle[j]->y >= SCREEN_H)
					particle[j]->vy = -particle[j]->vy;
		
				if (particle[j]->a <= 0 || particle[j]->a >= 256)
					particle[j]->a_dir = -particle[j]->a_dir;
					
				particle[j]->a += particle[j]->a_dir;
			}
		}
		old_time = chrono;
		
	} while (!key[KEY_ESC]);
	
	Error:
	
	TRACE("Shutting down.\n");
	
	if (mysha)
		destroy_bitmap(mysha);
	if (buffer)
		destroy_bitmap(buffer);
	
	for (i = 0; i < NUM_PARTICLES; i++) {
		if (particle[i]) {
			if (particle[i]->bmp)
				destroy_bitmap(particle[i]->bmp);
			free(particle[i]);
		}
	}

	set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
	
	return 0;	
	
} END_OF_MAIN();
コード例 #14
0
int main()
{
 int exit_flag = 0, i;
 MAT16F tmat, modelmat;
 VEC3F pos = vec3f(0.0, 0.0, 0.5), ang = vec3f(0.0, 0.0, 0.0);

 int vnum, snum;
 VEC2F *map_vec2f;
 WALL_SEGMENT *map_segment;
 VERTEX *map_vertex;

 MD2_MODEL mdl;
 VERTEX *model_verts;
 TRI *model_tris;

 VERTEX floor[4];
 floor[0].local = vec3f(-200.0, 0.0, 200.0);
 floor[1].local = vec3f(200.0, 0.0, 200.0);
 floor[2].local = vec3f(200.0, 0.0, -200.0);
 floor[3].local = vec3f(-200.0, 0.0, -200.0);
 
  NODE *head = NULL;

 init();
 
 
  if(load_md2("data/babe.md2", &mdl))
  {
   allegro_message("Error: I need the MD2 model, stupid!");
   exit(1);
  }

 convert_md2_to_base(&model_verts, &model_tris, &mdl, 0.2);

 load_map("map.txt", &map_vec2f, &map_segment, &vnum, &snum, 1.0);

 head = (NODE *)malloc(sizeof(NODE));
 head->val = val;
 head->a = map_segment[0].a;
 head->b = map_segment[0].b;
 head->n = NORMALIZED_NORMAL_VEC2F(map_vec2f[map_segment[0].a], map_vec2f[map_segment[0].b]);
 head->parent = NULL;
 head->left = NULL;
 head->right = NULL;
 val++;
 
 for(i = 1; i < snum; i++)
  {
   add_node(head, &val, map_segment[i].a, map_segment[i].b, &map_vec2f, &vnum);
   val++;
  }
  
  map_vertex = (VERTEX *)malloc(vnum * 2 * sizeof(VERTEX));

 for(i = 0; i < vnum; i++)
  {
   map_vertex[i * 2].local = USCALE_VEC3F(vec3f(map_vec2f[i].x, 0.0, map_vec2f[i].y), 0.2);
   map_vertex[i * 2 + 1].local = USCALE_VEC3F(vec3f(map_vec2f[i].x, WALL_HEIGHT, map_vec2f[i].y), 0.2);
   map_vec2f[i] = USCALE_VEC2F(map_vec2f[i], 0.2);
  }

 LOCK_VARIABLE(fps);
 LOCK_VARIABLE(frame_count);
 LOCK_FUNCTION(update_fps);
 install_int(update_fps, 1000);

 float frame = 0.0;

 VEC3F cam_pos = vec3f(0.0, 3.0, 0.0), cam_dir, cam_dir_normal, cam_ang = vec3f(0.0, 0.0, 0.0);

 while(!exit_flag)
  {              
   set_texture_mapping_mode(0);

   int mx, my;
   get_mouse_mickeys(&mx, &my);
   position_mouse(SCREEN_W / 2, SCREEN_H / 2);

   cam_ang.x += my * 0.001;
   cam_ang.y -= mx * 0.001;
   cam_dir.x = SPEED * cos(0.5 * M_PI + cam_ang.y);
   cam_dir.y = 0.0;
   cam_dir.z = SPEED * sin(0.5 * M_PI + cam_ang.y);
   cam_dir_normal = vec3f(-cam_dir.z, 0.0, cam_dir.x);

   if(key[KEY_ESC]) { exit_flag = 1; }
   if(key[KEY_W]) { cam_pos = VEC3F_SUM(cam_pos, cam_dir); }
   if(key[KEY_S]) { cam_pos = VEC3F_DIFF(cam_pos, cam_dir); }
   if(key[KEY_A]) { cam_pos = VEC3F_SUM(cam_pos, cam_dir_normal); }
   if(key[KEY_D]) { cam_pos = VEC3F_DIFF(cam_pos, cam_dir_normal); }
   //if(key[KEY_SPACE]) { set_texture_mapping_mode(1); }

   reset_mat16f(tmat);
   translate_mat16f(tmat, -cam_pos.x, -cam_pos.y, -cam_pos.z);
   rotate_mat16f(tmat, -cam_ang.x, -cam_ang.y, 0.0);

   convert_md2_frame_to_base(model_verts, &mdl, frame, 0.2);
   frame += 0.1;
   reset_mat16f(modelmat);
   rotate_mat16f(modelmat, M_PI * 1.5, 0.0, 0.0);
   translate_mat16f(modelmat, 0.0, 5.0, 0.0);
   translate_mat16f(modelmat, -cam_pos.x, -cam_pos.y, -cam_pos.z);
   rotate_mat16f(modelmat, -cam_ang.x, -cam_ang.y, 0.0);

   for(i = 0; i < vnum * 2; i++)
    transform_vec3f(&map_vertex[i].world, map_vertex[i].local, tmat);
   for(i = 0; i < 4; i++)
    transform_vec3f(&floor[i].world, floor[i].local, tmat);
   for(i = 0; i < mdl.header.num_vertices; i++)
    transform_vec3f(&model_verts[i].world, model_verts[i].local, modelmat);

   clear_bitmap(buffer);
   clear_to_color(zbuffer, ZBUFFER_PRECISION);

   bind_texture(texture);

   VEC2F p = vec2f(cam_pos.x, cam_pos.z);
   VEC2F v = vec2f(cam_dir.x, cam_dir.z);
   traverse_tree(head, p, v, map_vec2f, map_vertex);

   bind_texture(skin);
   for(i = 0; i < mdl.header.num_tris; i++)
    {
     update_tri_normal(&model_tris[i], model_verts);
     model_tris[i].n = NORMALIZED_VEC3F(model_tris[i].n);
     if(cull_backface(&model_tris[i], model_verts))
      render_tri(&model_tris[i], model_verts);
    }
    
   bind_texture(texture2);
   TRI temp;
   temp.a = 0; temp.b = 1; temp.c = 2;
   temp.tex[0] = vec2f(0.0, 0.0); temp.tex[1] = vec2f(20.0, 0.0); temp.tex[2] = vec2f(20.0, 20.0);
   render_tri(&temp, floor);
   temp.a = 2; temp.b = 3; temp.c = 0;
   temp.tex[0] = vec2f(20.0, 20.0); temp.tex[1] = vec2f(20.0, 0.0); temp.tex[2] = vec2f(0.0, 0.0);
   render_tri(&temp, floor);

   textprintf_ex(buffer, font, 10, 10, makecol(255, 255, 255), 0, "FPS: %d", fps);
   blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
   frame_count++;
  }

 destroy_bitmap(texture2);
 destroy_tree(head);
 free_md2(&mdl);
 free(model_tris);
 free(model_verts);
 free(map_vertex);
 free(map_vec2f);
 free(map_segment);
 destroy_bitmap(skin);
 destroy_bitmap(texture);
 destroy_bitmap(zbuffer);
 destroy_bitmap(buffer);
 deinit_renderer();

 return 0;
}
コード例 #15
0
ファイル: BFCULL.C プロジェクト: alejandro-du/legacy
int main(void)
{
  BITMAP *textura, *back_buffer;
  int x, y, c; // para rellenar la textura
  int tecla;
  int nPol;
  int i;
  char angulo_x = 0, angulo_y = 0, angulo_z = 0;
  float trans_z = 12.1;
  POLIGONO3D cara[6]; // un cubo
  PUNTO3D ver_t[4]; // v‚rtices transformados para un pol¡gono
  V3D_f ver_p[4]; // v‚rtices proyectados (2d) para un pol¡gono
  MATRIX_f matriz;

  printf("\nEjemplo de: backface culling (eliminaci¢n de caras posteriores)");
  printf("\n\nControles:");
  printf("\n  Q, W, flechas = rotar cubo.");
  printf("\n  A, Z = z++, z--.");
  printf("\n\n\nPresione una tecla para comenzar...\n");
  getch();

  // inicializar allegro y otras cosas
  allegro_init();
  set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0);
  install_keyboard();
  install_timer();
  install_int(&cont_frames, 1000);
  LOCK_VARIABLE(nFrames);
  LOCK_VARIABLE(nFramesPorSegundo);
  LOCK_FUNCTION(cont_frames);

  back_buffer = create_bitmap(SCREEN_W, SCREEN_H);
  clear(back_buffer);

  // crear una textura
  textura = create_bitmap(TEX_W, TEX_H);
  clear(textura);

  c = 1; // color
  for(x = 0; x < TEX_W; x++) {
    for(y = 0; y < TEX_H; y++) {
      putpixel(textura, x, y, c);
      if(c++ > 64)
        c = 1;
    }
  }

  line(textura, 0, 0, TEX_W, TEX_H, 4);
  line(textura, TEX_W, 0, 0, TEX_H, 4);

  line(textura, 0, 0, 0, TEX_H, 4);
  line(textura, 0, 0, TEX_W, 0, 4);
  line(textura, 0, TEX_H - 1, TEX_W - 1, TEX_H - 1, 4);
  line(textura, TEX_W - 1, TEX_H - 1, TEX_W - 1, 0, 4);

  textprintf(textura, font, 1, 1, 13, "Textura");

  // inicializar las coordenadas 3d del cubo

  cara[0].ver[0].x = -2;
  cara[0].ver[0].y = -2;
  cara[0].ver[0].z = -2;
  cara[0].ver[1].x = 2;
  cara[0].ver[1].y = -2;
  cara[0].ver[1].z = -2;
  cara[0].ver[2].x = 2;
  cara[0].ver[2].y = 2;
  cara[0].ver[2].z = -2;
  cara[0].ver[3].x = -2;
  cara[0].ver[3].y = 2;
  cara[0].ver[3].z = -2;

  cara[1].ver[0].x = 2;
  cara[1].ver[0].y = -2;
  cara[1].ver[0].z = 2;
  cara[1].ver[1].x = -2;
  cara[1].ver[1].y = -2;
  cara[1].ver[1].z = 2;
  cara[1].ver[2].x = -2;
  cara[1].ver[2].y = 2;
  cara[1].ver[2].z = 2;
  cara[1].ver[3].x = 2;
  cara[1].ver[3].y = 2;
  cara[1].ver[3].z = 2;

  cara[2].ver[0].x = -2;
  cara[2].ver[0].y = -2;
  cara[2].ver[0].z = 2;
  cara[2].ver[1].x = -2;
  cara[2].ver[1].y = -2;
  cara[2].ver[1].z = -2;
  cara[2].ver[2].x = -2;
  cara[2].ver[2].y = 2;
  cara[2].ver[2].z = -2;
  cara[2].ver[3].x = -2;
  cara[2].ver[3].y = 2;
  cara[2].ver[3].z = 2;

  cara[3].ver[0].x = 2;
  cara[3].ver[0].y = -2;
  cara[3].ver[0].z = -2;
  cara[3].ver[1].x = 2;
  cara[3].ver[1].y = -2;
  cara[3].ver[1].z = 2;
  cara[3].ver[2].x = 2;
  cara[3].ver[2].y = 2;
  cara[3].ver[2].z = 2;
  cara[3].ver[3].x = 2;
  cara[3].ver[3].y = 2;
  cara[3].ver[3].z = -2;

  cara[4].ver[0].x = -2;
  cara[4].ver[0].y = -2;
  cara[4].ver[0].z = 2;
  cara[4].ver[1].x = 2;
  cara[4].ver[1].y = -2;
  cara[4].ver[1].z = 2;
  cara[4].ver[2].x = 2;
  cara[4].ver[2].y = -2;
  cara[4].ver[2].z = -2;
  cara[4].ver[3].x = -2;
  cara[4].ver[3].y = -2;
  cara[4].ver[3].z = -2;

  cara[5].ver[0].x = -2;
  cara[5].ver[0].y = 2;
  cara[5].ver[0].z = -2;
  cara[5].ver[1].x = 2;
  cara[5].ver[1].y = 2;
  cara[5].ver[1].z = -2;
  cara[5].ver[2].x = 2;
  cara[5].ver[2].y = 2;
  cara[5].ver[2].z = 2;
  cara[5].ver[3].x = -2;
  cara[5].ver[3].y = 2;
  cara[5].ver[3].z = 2;

  // inicializar las coordenadas de la textura
  ver_p[0].u = 0;
  ver_p[0].v = 0;
  ver_p[1].u = TEX_W;
  ver_p[1].v = 0;
  ver_p[2].u = TEX_W;
  ver_p[2].v = TEX_H;
  ver_p[3].u = 0;
  ver_p[3].v = TEX_H;

  set_projection_viewport(0, 0, SCREEN_W, SCREEN_H);

  do {

    // teclado
    if(key[KEY_UP]) {
       angulo_x++;
    }
    if(key[KEY_DOWN]) {
       angulo_x--;
    }
    if(key[KEY_RIGHT]) {
       angulo_y--;
    }
    if(key[KEY_LEFT]) {
       angulo_y++;
    }
    if(key[KEY_Q]) {
       angulo_z++;
    }
    if(key[KEY_W]) {
       angulo_z--;
    }
    if(key[KEY_A]) {
       trans_z+=0.2;
    }
    if(key[KEY_Z]) {
       trans_z-=0.2;
    }

    get_transformation_matrix_f(&matriz,
                                1, // escala
                                angulo_x, // angulo rotaci¢n x
                                angulo_y, // angulo rotaci¢n y
                                angulo_z, // angulo rotaci¢n z
                                0, // translaci¢n x
                                0, // translaci¢n y
                                trans_z); // translaci¢n z

    for(nPol = 0; nPol < 6; nPol++) { // cada pol¡gono

      for(i = 0; i < 4; i++) { // cada v‚rtice del pol¡gono

        // transformaci¢n
        apply_matrix_f(&matriz,
                       cara[nPol].ver[i].x,
                       cara[nPol].ver[i].y,
                       cara[nPol].ver[i].z,
                       &ver_t[i].x,
                       &ver_t[i].y,
                       &ver_t[i].z);

        // proyecci¢n
        persp_project_f(ver_t[i].x,
                        ver_t[i].y,
                        ver_t[i].z,
                        &ver_p[i].x,
                        &ver_p[i].y);

        ver_p[i].z = ver_t[i].z; // requerido para renderizar la textura
      }

      // si la normal al pol¡gono es positiva -> pintar
      if(polygon_z_normal_f(&ver_p[0], &ver_p[1], &ver_p[2]) > 0) {
        quad3d_f(back_buffer,
                 POLYTYPE_PTEX,
                 textura,
                 &ver_p[0],
                 &ver_p[1],
                 &ver_p[2],
                 &ver_p[3]);
      }
    }

    textprintf(back_buffer, font, 0, 190, 2, "%d FPS", nFramesPorSegundo);
    blit(back_buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
    nFrames++;
    clear(back_buffer);

  } while(!key[KEY_ESC]);

  allegro_exit();

  return 0;
}
コード例 #16
0
int
main(int argc, char **argv)
{
	BITMAP *bmp;
	PACKFILE *f;
	char *file = NULL, *times = NULL, *memory = NULL;
	int arg, i, n, start, end, size;

	allegro_init();
	install_keyboard();
	install_timer();
	
	jpgalleg_init();
	
	set_color_conversion(COLORCONV_NONE);
	
	for (arg = 1; arg < argc; arg++) {
		if (!strcmp(argv[arg], "-nommx"))
			cpu_capabilities &= ~CPU_MMX;
		else if (!strcmp(argv[arg], "-f"))
			file = argv[++arg];
		else if (!times)
			times = argv[arg];
		else
			about();
	}
	if (times)
		n = atoi(times);
	else
		n = 30;
	if (!file)
		file = "jpgalleg.jpg";
	bmp = load_jpg(file, NULL);
	if (!bmp) {
		printf("Cannot find %s!\n", file);
		return -1;
	}
	size = file_size(file);
	memory = (char *)malloc(size);
	if (!memory) {
		printf("Not enough memory!\n");
		return -1;
	}
	f = pack_fopen(file, F_READ);
	pack_fread(memory, size, f);
	pack_fclose(f);
	
	LOCK_FUNCTION(timer_handler);
	LOCK_VARIABLE(timer);
	
	install_int(timer_handler, 10);
	
	printf("Average timing for %d function calls:\n", n);
	start = timer;
	for (i = 0; i < n; i++)
		bmp = load_jpg(file, NULL);
	end = timer;
	printf("load_jpg: %f seconds\n", ((float)end - (float)start) / 1000.0 / (float)n);

	start = timer;
	for (i = 0; i < n; i++)
		bmp = load_memory_jpg(memory, size, NULL);
	end = timer;
	printf("load_memory_jpg: %f seconds\n", ((float)end - (float)start) / 1000.0 / (float)n);
	
	free(memory);
	return 0;
}
コード例 #17
0
void inicia_allegro() {
	int profundidade, res;
	allegro_init();
	install_timer();
	install_keyboard();
	clear_keybuf();
	install_mouse();

	set_uformat(U_ASCII); // Habilita acentuação em ALGUMAS FONTES
	/*profundidade = desktop_color_depth();
	if (profundidade == 0) profundidade = 32;
	   set_color_depth(profundidade);*/

	//roda configuracao de um arquivo
	set_config_file("config.txt");

	profundidade = get_config_int("Inicializacao", "colordepth",32);
	int v = GetVersion() & 65535;
    float versao = (v%256) + (v/256)/10.;
    /*if (versao<=5.1) //5.1 = XP, 6.0 = Vista, 6.1 Win7
        profundidade=16;
    else
        profundidade=32;*/

	set_color_depth(profundidade); //padrao é 32 bits, no XP é 16

	volume=get_config_int("Inicializacao", "volume", 128); //usa as config de volume do arquivo
	exibirFPS=get_config_int("Inicializacao", "exibirFps", 0);

	#define GFX_BWINDOWSCREEN_ACCEL AL_ID('B','W','S','A')
	#define GFX_BWINDOWSCREEN        AL_ID('B','W','S',' ')
    AL_VAR(GFX_DRIVER, gfx_beos_bwindowscreen_accel);
    AL_VAR(GFX_DRIVER, gfx_beos_bwindowscreen);

	vSync = get_config_int("Inicializacao", "vsync",0);
	resolucaoX = get_config_int("Inicializacao", "resolucaox",800);
	resolucaoY = get_config_int("Inicializacao", "resolucaoy",600);
    //Fullscreen
    //res = set_gfx_mode(GFX_AUTODETECT_FULLSCREEN & GFX_BWINDOWSCREEN_ACCEL, resolucaoX, resolucaoY, 0, 0);
    //Janela
	res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, resolucaoX, resolucaoY, 0, 0);
	if (res != 0) {
		allegro_message(allegro_error);
		exit(-1);
	}
	if(install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL))
    {
        allegro_message("Sound Error: %s", allegro_error);
    }

	//inicializa o metodo de atualizacao
	initialize_screen_updating(get_config_int("Inicializacao", "updatemethod", UPDATE_TRIPLE_BUFFER));

    set_window_title("Snake Criado por Arthur Assuncao"); //nome da Janela

    set_display_switch_mode(SWITCH_BACKGROUND); //roda o allegro em segundo plano

    //Botao fechar
    LOCK_FUNCTION(BotaoFechar);
    set_close_button_callback(BotaoFechar);

	//Contador de frames
	// Faz o lock das variaveis usadas pela funcao de timer e da propria funcao
    LOCK_VARIABLE(fps);
    LOCK_VARIABLE(contFrames);
    LOCK_FUNCTION(funcFPS);
	//chama a funcao funcFPS
	install_int_ex(funcFPS,BPS_TO_TIMER(MAXFPS)); //Frames por segundo, 60FPS
	//chama a funcao funcTempo
	LOCK_VARIABLE(contTempo);
    LOCK_FUNCTION(funcTempo);
	install_int(funcTempo, 1000); //Timer "ticks" a cada mil milisegundos, ou seja, 1 segundo

	/* adicione outras iniciacoes aqui */
}
コード例 #18
0
ファイル: mouse.c プロジェクト: AntonLanghoff/whitecatlib
/* install_mouse:
 *  Installs the Allegro mouse handler. You must do this before using any
 *  other mouse functions. Return -1 if it can't find a mouse driver,
 *  otherwise the number of buttons on the mouse.
 */
int install_mouse(void)
{
   _DRIVER_INFO *driver_list;
   int num_buttons = -1;
   int config_num_buttons;
   AL_CONST char *emulate;
   char tmp1[64], tmp2[64];
   int i;

   if (mouse_driver)
      return 0;

   LOCK_VARIABLE(mouse_driver);
   LOCK_VARIABLE(mousedrv_none);
   LOCK_VARIABLE(mouse_x);
   LOCK_VARIABLE(mouse_y);
   LOCK_VARIABLE(mouse_z);
   LOCK_VARIABLE(mouse_w);
   LOCK_VARIABLE(mouse_b);
   LOCK_VARIABLE(mouse_pos);
   LOCK_VARIABLE(_mouse_x);
   LOCK_VARIABLE(_mouse_y);
   LOCK_VARIABLE(_mouse_z);
   LOCK_VARIABLE(_mouse_w);
   LOCK_VARIABLE(_mouse_b);
   LOCK_VARIABLE(_mouse_on);
   LOCK_VARIABLE(mon);
   LOCK_VARIABLE(emulate_three);
   LOCK_VARIABLE(freeze_mouse_flag);
   LOCK_VARIABLE(mouse_callback);
   LOCK_VARIABLE(mouse_x_focus);
   LOCK_VARIABLE(mouse_y_focus);
   LOCK_VARIABLE(mouse_sprite);
   LOCK_VARIABLE(_mouse_pointer);
   LOCK_VARIABLE(_mouse_screen);
   LOCK_VARIABLE(mx);
   LOCK_VARIABLE(my);
   LOCK_VARIABLE(ms);
   LOCK_VARIABLE(mtemp);
   LOCK_VARIABLE(mouse_polled);
   LOCK_VARIABLE(mouse_semaphore);
   LOCK_VARIABLE(cursors);
   LOCK_FUNCTION(draw_mouse_doublebuffer);
   LOCK_FUNCTION(draw_mouse);
   LOCK_FUNCTION(update_mouse);
   LOCK_FUNCTION(mouse_move);
   LOCK_FUNCTION(poll_mouse);
   LOCK_FUNCTION(mouse_needs_poll);
   LOCK_FUNCTION(_handle_mouse_input);
   
   /* Construct mouse pointers */
   if (!default_cursors[MOUSE_CURSOR_ARROW])
      default_cursors[MOUSE_CURSOR_ARROW] = create_mouse_pointer(mouse_arrow_data);
   if (!default_cursors[MOUSE_CURSOR_BUSY])
      default_cursors[MOUSE_CURSOR_BUSY] = create_mouse_pointer(mouse_busy_data);
   if (!default_cursors[MOUSE_CURSOR_QUESTION])
      default_cursors[MOUSE_CURSOR_QUESTION] = create_mouse_pointer(mouse_arrow_data);
   if (!default_cursors[MOUSE_CURSOR_EDIT])
      default_cursors[MOUSE_CURSOR_EDIT] = create_mouse_pointer(mouse_arrow_data);

   cursors[MOUSE_CURSOR_ARROW] = default_cursors[MOUSE_CURSOR_ARROW];
   cursors[MOUSE_CURSOR_BUSY] = default_cursors[MOUSE_CURSOR_BUSY];
   cursors[MOUSE_CURSOR_QUESTION] = default_cursors[MOUSE_CURSOR_QUESTION];
   cursors[MOUSE_CURSOR_EDIT] = default_cursors[MOUSE_CURSOR_EDIT];

   if (system_driver->mouse_drivers)
      driver_list = system_driver->mouse_drivers();
   else
      driver_list = _mouse_driver_list;

   if (_mouse_type == MOUSEDRV_AUTODETECT)
      _mouse_type = get_config_id(uconvert_ascii("mouse", tmp1), uconvert_ascii("mouse", tmp2), MOUSEDRV_AUTODETECT);

   if (_mouse_type != MOUSEDRV_AUTODETECT) {
      for (i=0; driver_list[i].driver; i++) {
	 if (driver_list[i].id == _mouse_type) {
	    mouse_driver = driver_list[i].driver;
	    break;
	 }
      }
   }

   if (mouse_driver) {
      mouse_driver->name = mouse_driver->desc = get_config_text(mouse_driver->ascii_name);
      num_buttons = mouse_driver->init();
   } 
   else {
      for (i=0; num_buttons<0; i++) {
	 if (!driver_list[i].driver)
	    break;

	 mouse_driver = driver_list[i].driver;
	 mouse_driver->name = mouse_driver->desc = get_config_text(mouse_driver->ascii_name);
	 num_buttons = mouse_driver->init();
      }
   }

   if (num_buttons < 0) {
      mouse_driver = NULL;
      return -1;
   }

   config_num_buttons = get_config_int(uconvert_ascii("mouse", tmp1), uconvert_ascii("num_buttons", tmp2), -1);
   emulate = get_config_string(uconvert_ascii("mouse", tmp1), uconvert_ascii("emulate_three", tmp2), NULL);

   /* clamp config_num_buttons to zero/positive values */
   if (config_num_buttons >= 0)
      num_buttons = config_num_buttons;

   if ((emulate) && ((i = ugetc(emulate)) != 0)) {
      if ((i == 'y') || (i == 'Y') || (i == '1'))
	 emulate_three = TRUE;
      else
	 emulate_three = FALSE;
   }
   else {
      emulate_three = FALSE;
   }

   mouse_polled = (mouse_driver->poll) ? TRUE : FALSE;

   _mouse_installed = TRUE;
   
   disable_hardware_cursor();

   set_mouse_etc();
   _add_exit_func(remove_mouse, "remove_mouse");

   if (mouse_driver->timer_poll)
      install_int(mouse_move, 10);

   return num_buttons;
}
コード例 #19
0
ファイル: main.cpp プロジェクト: Bencepapa/CymonsGames
//main function
void main()
{
    //setup allegro
    allegro_init();
    install_mouse();
    install_timer();
    set_color_depth(COLOR_DEPTH);
    set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0);

    //setup the timer
    install_int(update_timer, 1);

    //seed random number
    srand(time(NULL));

    //set up the close button
    set_close_button_callback(quit);

    //initialize the buffer
    buffer = create_bitmap(WIDTH, HEIGHT);

    //main loop
    while (!end_game)
    {
        //log the start time
        start_time = timer;

        F_PLUS = (loop_num/50);
        if (F_PLUS > 120) F_PLUS = 120;

        mx = (mouse_x+mx*7)/8;
        my = (mouse_y+my*7)/8;

        if (mouse_b & 2) {nshots = 0; score = 0; ray_t = 50; game_over = false;}

        //fire a new shot
        if (loop_num % 10-F_PLUS/30 == 0)
        {
                if (rand()%2)
                {
                        shot[nshots].x = rand()%2*WIDTH;
                        shot[nshots].y = rand()%HEIGHT;
                        shot[nshots].vy = 0;
                        shot[nshots].vx = (WIDTH/2-shot[nshots].x)/(WIDTH/2);
                        nshots++;
                }
                else
                {
                        shot[nshots].y = rand()%2*HEIGHT;
                        shot[nshots].x = rand()%WIDTH;
                        shot[nshots].vx = 0;
                        shot[nshots].vy = (HEIGHT/2-shot[nshots].y)/(HEIGHT/2);
                        nshots++;
                }
        }
        //rays
        if ((loop_num % 300-F_PLUS == 0)&&(loop_num > 300))
        {
                ray_x = mx+rand()%11-5;
                ray_y = my+rand()%11-5;
                ray_t = -40;
        }

        if (loop_num % 2) ray_t++;

        //bullet move
        for (int i = 0; i < nshots; i++)
        {
                shot[i].x += shot[i].vx;
                shot[i].y += shot[i].vy;
                if ((shot[i].x > WIDTH)||(shot[i].y > HEIGHT)||(shot[i].x < 0)||(shot[i].y < 0)){nshots--; shot[i] = shot[nshots];}
                if (hit(mx, my, shot[i].x, shot[i].y, 5)){game_over = true;}
        }

        //death
        if ((abs(ray_t) < 20)&&(((mx < ray_x+(20-abs(ray_t)))&&(mx > ray_x-(20-abs(ray_t))))
        ||((my < ray_y+(20-abs(ray_t)))&&(my > ray_y-(20-abs(ray_t)))))){game_over = true;}

        ////drawing////

        //player
        if (!game_over)
        circle(buffer, mx, my, 5, WHITE);
        else
        circle(buffer, mx, my, 5, makecol(255, 0, 0));

        //bullets
        for (int i = 0; i < nshots; i++)
        {
                circlefill(buffer, shot[i].x, shot[i].y, 2, WHITE);
        }

        //beams
        if (ray_t <= -20)
        {
                hline(buffer, 0, ray_y, WIDTH, WHITE);
                vline(buffer, ray_x, 0, HEIGHT, WHITE);
        }
        if (abs(ray_t) < 20)
        {
                rectfill(buffer, 0, ray_y-(20-abs(ray_t)), WIDTH, ray_y+(20-abs(ray_t)), WHITE);
                rectfill(buffer, ray_x-(20-abs(ray_t)), 0, ray_x+(20-abs(ray_t)), HEIGHT, WHITE);
                rectfill(buffer, 0, ray_y-(20-abs(ray_t))/2, WIDTH, ray_y+(20-abs(ray_t))/2, SILVER);
                rectfill(buffer, ray_x-(20-abs(ray_t))/2, 0, ray_x+(20-abs(ray_t))/2, HEIGHT, SILVER);
        }

        //text
        if (!game_over)
        textprintf_centre_ex(buffer, font, WIDTH/2, 10, WHITE, BLACK, "%i", score*LOOP_TIME/1000);
        else
        {
        textprintf_centre_ex(buffer, font, WIDTH/2, 10, makecol(255, 0, 0), BLACK, "%i", score*LOOP_TIME/1000);
        textprintf_centre_ex(buffer, font, WIDTH/2, HEIGHT/2-5, WHITE, BLACK, "Game Over");
        textprintf_centre_ex(buffer, font, WIDTH/2, HEIGHT/2+10, WHITE, BLACK, "Right-Click to restart");
        }

        //draw to the screen
        blit(buffer, screen, 0, 0, 0, 0, WIDTH, HEIGHT);

        //clear the buffer
        clear_to_color(buffer, BLACK);

        //wait
        while (timer < start_time + LOOP_TIME)
        {rest(1);}
        loop_num++;
        if (game_over == false) score++;
    }
    remove_int(update_timer);
    destroy_bitmap(buffer);
    return;
}
コード例 #20
0
/*
Self-explanatory.
*/
void init_at_startup(void)
{

   LOCK_FUNCTION (framecount);
   LOCK_FUNCTION (tickover);
   LOCK_VARIABLE (ticked);
   LOCK_VARIABLE (frames_per_second);
   LOCK_VARIABLE (framecounter);
   LOCK_VARIABLE (turns_per_second);
   LOCK_VARIABLE (turncounter);

   install_int (framecount, 1000);
   install_int (tickover, 20);

   set_color_depth(8);

   int randseed = get_config_int("Misc", "Seed", 0);
   srand(randseed);

   options.windowed = get_config_int("Misc", "Windowed", 0);


 int windowed;
 switch(options.windowed)
 {
    default:
     case 1: windowed = GFX_AUTODETECT_WINDOWED; break;
     case 0: windowed = GFX_AUTODETECT_FULLSCREEN; break;
 }

//   windowed  = GFX_AUTODETECT_WINDOWED;
//   windowed = GFX_AUTODETECT_FULLSCREEN;

//   if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0)
   if (set_gfx_mode(windowed, 640, 480, 0, 0) != 0)
   {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Unable to set 640x480 display mode\n%s\n", allegro_error);
      exit(1);
   }

 init_trig();

 prepare_display();
 init_sound();
/*
 player[0].ckey [CKEY_UP] = KEY_UP;
 player[0].ckey [CKEY_DOWN] = KEY_DOWN;
 player[0].ckey [CKEY_LEFT] = KEY_LEFT;
 player[0].ckey [CKEY_RIGHT] = KEY_RIGHT;
 player[0].ckey [CKEY_FIRE1] = KEY_Z;
 player[0].ckey [CKEY_FIRE2] = KEY_X;
 player[0].ckey [CKEY_FIRE3] = KEY_C;
*/

 player[0].ckey [CKEY_UP] = get_config_int("Misc", "key_up", KEY_UP);
 player[0].ckey [CKEY_DOWN] = get_config_int("Misc", "key_down", KEY_DOWN);
 player[0].ckey [CKEY_LEFT] = get_config_int("Misc", "key_left", KEY_LEFT);
 player[0].ckey [CKEY_RIGHT] = get_config_int("Misc", "key_right", KEY_RIGHT);
 player[0].ckey [CKEY_FIRE1] = get_config_int("Misc", "key_fire1", KEY_Z);
 player[0].ckey [CKEY_FIRE2] = get_config_int("Misc", "key_fire2", KEY_X);

 options.joy_stick = get_config_int("Misc", "joy_stick", 0);

 options.joy_sensitivity = get_config_int("Misc", "joy_sensitivity", 70);
 options.init_joystick = get_config_int("Misc", "joy_init", 1);
 options.joystick = 0;
 options.key_or_joy = 0; // don't put in initfile!

 options.sfx_volume = get_config_int("Misc", "sfx_volume", 70);
 options.ambience_volume = get_config_int("Misc", "ambience_volume", 100);
 options.run_vsync = get_config_int("Misc", "run_vsync", 0);

// set_config_int("Misc", "Tourist", 3);
// set_config_int("Misc", "joy_stick", 0);

 if (options.init_joystick)
  init_joystick();

 if (options.joystick == 1) // set in init_joystick
 {
  options.joy_button [0] = get_config_int("Misc", "joy_button_1", 0);
  if (options.joy_button [0] > joy[0].num_buttons)
   options.joy_button [0] = joy[0].num_buttons - 1;
  options.joy_button [1] = get_config_int("Misc", "joy_button_2", 1);
  if (options.joy_button [1] > joy[0].num_buttons)
   options.joy_button [1] = joy[0].num_buttons - 1;
  options.joy_button [2] = get_config_int("Misc", "joy_button_engine", 3);
  if (options.joy_button [2] > joy[0].num_buttons)
   options.joy_button [2] = joy[0].num_buttons - 1;
  options.joy_button [3] = get_config_int("Misc", "joy_button_brake", 2);
  if (options.joy_button [3] > joy[0].num_buttons)
   options.joy_button [3] = joy[0].num_buttons - 1;
 }

 ticked = 0;


}
コード例 #21
0
ファイル: extimer.c プロジェクト: kazzmir/allegro4-to-5
int main(void)
{
    int c;

    if (allegro_init() != 0)
        return 1;
    install_keyboard();
    install_timer();

    if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 320, 200, 0, 0) != 0) {
        if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
            set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
            allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
            return 1;
        }
    }

    set_palette(desktop_palette);
    clear_to_color(screen, makecol(255, 255, 255));

    textprintf_centre_ex(screen, font, SCREEN_W/2, 8, makecol(0, 0, 0),
                         makecol(255, 255, 255), "Driver: %s",
                         timer_driver->name);

    /* use rest() to delay for a specified number of milliseconds */
    textprintf_centre_ex(screen, font, SCREEN_W/2, 48, makecol(0, 0, 0),
                         makecol(255, 255, 255), "Timing five seconds:");

    for (c=1; c<=5; c++) {
        textprintf_centre_ex(screen, font, SCREEN_W/2, 62+c*10,
                             makecol(0, 0, 0), makecol(255, 255, 255), "%d", c);
        rest(1000);
        if (keypressed()) {
            return 0;
        }
    }

    textprintf_centre_ex(screen, font, SCREEN_W/2, 142, makecol(0, 0, 0),
                         makecol(255, 255, 255),
                         "Press a key to set up interrupts");
    readkey();

    /* all variables and code used inside interrupt handlers must be locked */
    LOCK_VARIABLE(x);
    LOCK_VARIABLE(y);
    LOCK_VARIABLE(z);
    LOCK_FUNCTION(inc_x);
    LOCK_FUNCTION(inc_y);
    LOCK_FUNCTION(inc_z);

    /* the speed can be specified in milliseconds (this is once a second) */
    install_int(inc_x, 1000);

    /* or in beats per second (this is 10 ticks a second) */
    install_int_ex(inc_y, BPS_TO_TIMER(10));

    /* or in seconds (this is 10 seconds a tick) */
    install_int_ex(inc_z, SECS_TO_TIMER(10));

    /* the interrupts are now active... */
    while (!keypressed()) {
        textprintf_centre_ex(screen, font, SCREEN_W/2, 176, makecol(0, 0, 0),
                             makecol(255, 255, 255), "x=%d, y=%d, z=%d", x, y, z);
        rest(1);
    }

    return 0;
}
コード例 #22
0
ファイル: extext.c プロジェクト: AntonLanghoff/whitecatlib
int main() {

	FONT *lucidia_fnt;
	FONT *allegro_fnt;
	DATAFILE *dat;
	
	struct {
		float x, y, z;
		int c;
	} coord[NUM_STRINGS];
	char *string = STRING;
	int i;

	allegro_init();
	install_allegro_gl();
	install_timer();
	
	LOCK_FUNCTION(the_timer);
	LOCK_VARIABLE(chrono);
	
	install_int(the_timer, 2);

	allegro_gl_clear_settings();
	allegro_gl_set(AGL_COLOR_DEPTH, 32);
	allegro_gl_set(AGL_Z_DEPTH, 24);
	allegro_gl_set(AGL_WINDOWED, TRUE);
	allegro_gl_set(AGL_DOUBLEBUFFER, 1);
	allegro_gl_set(AGL_RENDERMETHOD, 1);
	allegro_gl_set(AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_DOUBLEBUFFER
	             | AGL_RENDERMETHOD | AGL_Z_DEPTH | AGL_WINDOWED);

	if (set_gfx_mode(GFX_OPENGL, 640, 480, 0, 0)) {
		allegro_message("Error initializing OpenGL!\n");
		return -1;
	}

	install_keyboard();


	/* Load 2 copies of the datafile */	
	dat = load_datafile("lucidia.dat");

	if (!dat) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to load lucidia.dat\n");
		return -2;
	}

	lucidia_fnt = allegro_gl_convert_allegro_font((FONT*)dat[0].dat,
	                                              AGL_FONT_TYPE_TEXTURED, 16.0);

	if (!lucidia_fnt) {
		unload_datafile(dat);
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to convert font!\n");
		return -3;
	}

	allegro_fnt = allegro_gl_convert_allegro_font(font,
	                                              AGL_FONT_TYPE_TEXTURED, 16.0);

	if (!allegro_fnt) {
		allegro_gl_destroy_font(lucidia_fnt);
		unload_datafile(dat);
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to convert font!\n");
		return -4;
	}

	
	srand(time(NULL));


	for (i = 0; i < NUM_STRINGS; i++) {
		coord[i].z = 0;
		coord[i].c = 0;
	}
	i = 0;

	/* Start nice text demo */

	/* Setup OpenGL like we want */
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);

	glViewport(0, 0, SCREEN_W, SCREEN_H);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glFrustum(-1.0, 1.0, -1.0, 1.0, 1, 60.0);

	/* Set culling mode - not that we have anything to cull */
	glEnable(GL_CULL_FACE);
	glFrontFace(GL_CCW);
			
	glMatrixMode(GL_MODELVIEW);

	do {
		int c;

		/* Update rotation angle of text */	
		glLoadIdentity();
		
		glTranslatef(0, 0, -30);
		glRotatef(-45, 1, 0, 0);
		glRotatef(-30, 0, 1, 0);

		/* Clear the screen and set a nice blender mode */
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);						
		glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);

		/* Print the text wheel */
		for (i = 0; i < NUM_STRINGS; i++) {			
			allegro_gl_printf(lucidia_fnt, coord[i].x, coord[i].y, coord[i].z,
			                  coord[i].c, string);
		}
		/* Update the text wheel's position */
		for (i = 0; i < NUM_STRINGS; i++) {
			int r, g, b;
			float angle2 = angle + i * M_PI * 2 / NUM_STRINGS;
			coord[i].x = 10 * cos(angle2) - 10;
			coord[i].y = 10 * sin(angle2);			
			angle2 = angle2 * 180.0 / M_PI;
#if ((((ALLEGRO_VERSION) << 16) | ((ALLEGRO_SUB_VERSION) << 8) | (ALLEGRO_WIP_VERSION)) == 0x40200)
			/* Work around an Allegro bug that's only in 4.2.0 */
			while (angle2 > 360.0f) angle2 -= 360.0f;
			while (angle2 < 0)      angle2 += 360.0f;
#endif			
			hsv_to_rgb(angle2, 1, 1, &r, &g, &b);
			coord[i].c = makeacol(r, g, b, 255);
		}
		/* Draw "AllegroGL" */
		glLoadIdentity();
		c = MID(0, (int)(255 - chrono / 100), 255);
		allegro_gl_printf(allegro_fnt, -(strlen(STRING0) * 1 / 2.0f) / 2,
		                -3.0f, -chrono / 200.0 + 0, makecol(c, c, c), STRING0);
		c = MID(0, (int)(255 - chrono / 100) + 24, 255);
		allegro_gl_printf(allegro_fnt, -(strlen(STRING1) * 1 / 2.0f) / 2,
		                -3.0f, -chrono / 200.0 + 12, makecol(c, c, c), STRING1);
		c = MID(0, (int)(255 - chrono / 100) + 48, 255);
		allegro_gl_printf(allegro_fnt, -(strlen(STRING2) * 1 / 2.0f) / 2,
		                -3.0f, -chrono / 200.0 + 24, makecol(c, c, c), STRING2);
		c = MID(0, (int)(255 - chrono / 100) + 72, 255);
		allegro_gl_printf(allegro_fnt, -(strlen(STRING3) * 1 / 2.0f) / 2,
		                -3.0f, -chrono / 200.0 + 36, makecol(c, c, c), STRING3);
		c = MID(0, (int)(255 - chrono / 100) + 96, 255);
		allegro_gl_printf(allegro_fnt, -(strlen(STRING4) * 1 / 2.0f) / 2,
		                -3.0f, -chrono / 200.0 + 48, makecol(c, c, c), STRING4);
		c = MID(0, (int)(255 - chrono / 100) + 120, 255);
		allegro_gl_printf(allegro_fnt, -(strlen(URL) * 1 / 2.0f) / 2,
		                -3.0f, -chrono / 200.0 + 60, makecol(c, c, c), URL);

		allegro_gl_flip();

		rest(2);

	} while (!key[KEY_ESC]);

	return 0;
}
コード例 #23
0
ファイル: exfade.c プロジェクト: stefanhendriks/dune2themaker
int main() {

	BITMAP *backbuffer = NULL, *mysha;
	int count = 0;
	int old_time = 0, old_time2 = 0;
	int depth;
	int i;
	int use_alleg = 0;
	
	allegro_init();
	
	install_keyboard();
	install_timer();
	
	set_config_file("examples.cfg");
	depth = get_config_int("examples", "depth", 16);

	set_color_depth(depth);	
	if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
		set_color_depth(16);
			if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
			set_color_depth(15);
			if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
				set_color_depth(32);
				if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
					allegro_message("Unable to set 640x480 screen mode!\n");
					return -1;
				}
			}
		}
	}
	
	mysha = load_bitmap("mysha.pcx", NULL);
	
	if (!mysha) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to load mysha.pcx. Copy it from the allegro examples directory.\n");
		return -2;
	}
	
	backbuffer = create_bitmap(SCREEN_W, SCREEN_H);
	
	if (!backbuffer) {
		destroy_bitmap(mysha);
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Not enough memory to create backbuffer.\n");
		return -3;
	}
	
	LOCK_FUNCTION(the_timer);
	LOCK_VARIABLE(chrono);

	stretch_blit(mysha, backbuffer, 0, 0, mysha->w, mysha->h, 0, 0, SCREEN_W, SCREEN_H);
	
	for (i = 0; i < 4; i++) {
		fade[i].x = (SCREEN_W/2) * (i & 1);
		fade[i].y = (SCREEN_H/2) * (i & 2) >> 1;
		fade[i].fact = rand() & 255;
		fade[i].dir = (rand() & 1) ? 1 : -1;
		fade[i].src = create_sub_bitmap(backbuffer, fade[i].x, fade[i].y, SCREEN_W/2, SCREEN_H/2);
		fade[i].color = makecol((i & 1) * 255, ((i & 2) >> 1) * 255, 0);
	}
		

	install_int(the_timer, 1);
	old_time = chrono;

	while (!key[KEY_ESC]) {
		if (use_alleg) {
			stretch_blit(mysha, backbuffer, 0, 0, mysha->w, mysha->h, 0, 0, SCREEN_W, SCREEN_H);
		}
		textprintf(backbuffer, font, 0, 0, makecol(255, 255, 255), "%s  %.2f fps (%.3f avg)", use_alleg ? "Using Allegro" : "Using FBlend", (chrono - old_time2) == 0 ? 1000.0 : 1000 / ((double)chrono - old_time2), count * 1000.0 / chrono);

		if (use_alleg) {
			drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
			for (i = 0; i < 4; i++) {
				set_trans_blender(0, 0, 0, 255 - fade[i].fact);
				rectfill(fade[i].src, 0, 0, fade[i].src->w - 1, fade[i].src->h - 1, fade[i].color);
			}
			drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
		}
		else {
			for (i = 0; i < 4; i++) {
				fblend_fade_to_color(fade[i].src, screen, fade[i].x, fade[i].y, fade[i].color, fade[i].fact);
			}
		}

		if (key[KEY_SPACE]) {
			use_alleg = !use_alleg;
			key[KEY_SPACE] = 0;
			chrono = 0;
			count = 0;
			old_time = 0;
			old_time2 = 0;
		}
		count++;

		old_time2 = chrono;

		
		/* Draw the buffer */
		if (use_alleg) {
			blit(backbuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		}
		
		for (i = 0; i < 4; i++) {
			fade[i].fact += fade[i].dir;
			if (fade[i].fact >= 255 || fade[i].fact <= 0)
				fade[i].dir = -fade[i].dir;
			fade[i].fact = MID(0, fade[i].fact, 255);
		}
	}
	for (i = 0; i < 4; i++) {
		destroy_bitmap(fade[i].src);
	}
	
	destroy_bitmap(backbuffer);
	destroy_bitmap(mysha);
	
	return 0;
}
コード例 #24
0
ファイル: lathe.c プロジェクト: AntonLanghoff/whitecatlib
int main()
{
    /* Setup Allegro/AllegroGL */

	if (allegro_init())
		return 1;

	if (install_allegro_gl())
		return 1;

    if (install_keyboard() < 0)
    {
        allegro_message("Unable to install keyboard\n");
        return 1;
    }

    if (install_mouse() == -1)
    {
        allegro_message("Unable to install mouse\n");
        return 1;
    }

    if (install_timer() < 0)
    {
        allegro_message("Unable to install timers\n");
        return 1;
    }

    /* lock timer */
    LOCK_VARIABLE(rotation_counter);
    LOCK_FUNCTION(rotation_counter_handler);


    /* set desktop resolution */
    DESKTOP_W = GetSystemMetrics(SM_CXVIRTUALSCREEN);
    DESKTOP_H = GetSystemMetrics(SM_CYVIRTUALSCREEN);

    /* get monitor resolution/count */
    int monitor_count;
    MONITOR *monitors = get_monitors(&monitor_count);


    /* generate point data */
    PLACE places[POINT_COUNT];
    int c;
    for (c = 1; c < POINT_COUNT - 1; c++)
    {
        places[c].x = sin((M_PI * (GLfloat)c) / 10.0f) * 200.0f;
        places[c].y = cos((M_PI * (GLfloat)c) / 10.0f) * 200.0f;
    }
    places[0].x = 0.01;
    places[0].y = 200.0f;
    places[POINT_COUNT - 1].x = 0.01;
    places[POINT_COUNT - 1].y = -200.0f;


    /* setup display */
    allegro_gl_set(AGL_Z_DEPTH, 8);
	allegro_gl_set(AGL_COLOR_DEPTH, 16);
	allegro_gl_set(AGL_SUGGEST, AGL_Z_DEPTH | AGL_COLOR_DEPTH);
    glDepthFunc(GL_LEQUAL);

	if (set_gfx_mode(GFX_OPENGL_WINDOWED_BORDERLESS, DESKTOP_W, DESKTOP_H, 0, 0)) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to set graphic mode\n%s\n", allegro_error);
		return 1;
	}

    /* move window so it covers the desktop */
    position_window(0, 0);


    /* fake information to use if only 1 monitor */
    MONITOR fake = {0, 512, 512, 512};

    /* setup lighting model */
    glShadeModel(GL_FLAT);
    glEnable(GL_LIGHT0);
    glEnable(GL_COLOR_MATERIAL);
    GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    GLfloat ambient[] = { 0.1f, 0.1f, 0.1f };
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);


    int selected = -1; /* the point currently being moved */
    GLfloat rotation[3] = {0, 0, 0}; /* the rotation of the mesh */

    install_int(rotation_counter_handler, 20); /* install the rotation handler */

    /* enter main program loop */
    while(!key[KEY_ESC])
    {
        while (rotation_counter > 0)
        {
            /* rotate the mesh */
            rotation[0] += M_PI / 24.0f;
            rotation[1] += M_PI / 16.0f;
            rotation[2] += M_PI /  8.0f;
            rotation_counter--;
        }


        /* clear the buffers */
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        /* process monitor 0 */
        MONITOR *m = &monitors[0];

        /* adjust mouse so its relative to the monitor */
        int mx = (mouse_x - m->x) - (m->w / 2);
        int my = (mouse_y - m->y) - (m->h / 2);

        /* if the left mouse is pushed, find a close point */
        if (mouse_b & 1)
        {
            if (selected == -1)
            {
                GLfloat distance = 10;
                for (c = 0; c < POINT_COUNT; c++)
                {
                    GLfloat dx = mx - places[c].x;
                    GLfloat dy = my - places[c].y;
                    GLfloat d = sqrt(dx * dx + dy * dy);
                    if (d < distance)
                    {
                        distance = d;
                        selected = c;
                    }
                }
            }
        }
        else
            selected = -1;

        /* move selected point */
        if (selected >= 0)
        {
            places[selected].x = mx;
            places[selected].y = my;
        }

        /* center the viewport on monitor */
        glViewport(m->x, DESKTOP_H - m->h - m->y, m->w, m->h);

        /* setup viewport projection */
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluOrtho2D(-m->w / 2, m->w / 2, m->h / 2, -m->h / 2);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        /* draw points */
        glColor3ub(0, 255, 0);
        glBegin(GL_LINE_STRIP);
        for (c = 0; c < POINT_COUNT; c++)
        {
            glVertex2f(places[c].x, places[c].y);
        }
        glEnd();

        glColor3ub(255, 255, 255);
        for (c = 0; c < POINT_COUNT; c++)
        {
            draw_square(places[c].x, places[c].y, 10);
        }

        /* draw vertical line */
        glBegin(GL_LINE_STRIP);
        glVertex2f(0.0f, -m->h);
        glVertex2f(0.0f, m->h);
        glEnd();


        /* draw the mouse */
        glColor3ub(255, 255, 255);
        draw_square(mx, my, 20);



        /* process viewport 1 */

        /* select second monitor */
        if (monitor_count > 1)
        {
            /* if 2nd monitor exists use it */
            m = &monitors[1];
        }
        else
        {
            /* use fake monitor */
            m = &fake;
        }

        /* adjust mouse so its relative to the monitor*/
        mx = (mouse_x - m->x) - (m->w / 2);
        my = (mouse_y - m->y) - (m->h / 2);

        /* center the viewport on the monitor*/
        glViewport(m->x, DESKTOP_H - m->h - m->y, m->w, m->h);

        /* setup viewport projection */
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45.0f, (float)m->w / (float)m->h, 0.1f, 2000.0f);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        /* turn on lighting and depth testing */
        glEnable(GL_LIGHTING);
        glEnable(GL_DEPTH_TEST);

        /* move mesh so its visible */
        glTranslatef(0.0f, 0.0f, -1000.0f);
        /* rotate mesh */
        glRotatef(rotation[0], 1.0f, 0.0f, 0.0f);
        glRotatef(rotation[1], 0.0f, 1.0f, 0.0f);
        glRotatef(rotation[2], 0.0f, 0.0f, 1.0f);

        GLfloat p1[3] = {0, 0, 0};
        GLfloat p2[3] = {0, 0, 0};
        GLfloat p3[3] = {0, 0, 0};
        GLfloat p4[3] = {0, 0, 0};
        GLfloat vec1[3];
        GLfloat vec2[3];
        GLfloat normal[3];


        /* draw mesh to screen */
        glColor3ub(0, 255, 0);
        for (c = 0; c < (POINT_COUNT - 1); c++)
        {

            GLfloat a1 = 0;
            GLfloat a2 = M_PI / 16.0f;
            GLfloat d1 = places[c].x;
            GLfloat d2 = places[c + 1].x;

            p1[0] = sin(a1) * d1;  p1[1] = places[c].y;     p1[2] = cos(a1) * d1;
            p2[0] = sin(a2) * d1;  p2[1] = places[c].y;     p2[2] = cos(a2) * d1;
            p3[0] = sin(a2) * d2;  p3[1] = places[c + 1].y; p3[2] = cos(a2) * d2;
            p4[0] = sin(a1) * d2;  p4[1] = places[c + 1].y; p4[2] = cos(a1) * d2;

            buildVector(vec1, p1, p2);
            buildVector(vec2, p1, p4);
            cross_product_f(vec2[0], vec2[1], vec2[2], vec1[0], vec1[1], vec1[2], &normal[0], &normal[1], &normal[2]);
            normalize_vector_f(&normal[0], &normal[1], &normal[2]);


            glBegin(GL_QUAD_STRIP);
            glNormal3fv(normal);
            glVertex3fv(p1);
            glVertex3fv(p4);

            int s = 0;
            for (s = 1; s < 32; s++)
            {
                a2 = (M_PI * (GLfloat)(s + 1)) / 16.0f;
                d1 = places[c].x;
                d2 = places[c + 1].x;

                copyPoint(p1, p2);
                copyPoint(p4, p3);
                p2[0] = sin(a2) * d1;  p2[1] = places[c].y;     p2[2] = cos(a2) * d1;
                p3[0] = sin(a2) * d2;  p3[1] = places[c + 1].y; p3[2] = cos(a2) * d2;

                buildVector(vec1, p1, p2);
                buildVector(vec2, p1, p4);
                cross_product_f(vec2[0], vec2[1], vec2[2], vec1[0], vec1[1], vec1[2], &normal[0], &normal[1], &normal[2]);
                normalize_vector_f(&normal[0], &normal[1], &normal[2]);

                glNormal3fv(normal);
                glVertex3fv(p2);
                glVertex3fv(p3);
            }
            glEnd();
        }

        /* turn off lighting and depth testing */
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_LIGHTING);

        /* if not using the fake monitor */
        if (m != &fake)
        {

            /* setup viewport projection */
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            gluOrtho2D(-m->w / 2, m->w / 2, m->h / 2, -m->h / 2);
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();

            /* draw the mouse */
            glColor3ub(255, 255, 255);
            draw_square(mx, my, 20);
        }

        /* flip the contents to the screen */
        allegro_gl_flip();
    }


    free(monitors);

    return 0;
}
コード例 #25
0
ファイル: CAMARA1.C プロジェクト: alejandro-du/legacy
int main(void)
{
  BITMAP *textura, *back_buffer;
  int x, y, c; // para rellenar la textura
  int tecla;
  int nPol;
  int i;
  char angulo_x = 0, angulo_y = 0, angulo_z = 0;
  POLIGONO3D cara[6]; // un cubo
  PUNTO3D ver_t[4]; // v‚rtices transformados para un pol¡gono
  V3D_f ver_p[4]; // v‚rtices proyectados (2d) para un pol¡gono
  PUNTO3D cam_p; // posici¢n de la camara
  VECTOR cam_f; // vector frente de la camara
  VECTOR cam_a; // vector arriba de la camara
  MATRIX_f matriz;

  printf("\nEjemplo de c mara en un solo plano.");
  printf("\n\nControles:");
  printf("\n  Flechas: mover la camara.");
  printf("\n\n\nPresione una tecla para comenzar...\n");
  getch();

  // inicializar allegro y otras cosas
  allegro_init();
  set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
  install_keyboard();
  install_timer();
  install_int(&cont_frames, 1000);
  LOCK_VARIABLE(nFrames);
  LOCK_VARIABLE(nFramesPorSegundo);
  LOCK_FUNCTION(cont_frames);

  back_buffer = create_bitmap(SCREEN_W, SCREEN_H);
  clear(back_buffer);

  // crear una textura
  textura = create_bitmap(TEX_W, TEX_H);
  clear(textura);

  c = 1; // color
  for(x = 0; x < TEX_W; x++) {
    for(y = 0; y < TEX_H; y++) {
      putpixel(textura, x, y, c);
      if(c++ > 64)
        c = 1;
    }
  }

  line(textura, 0, 0, TEX_W, TEX_H, 4);
  line(textura, TEX_W, 0, 0, TEX_H, 4);

  line(textura, 0, 0, 0, TEX_H, 4);
  line(textura, 0, 0, TEX_W, 0, 4);
  line(textura, 0, TEX_H - 1, TEX_W - 1, TEX_H - 1, 4);
  line(textura, TEX_W - 1, TEX_H - 1, TEX_W - 1, 0, 4);

  textprintf(textura, font, 1, 1, 13, "Textura");

  // inicializar las coordenadas 3d del cubo

  cara[0].ver[0].x = -2;
  cara[0].ver[0].y = -2;
  cara[0].ver[0].z = -2;
  cara[0].ver[1].x = 2;
  cara[0].ver[1].y = -2;
  cara[0].ver[1].z = -2;
  cara[0].ver[2].x = 2;
  cara[0].ver[2].y = 2;
  cara[0].ver[2].z = -2;
  cara[0].ver[3].x = -2;
  cara[0].ver[3].y = 2;
  cara[0].ver[3].z = -2;

  cara[1].ver[0].x = 2;
  cara[1].ver[0].y = -2;
  cara[1].ver[0].z = 2;
  cara[1].ver[1].x = -2;
  cara[1].ver[1].y = -2;
  cara[1].ver[1].z = 2;
  cara[1].ver[2].x = -2;
  cara[1].ver[2].y = 2;
  cara[1].ver[2].z = 2;
  cara[1].ver[3].x = 2;
  cara[1].ver[3].y = 2;
  cara[1].ver[3].z = 2;

  cara[2].ver[0].x = -2;
  cara[2].ver[0].y = -2;
  cara[2].ver[0].z = 2;
  cara[2].ver[1].x = -2;
  cara[2].ver[1].y = -2;
  cara[2].ver[1].z = -2;
  cara[2].ver[2].x = -2;
  cara[2].ver[2].y = 2;
  cara[2].ver[2].z = -2;
  cara[2].ver[3].x = -2;
  cara[2].ver[3].y = 2;
  cara[2].ver[3].z = 2;

  cara[3].ver[0].x = 2;
  cara[3].ver[0].y = -2;
  cara[3].ver[0].z = -2;
  cara[3].ver[1].x = 2;
  cara[3].ver[1].y = -2;
  cara[3].ver[1].z = 2;
  cara[3].ver[2].x = 2;
  cara[3].ver[2].y = 2;
  cara[3].ver[2].z = 2;
  cara[3].ver[3].x = 2;
  cara[3].ver[3].y = 2;
  cara[3].ver[3].z = -2;

  cara[4].ver[0].x = -2;
  cara[4].ver[0].y = -2;
  cara[4].ver[0].z = 2;
  cara[4].ver[1].x = 2;
  cara[4].ver[1].y = -2;
  cara[4].ver[1].z = 2;
  cara[4].ver[2].x = 2;
  cara[4].ver[2].y = -2;
  cara[4].ver[2].z = -2;
  cara[4].ver[3].x = -2;
  cara[4].ver[3].y = -2;
  cara[4].ver[3].z = -2;

  cara[5].ver[0].x = -2;
  cara[5].ver[0].y = 2;
  cara[5].ver[0].z = -2;
  cara[5].ver[1].x = 2;
  cara[5].ver[1].y = 2;
  cara[5].ver[1].z = -2;
  cara[5].ver[2].x = 2;
  cara[5].ver[2].y = 2;
  cara[5].ver[2].z = 2;
  cara[5].ver[3].x = -2;
  cara[5].ver[3].y = 2;
  cara[5].ver[3].z = 2;

  // inicializar las coordenadas de la textura
  ver_p[0].u = 0;
  ver_p[0].v = 0;
  ver_p[1].u = TEX_W;
  ver_p[1].v = 0;
  ver_p[2].u = TEX_W;
  ver_p[2].v = TEX_H;
  ver_p[3].u = 0;
  ver_p[3].v = TEX_H;

  // inicializar c mara
  cam_p.x = 0;
  cam_p.y = 0;
  cam_p.z = -35;

  cam_f.x = 0;
  cam_f.y = 0;
  cam_f.z = 1;

  cam_a.x = 0;
  cam_a.y = -1;
  cam_a.z = 0;

  set_projection_viewport(0, 0, SCREEN_W, SCREEN_H);

  do {

    // teclado
    if(key[KEY_RIGHT]) {
      get_rotation_matrix_f(&matriz,
                            0,
                            -1,
                            0);

      apply_matrix_f(&matriz,
                     cam_f.x,
                     cam_f.y,
                     cam_f.z,
                     &cam_f.x,
                     &cam_f.y,
                     &cam_f.z);

    }
    if(key[KEY_LEFT]) {
      get_rotation_matrix_f(&matriz,
                            0,
                            1,
                            0);

      apply_matrix_f(&matriz,
                     cam_f.x,
                     cam_f.y,
                     cam_f.z,
                     &cam_f.x,
                     &cam_f.y,
                     &cam_f.z);

    }
    if(key[KEY_UP]) {
       cam_p.x += cam_f.x;
       cam_p.y += cam_f.y;
       cam_p.z += cam_f.z;
    }
    if(key[KEY_DOWN]) {
       cam_p.x -= cam_f.x;
       cam_p.y -= cam_f.y;
       cam_p.z -= cam_f.z;
    }

    get_camera_matrix_f(&matriz,
                        cam_p.x,
                        cam_p.y,
                        cam_p.z,
                        cam_f.x,
                        cam_f.y,
                        cam_f.z,
                        cam_a.x,
                        cam_a.y,
                        cam_a.z,
                        32,
                        1);


    for(nPol = 0; nPol < 6; nPol++) { // cada pol¡gono

      for(i = 0; i < 4; i++) { // cada v‚rtice del pol¡gono

        // transformaci¢n
        apply_matrix_f(&matriz,
                       cara[nPol].ver[i].x,
                       cara[nPol].ver[i].y,
                       cara[nPol].ver[i].z,
                       &ver_t[i].x,
                       &ver_t[i].y,
                       &ver_t[i].z);

        // proyecci¢n
        persp_project_f(ver_t[i].x,
                        ver_t[i].y,
                        ver_t[i].z,
                        &ver_p[i].x,
                        &ver_p[i].y);

        ver_p[i].z = ver_t[i].z; // requerido para renderizar la textura
      }

      // backface culling
      if(polygon_z_normal_f(&ver_p[0], &ver_p[1], &ver_p[2]) > 0) {
        quad3d_f(back_buffer,
                 POLYTYPE_PTEX,
                 textura,
                 &ver_p[0],
                 &ver_p[1],
                 &ver_p[2],
                 &ver_p[3]);
      }
    }

    textprintf(back_buffer, font, 0, 190, 2, "%d FPS", nFramesPorSegundo);
    blit(back_buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
    nFrames++;
    clear(back_buffer);

  } while(!key[KEY_ESC]);

  allegro_exit();
  return 0;
}
コード例 #26
0
ファイル: skeletal.c プロジェクト: omer4d/SuperOldCode
int main()
{
 int exit_flag = 0, i;
 MAT16F tmat;
 VEC3F pos = vec3f(0.0, 0.0, 0.5), ang = vec3f(0.0, 0.0, 0.0);
 MD2_MODEL mdl;
 VERTEX *model_verts;
 TRI *model_tris;

 if(load_md2("data/babe.md2", &mdl))
  {
   allegro_message("Error: I need the MD2 model, stupid!");
   exit(1);
  }

 convert_md2_to_base(&model_verts, &model_tris, &mdl, 0.02);

 init();
 
 LOCK_VARIABLE(fps);
 LOCK_VARIABLE(frame_count);
 LOCK_FUNCTION(update_fps);
 install_int(update_fps, 1000);

 float frame = 0.0;
 int flag = 0, flag2 = 0;
 int anim_flag = 0, point_flag = 0;

 while(!exit_flag)
  {
   set_texture_mapping_mode(0);

   if(key[KEY_ESC]) { exit_flag = 1; }
   if(key[KEY_LEFT]) { pos.x -= 0.01; }
   if(key[KEY_RIGHT]) { pos.x += 0.01; }
   if(key[KEY_UP]) { pos.z += 0.02; }
   if(key[KEY_DOWN]) { pos.z -= 0.02; }
   if(key[KEY_SPACE]) { frame += 0.1; }
   if(key[KEY_P]) { anim_flag = anim_flag ? 0 : 1; key[KEY_P] = 0; }
   if(key[KEY_O]) { point_flag = point_flag ? 0 : 1; key[KEY_O] = 0; }

   VEC2F mp, cp;
   cp = vec2f(mouse_x, mouse_y);

   if(mouse_b == 1)
    {
     if(flag == 0)
       mp = cp;
     flag = 1;

     ang.y -= ((cp.x - mp.x) * 0.0002);
    }

   else
    flag = 0;

   if(mouse_b == 2)
    {
     if(flag2 == 0)
       mp = cp;
     flag2 = 1;

     pos.z -= ((cp.y - mp.y) * 0.0002);
    }

   else
    flag2 = 0;

   ang.x = M_PI * 1.5;

   convert_md2_frame_to_base(model_verts, &mdl, frame, 0.02);
   
   if(anim_flag)
   frame += 0.1 * (60.0 / (fps + 1.0));

   reset_mat16f(tmat);
   rotate_mat16f(tmat, ang.x, ang.y, ang.z);
   translate_mat16f(tmat, pos.x, pos.y, pos.z);

   for(i = 0; i < mdl.header.num_vertices; i++)
    {
     transform_vec3f(&model_verts[i].world, model_verts[i].local, tmat);
     project_vertex(&model_verts[i]);
    }

   clear_bitmap(buffer);
   clear_to_color(zbuffer, ZBUFFER_PRECISION);

   for(i = 0; i < mdl.header.num_tris; i++)
    {
     update_tri_normal(&model_tris[i], model_verts);
     frustum_cull(&model_tris[i], model_verts, -0.95, 20.0);
     cull_backface(&model_tris[i], model_verts);
    }

   for(i = 0; i < mdl.header.num_tris; i++)
    if(model_tris[i].vis)
     my_triangle(buffer, model_verts, model_tris[i]);

   if(point_flag)
   for(i = 0; i < mdl.header.num_tris; i++)
    if(model_tris[i].vis)
     {
      int x1 = model_verts[model_tris[i].a].sx, y1 = model_verts[model_tris[i].a].sy,
          x2 = model_verts[model_tris[i].b].sx, y2 = model_verts[model_tris[i].b].sy,
          x3 = model_verts[model_tris[i].c].sx, y3 = model_verts[model_tris[i].c].sy;

      float z, z1 = model_verts[model_tris[i].a].screen.z,
               z2 = model_verts[model_tris[i].b].screen.z,
               z3 = model_verts[model_tris[i].c].screen.z;

      if(on_bitmap(x1, y1, SCREEN_W, SCREEN_H))
       {
        z = (float)RI_PIXEL_Z(x1, y1) / (float)(ZBUFFER_PRECISION);
        if(z1 < z + 0.001) circlefill(buffer, x1, y1, 1, makecol(255, 0, 0));
       }

      if(on_bitmap(x2, y2, SCREEN_W, SCREEN_H))
       {
        z = (float)RI_PIXEL_Z(x2, y2) / (float)(ZBUFFER_PRECISION);
        if(z2 < z + 0.001) circlefill(buffer, x2, y2, 1, makecol(255, 0, 0));
       }

      if(on_bitmap(x3, y3, SCREEN_W, SCREEN_H))
       {
        z = (float)RI_PIXEL_Z(x3, y3) / (float)(ZBUFFER_PRECISION);
        if(z3 < z + 0.001) circlefill(buffer, x3, y3, 1, makecol(255, 0, 0));
       }
     }

   textprintf_ex(buffer, font, 10, 10, makecol(255, 255, 255), 0, "FPS: %d", fps);
   blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
   frame_count++;
  }

 free_md2(&mdl);
 free(model_tris);
 free(model_verts);
 destroy_bitmap(texture);
 destroy_bitmap(zbuffer);
 destroy_bitmap(buffer);
 deinit_renderer();

 return 0;
}
コード例 #27
0
ファイル: main.cpp プロジェクト: stefanhendriks/cs2d-sdl
/***
  Function : install()
  Returns  : TRUE on succes, FALSE on failure
  Purpose  : Will install game variables, sets up the entire game.
***/
bool install()
{
    // Each time we run the game, we clear out the logbook
    FILE *fp;
    fp = fopen("log.txt", "wt");

    if (fp)
    {
        fprintf(fp, "Counter-Strike 2D Logbook\n");
        fprintf(fp, "-------------------------\n\n"); // print head of logbook
        fclose(fp);
    }

    logbook("--------------");
    logbook("Initialization");
    logbook("--------------");

    // init game
    map.init();
    game.init();
    steam.init();

    logbook("Creating entity types.");
    game.install_entities();

    // Logbook notification
    logbook("\n-------");
    logbook("Allegro");
    logbook("-------");


    // ALLEGRO - INIT
    if (allegro_init() != 0)
        return false;

    logbook(allegro_id);
    yield_timeslice();
    logbook("yield_timeslice()");

    int r = install_timer();
    if (r > -1) logbook("install_timer()");
    else
    {
        logbook("FAILED");
        return false;
    }

    alfont_init();
    logbook("alfont_init()");
    install_keyboard();
    logbook("install_keyboard()");
    install_mouse();
    logbook("install_mouse()");

    logbook("setting up timer functions / locking functions & memory");
    /* set up the interrupt routines... */
    LOCK_VARIABLE(RUNNING_TIMER_tenth);
    LOCK_VARIABLE(RUNNING_TIMER_fps);
    LOCK_FUNCTION(timer_tenth);
    LOCK_FUNCTION(fps_proc);

    install_int(timer_tenth, 10);
    install_int(fps_proc, 1000);

    logbook("Timers installed");

    frame_count = fps = 0;


    // set window title
    char title[80];
    sprintf(title, "Counter-Strike 2D");

    // Set window title
    set_window_title(title);
    char window_title[256];
    sprintf(window_title, "Window title set: [%s]", title);
    logbook(window_title);

    set_color_depth(16);      // run in 16 bit mode
    if (game.windowed)
    {
        int r = set_gfx_mode(GFX_AUTODETECT_WINDOWED, game.screen_x, game.screen_y, game.screen_x, game.screen_y);
        if (r > -1)
        {
            // Succes
        }
        else
        {
            // GFX_DIRECTX_ACCEL / GFX_AUTODETECT
            r = set_gfx_mode(GFX_DIRECTX_ACCEL, game.screen_x, game.screen_y, game.screen_x, game.screen_y);
            if (r > -1)
            {
                game.windowed = false;
                logbook("Could not enter windowed-mode; settings.d3 adjusted");
            }
            else
            {
                logbook("ERROR - !");
                return false;
            }
        }
    }
    else
    {
        int r = set_gfx_mode(GFX_AUTODETECT, game.screen_x, game.screen_y, game.screen_x, game.screen_y);

        // succes
        if (r > -1)
        {

        }
        else
        {
            logbook("ERROR - !!");
            return false;
        }

    }


    text_mode(0);

    logbook("Loading font data");
    // loading font

    game_font = alfont_load_font("gfx\\font\\tahoma.ttf");

    if (game_font != NULL)
    {
        alfont_set_font_size(game_font, 20); // set size
    }
    else
        allegro_message("Error loading tahoma.ttf!");

    // CS Font
    cs_font = alfont_load_font("gfx\\font\\cs.ttf");

    if (cs_font != NULL)
    {
        alfont_set_font_size(cs_font, 20); // set size
    }
    else
        allegro_message("Error loading cs.ttf");

    alfont_text_mode(-1);

    if (set_display_switch_mode(SWITCH_BACKGROUND) < 0)
    {
        set_display_switch_mode(SWITCH_PAUSE);
        logbook("Display 'switch and pause' mode set");
    }
    else
        logbook("Display 'switch to background' mode set");

    // sound
    logbook("Initializing sound");
    int s = install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL);

    /***
     Bitmap Creation
     ***/

    bmp_screen = create_bitmap(game.screen_x, game.screen_y);

    if (bmp_screen == NULL)
    {
        logbook("ERROR: Could not create bitmap: bmp_screen");
        return false;
    }
    else
        logbook("Bitmap created: bmp_screen");

    bmp_collide = create_bitmap(game.screen_x, game.screen_y);

    if (bmp_collide == NULL)
    {
        logbook("ERROR: Could not create bitmap: bmp_collide");
        return false;
    }
    else
        logbook("Bitmap created: bmp_collide");

    /*** End of Bitmap Creation ***/

    // load datafiles
    graphics = load_datafile("graphics.dat");
    if (graphics == NULL)
    {
        logbook("ERROR: Could not load datafile: graphics.dat");
        return false;
    }
    else
        logbook("Datafile loaded: graphics.dat");

    // Shadows
    shadows = load_datafile("shadows.dat");
    if (shadows == NULL)
    {
        logbook("ERROR: Could not load datafile: shadows.dat");
        return false;
    }
    else
        logbook("Datafile loaded: shadows.dat");

    // HUD
    hud = load_datafile("hud.dat");
    if (hud == NULL)
    {
        logbook("ERROR: Could not load datafile: hud.dat");
        return false;
    }
    else
        logbook("Datafile loaded: hud.dat");

    //set_color_conversion(COLORCONV_NONE);
    set_color_conversion(COLORCONV_MOST);
    logbook("Color conversion method set");

    // setup mouse speed
    set_mouse_speed(2,2);

    logbook("Mouse speed set");

    logbook("");
    logbook("----");
    logbook("GAME ");
    logbook("----");

    game.LOAD_TexturesFromDataFile("data//de_aztec.dat");
//  DATA_Init();

    // randomize timer
    srand( (unsigned)time( NULL ) );

    //srand(time(NULL));

    // normal sounds are loud, the music is lower (its background music, so it should not be disturbing)
    set_volume(255, 200);

    set_trans_blender(128, 128, 128, 128);

    logbook("");
    logbook("--------------");
    logbook("BATTLE CONTROL");
    logbook("--------------");
    logbook("\n3...2...1... GO!\n");
    return true;
}
コード例 #28
0
ファイル: EX_q3_map.c プロジェクト: omer4d/SuperOldCode
int main()
{
 int exit = 0, i, vnum, pnum;
 VEC3F pos = vec3f(0.0, 0.0, 0.3), ang = ZERO_VEC3F;
 MAT16F tmat;
 VERTEX *vertex;
 POLY3D *poly;

 init();

 load_map("quake_map2.txt", &vertex, &poly, &vnum, &pnum, 0.2);

 LOCK_VARIABLE(fps);
 LOCK_VARIABLE(frame_count);
 LOCK_FUNCTION(update_fps);
 install_int(update_fps, 1000);

 VEC3F cam_pos = vec3f(0.0, 3.0, 0.0), cam_dir, cam_dir_normal, cam_ang = vec3f(0.0, 0.0, 0.0);

 while(!exit)
  {
   int mx, my;
   get_mouse_mickeys(&mx, &my);
   position_mouse(SCREEN_W / 2, SCREEN_H / 2);

   cam_ang.x += my * 0.001;
   cam_ang.y -= mx * 0.001;
   cam_dir.x = CAM_SPEED * cos(0.5 * M_PI + cam_ang.y);
   cam_dir.y = CAM_SPEED * cos(0.5 * M_PI + cam_ang.x);
   cam_dir.z = CAM_SPEED * sin(0.5 * M_PI + cam_ang.y);
   cam_dir_normal = vec3f(-cam_dir.z, 0.0, cam_dir.x);

   if(key[KEY_ESC]) { exit = 1; }
   if(key[KEY_W]) { cam_pos = VEC3F_SUM(cam_pos, cam_dir); }
   if(key[KEY_S]) { cam_pos = VEC3F_DIFF(cam_pos, cam_dir); }
   if(key[KEY_A]) { cam_pos = VEC3F_SUM(cam_pos, cam_dir_normal); }
   if(key[KEY_D]) { cam_pos = VEC3F_DIFF(cam_pos, cam_dir_normal); }

   set_fov(90.0);
   if(mouse_b > 1)
    set_fov(30.0);

   reset_mat16f(tmat);
   translate_mat16f(tmat, -cam_pos.x, -cam_pos.y, -cam_pos.z);
   rotate_z_mat16f(tmat, 0.0);
   rotate_y_mat16f(tmat, -cam_ang.y);
   rotate_x_mat16f(tmat, -cam_ang.x);

   for(i = 0; i < vnum; i++)
    {
     transform_vec3f(&vertex[i].trans, vertex[i].object, tmat);
     project_vertex(&vertex[i]);
    }

   clear_to_color(buffer, 0);
   clear_to_color(BASE_INT_z_buffer, BASE_INT_z_buffer_precision);

   for(i = 0; i < pnum; i++)
    {
     update_poly3d_normal(&poly[i], vertex);
     V0 = vertex[poly[i].vind[0]].trans;
     global_n = USCALE_VEC3F(NORMALIZED_VEC3F(poly[i].normal), -1.0);
     VEC3F N = global_n;
     DIST = -VEC3F_DOT_PRODUCT(V0, N);

     get_axes(vertex[poly[i].vind[0]].trans,
              vertex[poly[i].vind[1]].trans,
              vertex[poly[i].vind[2]].trans,
              to_vec3f(poly[i].texcoord[0]),
              to_vec3f(poly[i].texcoord[1]),
              to_vec3f(poly[i].texcoord[2]), &A, &B, &C);
     T0 = to_vec3f(poly[i].texcoord[0]);

     if(cull_backface(&poly[i], vertex))
     render_poly3d(&poly[i], vertex);
    }

   textprintf_ex(buffer, font, 10, 10, makecol(255, 255, 255), 0, "FPS: %d", fps);
   blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
   frame_count++;
  }

 for(i = 0; i < pnum; i++)
  destroy_poly3d(&poly[i]);
 free(vertex);

 deinit_engine();
 return 0;
}
コード例 #29
0
ファイル: main.c プロジェクト: evktalo/angry_moth
/*
Self-explanatory.
*/
void init_at_startup(void)
{

   LOCK_FUNCTION (framecount);
   LOCK_FUNCTION (tickover);
   LOCK_VARIABLE (ticked);
   LOCK_VARIABLE (frames_per_second);
   LOCK_VARIABLE (framecounter);
   LOCK_VARIABLE (turns_per_second);
   LOCK_VARIABLE (turncounter);

   install_int (framecount, 1000);
   install_int (tickover, 20);

   set_color_depth(8);

   int randseed = get_config_int("Misc", "Seed", 0);
   srand(randseed);

   options.windowed = get_config_int("Misc", "Windowed", 0);


 int windowed;
 switch(options.windowed)
 {
    default:
     case 1: windowed = GFX_AUTODETECT_WINDOWED; break;
     case 0: windowed = GFX_AUTODETECT_FULLSCREEN; break;
 }

//   windowed  = GFX_AUTODETECT_WINDOWED;
//   windowed = GFX_AUTODETECT_FULLSCREEN;

//   if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0)
//   if (set_gfx_mode(windowed, 640, 480, 0, 0) != 0)
   if (set_gfx_mode(windowed, 800, 600, 0, 0) != 0)
   {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Unable to set 800x600 256 colour display mode. Sorry!\n%s\n", allegro_error);
      exit(1);
   }

 init_trig();

 prepare_display();
 init_sound();
/*
 PP.ckey [CKEY_UP] = KEY_UP;
 PP.ckey [CKEY_DOWN] = KEY_DOWN;
 PP.ckey [CKEY_LEFT] = KEY_LEFT;
 PP.ckey [CKEY_RIGHT] = KEY_RIGHT;
 PP.ckey [CKEY_FIRE1] = KEY_Z;
 PP.ckey [CKEY_FIRE2] = KEY_X;
 PP.ckey [CKEY_FIRE3] = KEY_C;
*/
 int p = 0;

 init_joystick();

 player[0].control = get_config_int("misc", "player1_control", CONTROL_KEY_A);
 player[1].control = get_config_int("misc", "player2_control", CONTROL_KEY_B);

// if a particular joystick isn't available, default to keyboard controls.
//  note that this doesn't set the config values
 for (p = 0; p < 2; p ++)
 {
  if (options.joystick_available [0] == 0
   && PP.control == CONTROL_JOY_A)
   {
    PP.control = CONTROL_KEY_A;
    if (PP.control == CONTROL_KEY_A)
     PP.control = CONTROL_KEY_B;
   }
  if (options.joystick_available [1] == 0
   && PP.control == CONTROL_JOY_B)
   {
    PP.control = CONTROL_KEY_A;
    if (PP.control == CONTROL_KEY_A)
     PP.control = CONTROL_KEY_B;
   }
 }

 options.ckey [0] [CKEY_UP] = get_config_int("Misc", "key1_up", KEY_8_PAD);
 options.ckey [0] [CKEY_DOWN] = get_config_int("Misc", "key1_down", KEY_2_PAD);
 options.ckey [0] [CKEY_LEFT] = get_config_int("Misc", "key1_left", KEY_4_PAD);
 options.ckey [0] [CKEY_RIGHT] = get_config_int("Misc", "key1_right", KEY_6_PAD);
 options.ckey [0] [CKEY_LEFT2] = get_config_int("Misc", "key1_left2", KEY_1_PAD);
 options.ckey [0] [CKEY_RIGHT2] = get_config_int("Misc", "key1_right2", KEY_3_PAD);
 options.ckey [0] [CKEY_FIRE1] = get_config_int("Misc", "key1_fire1", KEY_Z);
 options.ckey [0] [CKEY_FIRE2] = get_config_int("Misc", "key1_fire2", KEY_X);
 options.ckey [0] [CKEY_FIRE3] = get_config_int("Misc", "key1_fire3", KEY_C);
 options.ckey [0] [CKEY_FIRE4] = get_config_int("Misc", "key1_fire4", KEY_V);
 options.ckey [0] [CKEY_COMMAND] = get_config_int("Misc", "key1_command", KEY_A);

 options.ckey [1] [CKEY_UP] = get_config_int("Misc", "key2_up", KEY_UP);
 options.ckey [1] [CKEY_DOWN] = get_config_int("Misc", "key2_down", KEY_DOWN);
 options.ckey [1] [CKEY_LEFT] = get_config_int("Misc", "key2_left", KEY_LEFT);
 options.ckey [1] [CKEY_RIGHT] = get_config_int("Misc", "key2_right", KEY_RIGHT);
 options.ckey [1] [CKEY_LEFT2] = get_config_int("Misc", "key2_left2", KEY_J);
 options.ckey [1] [CKEY_RIGHT2] = get_config_int("Misc", "key2_right2", KEY_K);
 options.ckey [1] [CKEY_FIRE1] = get_config_int("Misc", "key2_fire1", KEY_T);
 options.ckey [1] [CKEY_FIRE2] = get_config_int("Misc", "key2_fire2", KEY_Y);
 options.ckey [1] [CKEY_FIRE3] = get_config_int("Misc", "key2_fire3", KEY_U);
 options.ckey [1] [CKEY_FIRE4] = get_config_int("Misc", "key2_fire4", KEY_I);
 options.ckey [1] [CKEY_COMMAND] = get_config_int("Misc", "key2_command", KEY_O);


/*
 PP.ckey [CKEY_UP] = get_config_int("Misc", "key_up", KEY_UP);
 PP.ckey [CKEY_DOWN] = get_config_int("Misc", "key_down", KEY_DOWN);
 PP.ckey [CKEY_LEFT] = get_config_int("Misc", "key_left", KEY_LEFT);
 PP.ckey [CKEY_RIGHT] = get_config_int("Misc", "key_right", KEY_RIGHT);
 PP.ckey [CKEY_FIRE1] = get_config_int("Misc", "key_fire1", KEY_Z);
 PP.ckey [CKEY_FIRE2] = get_config_int("Misc", "key_fire2", KEY_X);
 PP.ckey [CKEY_FIRE3] = get_config_int("Misc", "key_fire3", KEY_C);
 PP.ckey [CKEY_FIRE4] = get_config_int("Misc", "key_fire4", KEY_V);
*/
/*
 player[1].ckey [CKEY_UP] = get_config_int("MiscP2", "key_up", KEY_UP);
 player[1].ckey [CKEY_DOWN] = get_config_int("MiscP2", "key_down", KEY_DOWN);
 player[1].ckey [CKEY_LEFT] = get_config_int("MiscP2", "key_left", KEY_LEFT);
 player[1].ckey [CKEY_RIGHT] = get_config_int("MiscP2", "key_right", KEY_RIGHT);
 player[1].ckey [CKEY_LEFT2] = get_config_int("MiscP2", "key_left2", KEY_K);
 player[1].ckey [CKEY_RIGHT2] = get_config_int("MiscP2", "key_right2", KEY_L);
 player[1].ckey [CKEY_FIRE1] = get_config_int("MiscP2", "key_fire1", KEY_0_PAD);
 player[1].ckey [CKEY_FIRE2] = get_config_int("MiscP2", "key_fire2", KEY_P);
 player[1].ckey [CKEY_FIRE3] = get_config_int("MiscP2", "key_fire3", KEY_O);
 player[1].ckey [CKEY_FIRE4] = get_config_int("MiscP2", "key_fire4", KEY_I);

 options.joy_stick = get_config_int("Misc", "joy_stick", 0);

 options.joy_sensitivity = get_config_int("Misc", "joy_sensitivity", 70);
 options.init_joystick = get_config_int("Misc", "joy_init", 1);*/

// options.joystick = 0;
// options.key_or_joy = 0; // don't put in initfile!

 options.sfx_volume = get_config_int("Misc", "sfx_volume", 70);
 options.ambience_volume = get_config_int("Misc", "ambience_volume", 100);
 options.run_vsync = get_config_int("Misc", "run_vsync", 0);
 options.fix_camera_angle = get_config_int("Misc", "fix_camera_angle", 0);
 options.joystick_dual = get_config_int("Misc", "joystick_dual", 1);

// set_config_int("Misc", "Tourist", 3);
// set_config_int("Misc", "joy_stick", 0);

// if (options.init_joystick)
// if (options.joystick == 1) // set in init_joystick
 {
  options.joy_button [0] [0] = get_config_int("Misc", "joy1_button_1", 0);
  if (options.joy_button [0] [0] > joy[0].num_buttons)
   options.joy_button [0] [0] = joy[0].num_buttons - 1;
  options.joy_button [0] [1] = get_config_int("Misc", "joy1_button_2", 1);
  if (options.joy_button [0] [1] > joy[0].num_buttons)
   options.joy_button [0] [1] = joy[0].num_buttons - 1;
  options.joy_button [0] [2] = get_config_int("Misc", "joy1_button_3", 2);
  if (options.joy_button [0] [2] > joy[0].num_buttons)
   options.joy_button [0] [2] = joy[0].num_buttons - 1;
  options.joy_button [0] [3] = get_config_int("Misc", "joy1_button_4", 4);
  if (options.joy_button [0] [3] > joy[0].num_buttons)
   options.joy_button [0] [3] = joy[0].num_buttons - 1;
  options.joy_button [0] [4] = get_config_int("Misc", "joy1_button_5", 5);
  if (options.joy_button [0] [4] > joy[0].num_buttons)
   options.joy_button [0] [4] = joy[0].num_buttons - 1;
  options.joy_button [0] [5] = get_config_int("Misc", "joy1_button_6", 6);
  if (options.joy_button [0] [5] > joy[0].num_buttons)
   options.joy_button [0] [5] = joy[0].num_buttons - 1;

  options.joy_button [1] [0] = get_config_int("Misc", "joy2_button_1", 0);
  if (options.joy_button [1] [0] > joy[0].num_buttons)
   options.joy_button [1] [0] = joy[0].num_buttons - 1;
  options.joy_button [1] [1] = get_config_int("Misc", "joy2_button_2", 1);
  if (options.joy_button [1] [1] > joy[0].num_buttons)
   options.joy_button [1] [1] = joy[0].num_buttons - 1;
  options.joy_button [1] [2] = get_config_int("Misc", "joy2_button_3", 2);
  if (options.joy_button [1] [2] > joy[0].num_buttons)
   options.joy_button [1] [2] = joy[0].num_buttons - 1;
  options.joy_button [1] [3] = get_config_int("Misc", "joy2_button_4", 4);
  if (options.joy_button [1] [3] > joy[0].num_buttons)
   options.joy_button [1] [3] = joy[0].num_buttons - 1;
  options.joy_button [1] [4] = get_config_int("Misc", "joy2_button_5", 5);
  if (options.joy_button [1] [4] > joy[0].num_buttons)
   options.joy_button [1] [4] = joy[0].num_buttons - 1;
  options.joy_button [1] [5] = get_config_int("Misc", "joy2_button_6", 6);
  if (options.joy_button [1] [5] > joy[0].num_buttons)
   options.joy_button [1] [5] = joy[0].num_buttons - 1;
 }

 ticked = 0;

 arena.players = 1;
// NOTE: it's assumed in a few places that if there's just one player, it's player[0].


}
コード例 #30
0
ファイル: mouse.c プロジェクト: AntonLanghoff/whitecatlib
/* show_mouse:
 *  Tells Allegro to display a mouse pointer. This only works when the timer 
 *  module is active. The mouse pointer will be drawn onto the bitmap bmp, 
 *  which should normally be the hardware screen. To turn off the mouse 
 *  pointer, which you must do before you draw anything onto the screen, call 
 *  show_mouse(NULL). If you forget to turn off the mouse pointer when 
 *  drawing something, the SVGA bank switching code will become confused and 
 *  will produce garbage all over the screen.
 */
void show_mouse(BITMAP *bmp)
{
   if (!mouse_driver)
      return;

   remove_int(mouse_move);

   /* Remove the mouse cursor */
   if (_mouse_screen) {
      acquire_bitmap(_mouse_screen);

      if (gfx_capabilities & GFX_HW_CURSOR) {
	 gfx_driver->hide_mouse();
	 gfx_capabilities &= ~(GFX_HW_CURSOR|GFX_SYSTEM_CURSOR);
 	 hw_cursor_dirty = TRUE;
      }
      else
	 draw_mouse(TRUE, FALSE);

      release_bitmap(_mouse_screen);
   }

   _mouse_screen = bmp;

   if (bmp && (current_cursor != MOUSE_CURSOR_NONE)) {
      acquire_bitmap(_mouse_screen);

      /* Default system cursor? */
      if ((current_cursor != MOUSE_CURSOR_ALLEGRO) && allow_system_cursor) {
         if (mouse_driver && mouse_driver->select_system_cursor) {
            use_system_cursor = mouse_driver->select_system_cursor(current_cursor);
            if (use_system_cursor) {
               gfx_capabilities |= GFX_HW_CURSOR|GFX_SYSTEM_CURSOR;
               hw_cursor_dirty = FALSE;
               got_hw_cursor = TRUE;
            }
         }
      }
      else {
         use_system_cursor = FALSE;
      }

      /* Custom hardware cursor? */
      if (hw_cursor_dirty) {
	 got_hw_cursor = FALSE;

	 if ((gfx_driver) && (gfx_driver->set_mouse_sprite) && (!_dispsw_status))
	    if (gfx_driver->set_mouse_sprite(mouse_sprite, mouse_x_focus, mouse_y_focus) == 0)
	       got_hw_cursor = TRUE;

	 hw_cursor_dirty = FALSE;
      }
      
      /* Try to display hardware (custom or system) cursor */
      if ((got_hw_cursor) && (is_same_bitmap(bmp, screen)))
	 if (gfx_driver->show_mouse(bmp, mx=mouse_x, my=mouse_y) == 0)
	    gfx_capabilities |= GFX_HW_CURSOR;

      /* Draw cursor manually if we can't do that */
      if (!(gfx_capabilities & GFX_HW_CURSOR)) {
	 draw_mouse(FALSE, TRUE);
         use_system_cursor = FALSE;
      }

      release_bitmap(_mouse_screen);

      install_int(mouse_move, 10);
   }
   else {
      if (mouse_driver->timer_poll) 
	 install_int(mouse_move, 10);
   }
}