Esempio n. 1
0
void
init_video (void)
{
  if (! al_init_image_addon ())
    error (-1, 0, "%s (void): failed to initialize image addon",
            __func__);

  al_set_new_display_flags (al_get_new_display_flags ()
                            | (display_mode < 0 ? ALLEGRO_WINDOWED : ALLEGRO_FULLSCREEN)
                            | ALLEGRO_RESIZABLE
                            | ALLEGRO_GENERATE_EXPOSE_EVENTS);

  display_width = display_width ? display_width : DISPLAY_WIDTH;
  display_height = display_height ? display_height : DISPLAY_HEIGHT;

  if (display_mode >= 0) {
    ALLEGRO_DISPLAY_MODE d;
    get_display_mode (display_mode, &d);
    display_width = d.width;
    display_height = d.height;
    al_set_new_display_refresh_rate (d.refresh_rate);
    al_set_new_display_flags (al_get_new_display_flags ()
                              & ~ALLEGRO_FULLSCREEN_WINDOW);
  }

  al_set_new_display_option (ALLEGRO_SINGLE_BUFFER, 1, ALLEGRO_SUGGEST);

  display = al_create_display (display_width, display_height);
  if (! display) error (-1, 0, "%s (void): failed to initialize display", __func__);

  set_target_backbuffer (display);
  al_set_new_bitmap_flags (ALLEGRO_VIDEO_BITMAP);

  al_set_window_title (display, WINDOW_TITLE);
  icon = load_bitmap (ICON);
  al_set_display_icon (display, icon);

  cutscene = true;
  if (mr.fit_w == 0 && mr.fit_h == 0) {
    mr.fit_w = 2;
    mr.fit_h = 2;
  }
  set_multi_room (1, 1);
  effect_buffer = create_bitmap (CUTSCENE_WIDTH, CUTSCENE_HEIGHT);
  black_screen = create_bitmap (CUTSCENE_WIDTH, CUTSCENE_HEIGHT);
  uscreen = create_bitmap (CUTSCENE_WIDTH, CUTSCENE_HEIGHT);
  iscreen = create_bitmap (display_width, display_height);
  clear_bitmap (uscreen, TRANSPARENT_COLOR);

  video_timer = create_timer (1.0 / EFFECT_HZ);

  al_init_font_addon ();
  builtin_font = al_create_builtin_font ();
  if (! builtin_font)
    error (-1, 0, "%s (void): cannot create builtin font", __func__);

  if (! al_init_primitives_addon ())
    error (-1, 0, "%s (void): failed to initialize primitives addon",
           __func__);
}
Esempio n. 2
0
void Window::resize(int width, int height, Window::WindowMode windowMode) {
	assert(mDisplay);

	if (windowMode == mWindowMode) {
		al_resize_display(mDisplay, width, height);
		return;
	}


	al_unregister_event_source(mEventQueue, al_get_display_event_source(mDisplay));
	al_destroy_display(mDisplay);
	switch (windowMode) {
		case Windowed:
			al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_OPENGL); break;
		case Resizable:
			al_set_new_display_flags(ALLEGRO_RESIZABLE | ALLEGRO_OPENGL); break;
		case FullScreen:
			al_set_new_display_flags(ALLEGRO_FULLSCREEN | ALLEGRO_OPENGL); break;
	}
	mDisplay = al_create_display(width, height);
	if (mDisplay == 0) {
		error(U"Creating a window failed");
		sys::closeProgram();
	}

	al_register_event_source(mEventQueue, al_get_display_event_source(mDisplay));

	activate();
}
Esempio n. 3
0
/** Returns the fullscreen display mode in ID as string
 * @param id Id of the display mode. MUST BE in range of 0 to cbeGetGfxModesCount()-1.
 * @returns Display mode as string. I.e. cbeGetGfxMode(0) returns a string "640,480,60,32" (in most cases).
 */
void cbeGetGfxMode(CBEnchanted *cb) {
	// Store the old flags for later restoring
	int32_t oldFlags = al_get_display_flags(cb->gfxInterface->getWindow());

	// Set the display flags for fullscreen
	al_set_new_display_flags(ALLEGRO_FULLSCREEN);

	// Get display modes count
	int32_t displayModesCount = al_get_num_display_modes();

	// Pop the ID from input
	int32_t displayId = cb->popValue().toInt();

	// Check if displayId is valid
	if (displayId < 0 || displayId >= displayModesCount) {
		string id = std::to_string(displayId);
		string count = std::to_string(displayModesCount);
		bool ignore = cb->errors->createError("cbeGetGfxMode() failed!", "Trying to get gfx mode with ID " + id + " out of " + count + " modes\nWhen ignored, the first display mode available in the list is returned.");

		// If ignored, displayId is 0. Otherwise push empty string and return.
		if (ignore) {
			displayId = 0;
		}
		else {
			cb->pushValue(ISString(""));
			return;
		}
	}

	// Where the display modes data is stored
	ALLEGRO_DISPLAY_MODE *displayData = new ALLEGRO_DISPLAY_MODE;

	// Get the display mode with id
	al_get_display_mode(displayId, displayData);

	// Restore old flags
	al_set_new_display_flags(oldFlags);

	if (displayData != NULL) {
		// Initialize the string to be returned
		string displayModeString;

		// Construct the string
		displayModeString =	std::to_string(displayData->width);
		displayModeString += "," + std::to_string(displayData->height);
		displayModeString += "," + std::to_string(displayData->refresh_rate);
		displayModeString += "," + std::to_string(al_get_pixel_format_bits(displayData->format));

		// Return the display mode
		cb->pushValue(displayModeString.substr(0 , displayModeString.length() ));
	}
	else {
		INFO("Something funny happened in cbeGetGfxMode(), you got an empty display mode...")
		cb->pushValue(ISString(""));
	}

	// Free memory
	delete displayData;
}
Esempio n. 4
0
int main3()
{
	if(!al_init())
	{
		al_show_native_message_box(NULL, NULL, "Error", "Could not initialize Allegro 5", NULL, ALLEGRO_MESSAGEBOX_ERROR); 
		return -1;
	}
	
	al_set_new_display_flags(ALLEGRO_FULLSCREEN);
	// al_set_new_display_flags(ALLEGRO_WINDOWED);
	// al_set_new_display_flags(ALLEGRO_RESIZABLE);
	// al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE);
	
	ALLEGRO_DISPLAY *display = al_create_display(800, 600); 

	if(!display)
	{
		al_show_native_message_box(NULL, NULL, "Error", "Could not create Allegro 5 display", NULL, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}

	al_set_window_position(display, 200, 100);
	al_set_window_title(display, "CodingMadeEasy");

	// You generally want to do this after you check to see if the display was created. If the display wasn't created then there's
	// no point in calling this function

	al_rest(10.0);
	al_destroy_display(display);

	return 0;
}
Esempio n. 5
0
int main(int argc, char **argv)
{
    al_init();
    al_init_image_addon();
    al_init_primitives_addon();
    al_init_font_addon();
    al_init_ttf_addon();
    al_get_display_mode(al_get_num_display_modes()-1, &disp_data);
    //al_set_new_display_flags(ALLEGRO_FULLSCREEN);
    al_set_new_display_flags(ALLEGRO_WINDOWED);
    al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST);
    disp_data.width*=0.8;
    disp_data.height*=0.8;
    display=al_create_display(disp_data.width, disp_data.height);
    if(!display)
    {
        return -1;
    }
    al_clear_to_color(al_map_rgb(0, 0, 0));
    al_flip_display();
    al_install_keyboard();
    al_install_mouse();
    al_install_audio();
    al_init_acodec_addon();
    al_reserve_samples(5);
    al_rest(5.0);
    al_destroy_display(display);

    return 0;
}
Esempio n. 6
0
void BaseGame::initScreen(ScreenType screenType, string screenTitle)
{
	if(!al_init())
	{
		al_show_native_message_box(NULL, "Error", "Error", "Could not initialize Allegro 5", NULL, 0);
		exit(-1);
	}

	int displayFlags = 0;
	switch(screenType)
	{
	case WINDOW: displayFlags = ALLEGRO_WINDOWED; break;
	case FULLSCREEN: displayFlags = ALLEGRO_FULLSCREEN; break;
	case FULLSCREEN_WINDOWED: displayFlags = ALLEGRO_FULLSCREEN | ALLEGRO_FULLSCREEN_WINDOW; break;
	default: displayFlags = ALLEGRO_WINDOWED;
	}
	al_set_new_display_flags(displayFlags);
	display = al_create_display(windowSize.x, windowSize.y);
	al_set_window_position(display, 0, 0);
	al_set_window_title(display, screenTitle.c_str());

	if(!display)
	{
		al_show_native_message_box(display, "Error", "Error", "Could not create Allegro Window", NULL, 0);
		exit(-1);
	}
}
Esempio n. 7
0
GUI::GUI()
{
    al_init();
    al_init_image_addon();
    al_init_primitives_addon();
    al_init_font_addon();
    al_install_keyboard();

    al_set_new_display_flags(ALLEGRO_WINDOWED);
    display = al_create_display(640, 480);
    al_set_window_position(display,10,10);
    al_set_window_title(display, "Rogue");

    timer = al_create_timer(1.0 / TICK_PER_S);
    queue = al_create_event_queue();

    al_register_event_source(queue, al_get_keyboard_event_source());
    al_register_event_source(queue, al_get_display_event_source(display));
    al_register_event_source(queue, al_get_timer_event_source(timer));
    al_start_timer(timer);

    viewport.view = Rectangle(0,0,640,480);

    tiles = al_load_bitmap("Images/Phoebus_tileset.png");

}
Esempio n. 8
0
void init(void)
{
	if (!al_init())
		abort_game("failed to initialize allegro!");

	if (!al_install_keyboard())
		abort_game("Couldn't find or connect the keyboard.");

	timer = al_create_timer(1.0 / 60);
	if (!timer)
		abort_game("Weird...I couldn't find or create a system timer.");

	al_set_new_display_flags(ALLEGRO_WINDOWED);
	display = al_create_display(640, 480);
	if(!display)
		abort_game("failed to create the display!");

	event_queue = al_create_event_queue();
	if (!event_queue)
		abort_game("Weird...I couldn't create an event queue.");

	al_register_event_source(event_queue, al_get_keyboard_event_source());
	al_register_event_source(event_queue, al_get_timer_event_source(timer));
	al_register_event_source(event_queue, al_get_display_event_source(display));

    spaceship.color = al_map_rgb(0,100,0);
    spaceship.heading = 0.0f;
    spaceship.x = 320.0f;
    spaceship.y = 240.0f;

	done = false;
}
Esempio n. 9
0
bool System::initSharedSystem()
{
  if (!al_is_system_installed())
    {
      assert(al_init() && "Failed to initialize Allegro.");
      assert(al_inhibit_screensaver(true) && "Failed to inhibit screensaver.");
    
      al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_GENERATE_EXPOSE_EVENTS | ALLEGRO_OPENGL_FORWARD_COMPATIBLE | ALLEGRO_OPENGL);
      al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP | ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR);
    }
  if (!al_init_image_addon())
    {
      std::cerr << "Failed to initialize image addon" << std::endl;
      return false;
    }
  if (!al_install_keyboard())
    {
      std::cerr << "Failed to install keyboard" << std::endl;
      return false;
    }
  if (!al_install_mouse())
    {
      std::cerr << "Failed to install mouse" << std::endl;
      return false;
    }
  if (!al_install_joystick())
    {
      std::cerr << "Failed to install joystick" << std::endl;
      return false;
    }

  return true;
}
void mw2_Application::Initialize()
{
	al_init();
	al_init_image_addon();
	al_install_keyboard();
	al_install_mouse();
	al_init_primitives_addon();
	al_init_font_addon();
	al_init_ttf_addon();
	al_init_acodec_addon();

	al_install_audio();
	al_reserve_samples(20); // maximum 20 sounds at a time

	al_set_new_display_flags(ALLEGRO_WINDOWED);
	al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);

	// this prevents random lag
	al_set_new_display_option( ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST );

	mWindow = al_create_display(Settings::width, Settings::height);
	al_set_window_title(mWindow, Settings::title.c_str());

	mw2_Input::Initialize(mWindow);

	srand( (unsigned int) std::time(0) );
}
Esempio n. 11
0
void Framework::InitialiseDisplay()
{
#ifdef WRITE_LOG
  printf( "Framework: Initialise Display\n" );
#endif

	int scrW = 800;
	int scrH = 480;
	bool scrFS = false;

	if( Settings->KeyExists( "Visual.ScreenWidth" ) )
  {
    Settings->GetIntegerValue( "Visual.ScreenWidth", &scrW );
  }
	if( Settings->KeyExists( "Visual.ScreenHeight" ) )
  {
    Settings->GetIntegerValue( "Visual.ScreenHeight", &scrH );
  }
	if( Settings->KeyExists( "Visual.FullScreen" ) )
  {
    Settings->GetBooleanValue( "Visual.FullScreen", &scrFS );
  }
  if( scrFS )
  {
    al_set_new_display_flags( ALLEGRO_FULLSCREEN_WINDOW );
  }
  al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST);
  displaySurface = al_create_display( scrW, scrH );
  if( displaySurface == 0 )
  {
    return;
  }
  al_set_blender( ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA );
  al_register_event_source( eventQueue, al_get_display_event_source( displaySurface ) );
}
Esempio n. 12
0
/** Get fullscreen display modes count
 * @returns List size
 */
void cbeGetGfxModesCount(CBEnchanted *cb) {
	// Store the old flags for later restoring
	int32_t oldFlags = al_get_display_flags(cb->gfxInterface->getWindow());

	// Set the display flags for fullscreen
	al_set_new_display_flags(ALLEGRO_FULLSCREEN);

	// Get display modes count
	int32_t displayModesCount = al_get_num_display_modes();

	// Restore old flags
	al_set_new_display_flags(oldFlags);

	// Return the modes count
	cb->pushValue(displayModesCount);
}
Esempio n. 13
0
void init(void)
{
    if (!al_init())
        abort_game("Failed to initialize allegro");
 
    if (!al_install_keyboard())
        abort_game("Failed to install keyboard");
 
    timer = al_create_timer(1.0 / 60);
    if (!timer)
        abort_game("Failed to create timer");
 
    al_set_new_display_flags(ALLEGRO_WINDOWED);
    display = al_create_display(640, 480);
    if (!display)
        abort_game("Failed to create display");
 
    event_queue = al_create_event_queue();
    if (!event_queue)
        abort_game("Failed to create event queue");
 
    al_register_event_source(event_queue, al_get_keyboard_event_source());
    al_register_event_source(event_queue, al_get_timer_event_source(timer));
    al_register_event_source(event_queue, al_get_display_event_source(display));
 
    done = false;
}
Esempio n. 14
0
int main(void)
{
    ALLEGRO_DISPLAY *display;
    ALLEGRO_EVENT_QUEUE *events;
    ALLEGRO_EVENT event;

    double last_resize;
    int rs = 100;

    /* Initialize Allegro and create an event queue. */
    if (!al_init()) {
        abort_example("Could not init Allegro.\n");
        return 1;
    }
    events = al_create_event_queue();

    /* Setup a display driver and register events from it. */
    al_set_new_display_flags(ALLEGRO_RESIZABLE);
    display = al_create_display(rs, rs);
    al_register_event_source(events, al_get_display_event_source(display));

    /* Setup a keyboard driver and regsiter events from it. */
    al_install_keyboard();
    al_register_event_source(events, al_get_keyboard_event_source());

    /* Display a pulsating window until a key or the closebutton is pressed. */
    redraw();
    last_resize = 0;
    while (true) {
        if (al_get_next_event(events, &event)) {
            if (event.type == ALLEGRO_EVENT_DISPLAY_RESIZE) {
                ALLEGRO_DISPLAY_EVENT *de = &event.display;
                al_acknowledge_resize(de->source);
                redraw();
            }
            if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
                break;
            }
            if (event.type == ALLEGRO_EVENT_KEY_DOWN) {
                break;
            }
        }
        if (al_current_time() - last_resize > 0.1) {
            int s;

            last_resize = al_current_time();
            rs += 10;
            if (rs == 300)
               rs = 100;
            s = rs;
            if (s > 200)
               s = 400 - s;
            al_resize_display(s, s);
        }
    }

    return 0;
}
Esempio n. 15
0
bool init(int w, int h, bool fullscreen = false) {
//	HWND hWndDisplay = NULL;
	const char* err;
	#define INIT(x, y) if(!(x)) { err = y; goto err; }

	mt_seed();
	
	// Allegro initialization

	INIT( al_init() &&
	      al_install_mouse() &&
	      al_install_keyboard() &&
	      al_init_image_addon() &&
		  al_init_primitives_addon(),
		"initialize allegro" );
	
	
	if(fullscreen) al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);
	INIT(display = al_create_display(w, h), "create display")
	al_set_window_title(display, "ŒwiteŸ");
//	{	auto icon = al_load_bitmap("img\\icon.gif");
//		if(icon) al_set_display_icon(display, icon);	}
//	if(fullscreen) {
//		hWndDisplay = al_get_win_window_handle(display);
//		SetWindowLong(hWndDisplay, GWL_STYLE, 0);
//		ShowWindow(hWndDisplay, SW_MAXIMIZE);
//	}


	INIT(timer = al_create_timer(1.0 / 60), "create timer")

    INIT(event_queue = al_create_event_queue(), "create event queue")

	al_register_event_source(event_queue, al_get_keyboard_event_source());
    al_register_event_source(event_queue, al_get_mouse_event_source());
    al_register_event_source(event_queue, al_get_display_event_source(display));
    al_register_event_source(event_queue, al_get_timer_event_source(timer));
    al_start_timer(timer);

	// End of Allegro initialization

	INIT(setup(display), "initialize renderer");

	#undef INIT
	return true;

err:
	if(display) al_destroy_display(display);
	{
		char* buf = new char[strlen(err) + 13];
		sprintf(buf, "Failed to %s!\n", err);
//		MessageBoxA(NULL, buf, "Error", MB_ICONERROR);
		delete buf;
	}
	return false;
}
Esempio n. 16
0
void StateControl::CreateAllegroDisplay()
{
	al_set_new_display_flags(ALLEGRO_WINDOWED);
	display = al_create_display(ScreenWidth, ScreenHeight);
	if (!display)
	{
		al_show_native_message_box(display, "Error", "Display Settings", "Couldn't create a display.", NULL, ALLEGRO_MESSAGEBOX_ERROR);
		exit(-1);
	}
	/* setting new window title */
	al_set_window_title(display, "Radio Station");
}
Esempio n. 17
0
int main(void)
{
   ALLEGRO_DISPLAY *display;
   ALLEGRO_EVENT_QUEUE *queue;
   ALLEGRO_EVENT event;
   int frames = 0;
   double start;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
      return 1;
   }

   al_install_keyboard();
   al_set_new_display_flags(ALLEGRO_OPENGL);
   display = al_create_display(640, 480);
   if (!display) {
      abort_example("Could not create display.\n");
      return 1;
   }

   queue = al_create_event_queue();
   al_register_event_source(queue, al_get_keyboard_event_source());
   al_register_event_source(queue, al_get_display_event_source(display));

   start = al_get_time();
   while (true) {
      /* Check for ESC key or close button event and quit in either case. */
      if (!al_is_event_queue_empty(queue)) {
         while (al_get_next_event(queue, &event)) {
            switch (event.type) {
               case ALLEGRO_EVENT_DISPLAY_CLOSE:
                  goto done;

               case ALLEGRO_EVENT_KEY_DOWN:
                  if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
                     goto done;
                  break;
            }
         }
      }
      draw_opengl();
      al_flip_display();
      frames++;
   }

done:

   printf("%.1f FPS\n", frames / (al_get_time() - start));
   al_destroy_event_queue(queue);

   return 0;
}
Esempio n. 18
0
bool Window::create(int width, int height, Window::WindowMode windowMode) {
	assert(mDisplay == 0 && mEventQueue == 0);

	switch (windowMode) {
		case Windowed:
			al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_OPENGL); break;
		case Resizable:
			al_set_new_display_flags(ALLEGRO_RESIZABLE | ALLEGRO_OPENGL); break;
		case FullScreen:
			al_set_new_display_flags(ALLEGRO_FULLSCREEN | ALLEGRO_OPENGL); break;
	}
	mWindowMode = windowMode;
	al_set_new_display_option(ALLEGRO_DEPTH_SIZE,0,ALLEGRO_SUGGEST);
	al_set_new_display_option(ALLEGRO_SUPPORT_NPOT_BITMAP,1,ALLEGRO_SUGGEST);
	al_set_new_display_option(ALLEGRO_CAN_DRAW_INTO_BITMAP,1,ALLEGRO_REQUIRE);
	al_set_new_display_option(ALLEGRO_COMPATIBLE_DISPLAY,1,ALLEGRO_REQUIRE);
	al_set_new_display_option(ALLEGRO_VSYNC, 2, ALLEGRO_SUGGEST);
	mDisplay = al_create_display(width, height);
	if (mDisplay == 0) {
		error(U"Creating a window failed");

		//If fullscreen, try windowed
		if (windowMode == FullScreen) {
			return create(width, height);
		}
		else {
			return false;
		}
	}

	mEventQueue = al_create_event_queue();
	al_register_event_source(mEventQueue, al_get_display_event_source(mDisplay));

	mBackgroundColor = al_map_rgb(0,0,0);

	activate();

	return true;

}
Esempio n. 19
0
int
main (int argc, char **argv)
{
  g_type_init ();
  
  al_init ();
  al_init_image_addon ();

  al_set_new_display_option (ALLEGRO_RED_SIZE, 8,  ALLEGRO_REQUIRE);
  al_set_new_display_option (ALLEGRO_GREEN_SIZE, 8, ALLEGRO_REQUIRE);
  al_set_new_display_option (ALLEGRO_BLUE_SIZE, 8, ALLEGRO_REQUIRE);
  al_set_new_display_option (ALLEGRO_ALPHA_SIZE, 8, ALLEGRO_REQUIRE);
  /* Nouveau = good */
  /* al_set_new_display_option (ALLEGRO_AUX_BUFFERS, 4, ALLEGRO_REQUIRE); */

  al_set_new_display_flags (ALLEGRO_WINDOWED | ALLEGRO_OPENGL);

  ALLEGRO_DISPLAY *disp;
  disp = al_create_display (640, 480);
  xassert (disp);

  g_xassert (al_get_opengl_extension_list ()->ALLEGRO_GL_ARB_depth_texture);
  g_xassert (al_get_opengl_extension_list ()->ALLEGRO_GL_ARB_framebuffer_object);

  al_set_target_backbuffer (disp);

  printf ("OPENGL %x\n", al_get_opengl_version ());


  blender_bmp = al_load_bitmap ("../data/n1img0.bmp");
  g_xassert (640 == al_get_bitmap_width (blender_bmp) &&
             480 == al_get_bitmap_height (blender_bmp));
  blender_tex = al_get_opengl_texture (blender_bmp);
  g_xassert (blender_tex);


  GLint glvar;
  /* Query GL_MAX_DRAW_BUFFERS, GL_MAX_COLOR_ATTACHMENTS */
  glGetIntegerv (GL_MAX_DRAW_BUFFERS, &glvar);
  xassert (4 <= glvar);
  glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &glvar);
  xassert (4 <= glvar);

  derp ();

  al_flip_display ();

  al_rest (2);

  return EXIT_SUCCESS;
}
Esempio n. 20
0
void init(int width, int height) {
	danmakux.width = width;
	danmakux.height = height;

	if (!al_init()) al_show_native_message_box(display, "Error", "Error", "Failed to initialize Allegro!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
	
	if (!al_install_keyboard()) al_show_native_message_box(display, "Error", "Error", "Failed to install keyboard!", NULL, ALLEGRO_MESSAGEBOX_ERROR);

	if (!al_install_audio()) al_show_native_message_box(display, "Error", "Error", "Failed to install audio!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
	
	if (!al_reserve_samples(10)) al_show_native_message_box(display, "Error", "Error", "Failed to reserve samples!", NULL, ALLEGRO_MESSAGEBOX_ERROR);

	timer = al_create_timer(1.0 / FPS);
	if (!timer) al_show_native_message_box(display, "Error", "Error", "Failed to create timer!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
	
	al_set_new_display_flags(ALLEGRO_WINDOWED);
	al_set_new_window_position(700, 200);
	display = al_create_display(danmakux.width, danmakux.height);
	if (!display) al_show_native_message_box(display, "Error", "Error", "Failed to create display!", NULL, ALLEGRO_MESSAGEBOX_ERROR);

	event_queue = al_create_event_queue();
	if (!event_queue) al_show_native_message_box(display, "Error", "Error", "Failed to create event queue!", NULL, ALLEGRO_MESSAGEBOX_ERROR);

	al_register_event_source(event_queue, al_get_keyboard_event_source());
	al_register_event_source(event_queue, al_get_timer_event_source(timer));
	al_register_event_source(event_queue, al_get_display_event_source(display));

	redraw = false;
	danmakux.fireBomb = false;
	danmakux.lives = 2;
	danmakux.bombsRemain = 2;
	danmakux.weaponLevel = 1;
	danmakux.done = false;
	danmakux.state_menu = true;
	danmakux.state_paused = false;
	danmakux.state_playing = false;
	danmakux.state_dialog = false;
	danmakux.menuChoice = 0;
	danmakux.currentLevel = 1;
	danmakux.player = &playerset;
	UI = danmakux.resources.get_image("ui.png");

	al_start_timer(timer);
	loadMenu("mainmenu");
	/*danmakux.state_menu = false;
							danmakux.state_playing = true;
							danmakux.state_paused = false;
							loadLevel("level1");*/
	al_play_sample(danmakux.bgm, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL);
}
Esempio n. 21
0
Terminal::Terminal(std::string const& fontPath, int charWidth, int charHeight, int width, int height)
{
    this->width = width;
    this->height = height;
    this->charWidth = charWidth;
    this->charHeight = charHeight;
    
    // init addons
    if (!al_init_image_addon())
        THROW() << "Failed to init image addon";
    if (!al_init_primitives_addon())
        THROW() << "Failed to init primitives addon";
    
    // load the font
    glyphSheet = al_load_bitmap(fontPath.c_str());
    if (!glyphSheet)
        THROW() << "Failed to load font: " << fontPath;
    
    // create the glyphs
    for (int y = 0; y < GLYPH_ROWS; ++y) {
        for (int x = 0; x < GLYPH_COLUMNS; ++x) {
            ALLEGRO_BITMAP* glyph = al_create_sub_bitmap(glyphSheet, x * charWidth, y * charHeight, charWidth, charHeight);
            if (!glyph)
                THROW() << "Failed to create glyphs";
            al_convert_mask_to_alpha(glyph, al_map_rgb(0, 0, 0));
            glyphs.push_back(glyph);
        }
    }
    
    // create the window
    al_set_new_display_flags(ALLEGRO_WINDOWED);
    al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST);
    al_set_new_display_option(ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST);
    display = al_create_display(width * charWidth, height * charHeight);
    if (!display)
        THROW() << "Failed to create display";
    al_clear_to_color(al_map_rgb(0, 0, 0));
    
    // create the character arrays
    for (int i = 0; i < width * height; i++) {
        chars.push_back(CharData(' ', white, black));
        oldChars.push_back(CharData('?', white, black));
        // we make oldChars different to force a refresh
    }
    
    foregroundColor = white;
    backgroundColor = black;
    cursorX = cursorY = 0;
}
Esempio n. 22
0
void init_allegro(void)
{

	if (!al_init()) {
	abort_game("Failed to initialize allegro");
	}

 
	if(!al_init_image_addon()){
		abort_game("failed to initialize allegro image addon!");
	}

	al_init_font_addon();
	if(!al_init_ttf_addon()) {
		abort_game("failed to initialize allegro ttf addon!");
	}


	if (!al_install_keyboard()) {
		abort_game("Failed to install keyboard");
	}
 
	timer = al_create_timer(1.0 / FPS);
	if (!timer) {
		abort_game("Failed to create timer");
	}
 
	al_set_new_display_flags(ALLEGRO_WINDOWED);
	display = al_create_display(width, height);
	if (!display){
		abort_game("Failed to create display");
	}
 
	event_queue = al_create_event_queue();
	if (!event_queue) {
		abort_game("Failed to create event queue");
	}






	al_register_event_source(event_queue, al_get_keyboard_event_source());
	al_register_event_source(event_queue, al_get_timer_event_source(timer));
	al_register_event_source(event_queue, al_get_display_event_source(display));

}
int main(int argc, char *argv[])
{
   ALLEGRO_DISPLAY *display;
   ALLEGRO_FONT *font;

   (void)argc;
   (void)argv;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
      return 1;
   }

   al_init_primitives_addon();
   al_init_image_addon();
   al_init_font_addon();

   al_install_keyboard();
   al_install_mouse();

   al_set_new_display_flags(ALLEGRO_GENERATE_EXPOSE_EVENTS);
   display = al_create_display(640, 480);
   if (!display) {
      abort_example("Error creating display\n");
      return 1;
   }

   //printf("Display format = %d\n", al_get_display_format());

   font = al_load_font("data/fixed_font.tga", 0, 0);
   if (!font) {
      abort_example("Failed to load data/fixed_font.tga\n");
      return 1;
   }

   /* Don't remove these braces. */
   {
      Theme theme(font);
      Prog prog(theme, display);
      prog.run();
   }

   al_destroy_font(font);

   return 0;
}
Esempio n. 24
0
ALLEGRO_DISPLAY *AllegroNewDisplay(int x, int y, ALLEGRO_EVENT_QUEUE *queue)
{
    al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE | ALLEGRO_NOFRAME);

    ALLEGRO_DISPLAY *display = al_create_display(x, y);
    if(!display) {
        fprintf(stderr, "failed to create display!\n");
        return NULL;
    }

    al_register_event_source(queue, al_get_display_event_source(display));

    al_clear_to_color(al_map_rgb(0,0,0));
    al_flip_display();

    return display;
}
Esempio n. 25
0
int main(int argc, char **argv)
{
   ALLEGRO_DISPLAY *display;
   ALLEGRO_BITMAP *picture;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
      return 1;
   }
   al_init_primitives_addon();
   al_install_keyboard();
   al_init_image_addon();

   open_log_monospace();

   if (argc == 2) {
   	al_set_new_display_adapter(atoi(argv[1]));
   }

   al_set_new_display_flags(ALLEGRO_FULLSCREEN |
       ALLEGRO_GENERATE_EXPOSE_EVENTS);
   display = al_create_display(res[cur_res].w, res[cur_res].h);
   if (!display) {
      abort_example("Error creating display\n");
      return 1;
   }
   
   picture = al_load_bitmap("data/mysha.pcx");
   if (!picture) {
      abort_example("mysha.pcx not found\n");
      return 1;
   }

   main_loop(display, picture);

   al_destroy_bitmap(picture);

   /* Destroying the fullscreen display restores the original screen
    * resolution.  Shutting down Allegro would automatically destroy the
    * display, too.
    */
   al_destroy_display(display);

   return 0;
}
Esempio n. 26
0
int main(int argc, char **argv)
{
   (void)argc;
   (void)argv;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }

   al_init_primitives_addon();
   al_install_keyboard();
   al_init_image_addon();
   al_init_font_addon();
   init_platform_specific();

   al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);
   display = al_create_display(640, 480);
   if (!display) {
      abort_example("Error creating display\n");
   }

   queue = al_create_event_queue();
   al_register_event_source(queue, al_get_keyboard_event_source());
   al_register_event_source(queue, al_get_display_event_source(display));

   picture = al_load_bitmap("data/mysha.pcx");
   if (!picture) {
      abort_example("mysha.pcx not found\n");
   }
   
   font = al_load_font("data/fixed_font.tga", 0, 0);
   if (!font) {
      abort_example("data/fixed_font.tga not found.\n");
   }

   redraw();
   run();

   al_destroy_display(display);

   al_destroy_event_queue(queue);

   return 0;
}
Esempio n. 27
0
void gdp_init(){
    // aloca limites de exibicao
    listlifeless = calloc(LIFELESS,sizeof(Lifeless*));
    listchars = calloc(CHARS,sizeof(Char*));

    // configurações iniciais
    ncanaisaudio = 3; // numero de canais de audio
    connecterro  = 0; //nao existe erro
    ntotlifeless = 0; // numero de objetos
    ntotchars    = 4; // numero de personagens
    ntotenemies  = 0; // numero de inimigos
    opmap        = 1; // mapa escolhido
    scale        = 1.5; //escala do mapa
    boss_char_id = gdp_files_quick_getint("Configs//server.txt","boss_char_id"); //id do boss

	// Inicializa a Allegro
	al_init();

	// Inicializa o add-on para utilização de imagens
	al_init_image_addon();

	// Inicializa o add-on para utilização de teclado
	al_install_keyboard();

	// Inicialização do add-on para uso de fontes
	al_init_font_addon();
	al_init_ttf_addon();

	// Inicialização do add-on para uso de sons
	al_install_audio();
	al_init_acodec_addon();
	al_reserve_samples(ncanaisaudio);

    //inicia addons de primitivas
    al_init_primitives_addon();

	// Configura a janela
	 al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW|ALLEGRO_FULLSCREEN);
	SCREEN = al_create_display(wigth, height);
	// define o titulo
	al_set_window_title(SCREEN, title);

    ambient = NULL;
}
Esempio n. 28
0
int main(int argc, char **argv){
 
   ALLEGRO_DISPLAY       *display = NULL;
   ALLEGRO_DISPLAY_MODE   disp_data;
 
   al_init(); // I'm not checking the return value for simplicity.
   al_init_image_addon();
   al_init_primitives_addon();
 
   al_get_display_mode(al_get_num_display_modes() - 1, &disp_data);
 
   al_set_new_display_flags(ALLEGRO_FULLSCREEN);
   display = al_create_display(disp_data.width, disp_data.height);
 
   al_rest(3);
   al_destroy_display(display);
 
   return 0;
}
Esempio n. 29
0
  bool					launch(int width, int height)
  {
    al_set_new_display_flags(ALLEGRO_OPENGL_3_0);
    if (!al_create_display(width, height))
      return false;
    glEnable(GL_TEXTURE_2D);
    // glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    //glEnable(GL_ALPHA_TEST);
    //glEnable(GL_BLEND);

    //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //glAlphaFunc(GL_GREATER, 0.1);

    if (!EventManager::getInstance().init())
      return false;
    srand(time(NULL));
    return true;
  }
Esempio n. 30
0
void Engine::cleanup(){
	// cleanup the all states

	while(!states.empty()){
		states.back()->cleanup();
		states.pop_back();
	}

	// switch back to windowed mode so other
	// programs won't get accidentally resized
	if(m_fullscreen){
		al_set_new_display_flags(ALLEGRO_WINDOWED);
	}

    al_destroy_font(defaultFont);
    al_destroy_display(display);
    al_destroy_event_queue(event_queue);
    al_destroy_timer(timer);
}