From 768f80a3629bfe95d62f5acab09fcb2d8f38cca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Sun, 25 Mar 2018 14:27:10 +0200 Subject: [PATCH] Create a display. --- CMakeLists.txt | 3 ++- src/display.c | 35 +++++++++++++++++++++++++++++++++++ src/display.h | 34 ++++++++++++++++++++++++++++++++++ src/globals.h | 6 ++++++ src/main.c | 34 ++++++++++++++++++++++++++++++++-- 5 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 src/display.c create mode 100644 src/display.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 17d445b..0f2de42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,8 @@ include_directories( SYSTEM ${ALLEG5_INCLUDE_DIRS}) set(SRCS - src/main.c) + src/main.c + src/display.c) add_definitions(-DVERSION="${TARGET_VERSION}") diff --git a/src/display.c b/src/display.c new file mode 100644 index 0000000..a2aada9 --- /dev/null +++ b/src/display.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2018 Ortega Froysa, Nicolás + * Author: Ortega Froysa, Nicolás + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "display.h" + +#include +#include + +static ALLEGRO_DISPLAY *display; + +int create_display(unsigned int width, unsigned int height) { + display = al_create_display(width, height); + if(!display) + return 0; + return 1; +} + +void destroy_display() { + al_destroy_display(display); +} diff --git a/src/display.h b/src/display.h new file mode 100644 index 0000000..e1db860 --- /dev/null +++ b/src/display.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2018 Ortega Froysa, Nicolás + * Author: Ortega Froysa, Nicolás + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +/** + * @brief Create an allegro 5 display with a given width and height. + * + * @param width The width of the display. + * @param height The height of the display. + * + * @return If successful it will return 1, else it will return 0. + */ +int create_display(unsigned int width, unsigned int height); + +/** + * @brief Destroy the display (used for shutdown). + */ +void destroy_display(); diff --git a/src/globals.h b/src/globals.h index e45c75f..55ade6b 100644 --- a/src/globals.h +++ b/src/globals.h @@ -21,3 +21,9 @@ #ifndef VERSION # define VERSION "[version]" #endif + +#ifndef FPS +# define FPS 60 +#endif + +extern int run; ///< Whether or not to continue running the simulation. diff --git a/src/main.c b/src/main.c index 624d078..d5252c5 100644 --- a/src/main.c +++ b/src/main.c @@ -16,11 +16,41 @@ * along with this program. If not, see . */ -#include - #include "globals.h" +#include "display.h" + +int run; + +#include +#include int main() { printf("SpaceShipSim v%s\n", VERSION); + + if(!al_init()) + { + fprintf(stderr, "alleg5: failed to initialize Allegro.\n"); + return 1; + } + if(!create_display(800, 600)) + { + fprintf(stderr, "alleg5: failed to create display.\n"); + return 1; + } + + // begin running the simulation + run = 1; + + while(run) + { + // TODO: handle events + // TODO: run simulation physics + al_clear_to_color(al_map_rgb(0, 0, 0)); + // TODO: run simulation draw functions + al_flip_display(); + } + + destroy_display(); + return 0; }