cmake + main.c
This commit is contained in:
1 parent
47ae303ec1
commit
8632d36b69
2 files changed
+91
-2
No files matched your search
+24
-2
@@ -9,6 +9,23 @@ enable_testing()
|
|||||||
set(MEMORYCHECK_COMMAND_OPTIONS "--error-exitcode=1 --leak-check=full")
|
set(MEMORYCHECK_COMMAND_OPTIONS "--error-exitcode=1 --leak-check=full")
|
||||||
include(CTest)
|
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
|
#positionne la variable
|
||||||
set(CMAKE_C_FLAGS "-std=c99 -Wall")
|
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
|
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)
|
add_executable(game_text game_text.c)
|
||||||
target_link_libraries(game_text game)
|
target_link_libraries(game_text game)
|
||||||
|
|
||||||
# game tests
|
# game_tests
|
||||||
add_executable(game_test game_test.c)
|
add_executable(game_test game_test.c)
|
||||||
target_link_libraries(game_test game)
|
target_link_libraries(game_test game)
|
||||||
|
|
||||||
# game solve
|
# game_solve
|
||||||
add_executable(game_solve game_solve.c)
|
add_executable(game_solve game_solve.c)
|
||||||
target_link_libraries(game_solve game)
|
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
|
# libgame
|
||||||
add_library (game game.c game_aux.c game_ext.c game_private.c history.c game_tools.c game_examples.c)
|
add_library (game game.c game_aux.c game_ext.c game_private.c history.c game_tools.c game_examples.c)
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user