Merge branch 'main' of gitlab.emi.u-bordeaux.fr:pt2/teams-s4/tm07/lightup-07c

This commit is contained in:
valentin carmona committed 2022-03-13 09:36:03 +01:00
commit 6252ce1ef0
2 files changed
+91 -2

No files matched your search

+24 -2
View File
@@ -9,6 +9,23 @@ enable_testing()
set(MEMORYCHECK_COMMAND_OPTIONS "--error-exitcode=1 --leak-check=full")
include(CTest)
## use pkgconfig to solve SDL2 dependencies (Linux only)
include(FindPkgConfig) # pkg-config --list-all | grep -i sdl2
pkg_search_module(SDL2 REQUIRED sdl2)
pkg_search_module(SDL2_IMG REQUIRED SDL2_image)
pkg_search_module(SDL2_TTF REQUIRED SDL2_ttf)
set(SDL2_ALL_LIBS ${SDL2_LIBRARIES} ${SDL2_IMG_LIBRARIES} ${SDL2_TTF_LIBRARIES})
set(SDL2_ALL_INC ${SDL2_INCLUDE_DIRS} ${SDL2_IMG_INCLUDE_DIRS} ${SDL2_TTF_INCLUDE_DIRS})
## use a CMake3 package to solve SDL2 dependencies
# find_package(SDL2 REQUIRED)
# set(SDL2_ALL_INC ${SDL2_INCLUDE_DIRS})
# set(SDL2_ALL_LIBS ${SDL2_LIBRARIES} -lSDL2_ttf -lSDL2_image) # add extra SDL2 libraries
message(STATUS "SDL2 include dir: ${SDL2_ALL_INC}")
message(STATUS "SDL2 all libraries: ${SDL2_ALL_LIBS}")
#positionne la variable
set(CMAKE_C_FLAGS "-std=c99 -Wall")
set(CMAKE_C_FLAGS_DEBUG "-g --coverage -pthread -Wextra -Wunused-parameter -Wpedantic -Werror") # use CMake option: -DCMAKE_BUILD_TYPE=DEBUG
@@ -20,14 +37,19 @@ set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG") # use CMake option: -DCMAKE_BUILD_TY
add_executable(game_text game_text.c)
target_link_libraries(game_text game)
# game tests
# game_tests
add_executable(game_test game_test.c)
target_link_libraries(game_test game)
# game solve
# game_solve
add_executable(game_solve game_solve.c)
target_link_libraries(game_solve game)
# game_sdl
# include_directories(${SDL2_ALL_INC})
# add_executable(game_sdl main.c model.c)
# target_link_libraries(game_sdl game ${SDL2_ALL_LIBS} m)
# libgame
add_library (game game.c game_aux.c game_ext.c game_private.c history.c game_tools.c game_examples.c)
+67
View File
@@ -0,0 +1,67 @@
// SDL2 Demo by aurelien.esnard@u-bordeaux.fr
#include <SDL.h>
#include <SDL_image.h> // required to load transparent texture from PNG
#include <SDL_ttf.h> // required to use TTF fonts
#include <stdbool.h>
#include <stdio.h>
#include "model.h"
/* **************************************************************** */
int main(int argc, char* argv[]) {
/* initialize SDL2 and some extensions */
if (SDL_Init(SDL_INIT_VIDEO) != 0)
ERROR("Error: SDL_Init VIDEO (%s)", SDL_GetError());
if (IMG_Init(IMG_INIT_PNG & IMG_INIT_PNG) != IMG_INIT_PNG)
ERROR("Error: IMG_Init PNG (%s)", SDL_GetError());
if (TTF_Init() != 0)
ERROR("Error: TTF_Init (%s)", SDL_GetError());
/* create window and renderer */
SDL_Window* win =
SDL_CreateWindow(APP_NAME, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
if (!win)
ERROR("Error: SDL_CreateWindow (%s)", SDL_GetError());
SDL_Renderer* ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (!ren)
ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_SOFTWARE);
if (!ren)
ERROR("Error: SDL_CreateRenderer (%s)", SDL_GetError());
/* initialize your environment */
Env* env = init(win, ren, argc, argv);
/* main render loop */
SDL_Event e;
bool quit = false;
while (!quit) {
/* manage events */
while (SDL_PollEvent(&e)) {
/* process your events */
quit = process(win, ren, env, &e);
if (quit)
break;
}
/* background in gray */
SDL_SetRenderDrawColor(ren, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(ren);
/* render all what you want */
render(win, ren, env);
SDL_RenderPresent(ren);
SDL_Delay(DELAY);
}
/* clean your environment */
clean(win, ren, env);
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
IMG_Quit();
TTF_Quit();
SDL_Quit();
return EXIT_SUCCESS;
}