Windows, Visual Studio 2015 and Nuget Allegro 5

From Allegro Wiki
Revision as of 21:11, June 29, 2017 by Mupi (talk | contribs) (Create a sample Allegro program)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

About

This tutorial will explain how to start a simple Allegro project using MSVC 2015 and NuGet. Note that this should also work for later versions of MSVC (and possibly earlier versions), as the NuGet package is built to handle different versions.

Tutorial

Create the project

Creating a new project.
  • Go to File>New>Project to create a new empty C++ project.

Install the Allegro Package

Select Manage NuGet Packages.
Find and install the Allegro package.
  • Right click your project name, and select Manage NuGet Packages.
  • Go to the Browse tab and search for Allegro in the search bar. You should see the main Allegro 5 package there.
  • Press the Install button on the right.
  • Allegro should now be installed!

Configure the Allegro Package

Open Project properties.
Configure the Allegro library type.
Configure the Allegro add-ons.
  • Allegro package comes with a few options that you can and should configure. Right click your project name, and select Properties.
  • Select Allegro 5 entry and the Library type item. This is where you configure what type of build of Allegro you'll be using. For now, select Dynamic Debug - Dynamic Runtime. This will use the Debug version of Allegro, which is Dynamic (which means there will be Allegro DLLs next to your program) and it'll be using a Dynamic Runtime (doesn't matter much here, as you're probably not going to distribute your program with the Debug version of Allegro). Using the Debug version of Allegro is recommended during development as it will have additional checks to make help you make sure you're using Allegro correctly.
  • Now select the Add-ons item. Here you enable which Allegro addons you'll be using. For this tutorial, we'll be using the Font Addon so change that to Yes.
  • Hit the Apply button.

Create a sample Allegro program

Add a new item.
Add a new main.cpp file.
Compile and run your Allegro program.
Welcome to Allegro!
  • Now it's time to write a simple program to make sure everything works. Right click your project name, and select Add>New Item....
  • Create a new file called main.cpp.
  • Write a simple program. Note: for tutorial purposes there is no error checking here. Make sure to add error checking in your actual program!
#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>

int main()
{
	al_init();
	al_init_font_addon();
	ALLEGRO_DISPLAY* display = al_create_display(800, 600);
	ALLEGRO_FONT* font = al_create_builtin_font();
	al_clear_to_color(al_map_rgb(0, 0, 0));
	al_draw_text(font, al_map_rgb(255, 255, 255), 400, 300, ALLEGRO_ALIGN_CENTER, "Welcome to Allegro!");
	al_flip_display();
	al_rest(5.0);
	return 0;
}
  • Press the Local Windows Debugger button and watch your program compile and run. It should display a window with a nice salutation!

Next steps

  • When sending your program to other people, it's best to select the Static Monolith Release - Static runtime. That way, there'll be no extra binaries aside from your .exe file.
  • Check out the Allegro 5 API Tutorials.