-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_sdl.c
65 lines (57 loc) · 1.92 KB
/
game_sdl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "game.h"
#include "game_aux.h"
#include "game_ext.h"
#include "game_private.h"
#include "game_tools.h"
#include "graphics.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 (TTF_Init() != 0) ERROR("Error: TTF_Init (%s)", SDL_GetError());
// if (Mix_OpenAudio(96000, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024) <
// 0) // création de la configuration de la carte son
// {
// SDL_Log("Erreur initialisation SDL_mixer : %s", Mix_GetError());
// SDL_Quit();
// return -1;
// }
/* 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());
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);
TTF_Quit();
SDL_Quit();
return EXIT_SUCCESS;
}