Create a display.
This commit is contained in:
parent
8c19b96bb7
commit
768f80a362
@ -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}")
|
||||
|
||||
|
35
src/display.c
Normal file
35
src/display.c
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
|
||||
* Author: Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "display.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <allegro5/allegro.h>
|
||||
|
||||
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);
|
||||
}
|
34
src/display.h
Normal file
34
src/display.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
|
||||
* Author: Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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();
|
@ -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.
|
||||
|
34
src/main.c
34
src/main.c
@ -16,11 +16,41 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "globals.h"
|
||||
#include "display.h"
|
||||
|
||||
int run;
|
||||
|
||||
#include <stdio.h>
|
||||
#include<allegro5/allegro.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user