-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisplay.c
77 lines (56 loc) · 1.38 KB
/
display.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
66
67
68
69
70
71
72
73
74
75
76
77
#define _XOPEN_SOURCE 500 /* usleep */
#include <stdio.h>
#include <unistd.h>
#include <SDL/SDL.h>
#include <GL/gl.h>
#include "controller.h"
#include "controller_state.h"
#include "debug.h"
#include "display.h"
#include "ending.h"
/* - - - - - - - - - - - - - - - - - - - - */
static struct {
SDL_Surface *surface;
} g;
/* - - - - - - - - - - - - - - - - - - - - */
static void graphics_init(void);
static void graphics_deinit(void);
static void draw_display(void);
/* - - - - - - - - - - - - - - - - - - - - */
void *
display_run(void *v)
{
struct display_run_args *d_args = v;
ending_t ending = d_args->ending;
controller_state_t cs = d_args->cs;
(void)cs;
graphics_init();
while (1) {
if (ending_get(ending)) {
break;
}
SDL_Delay(100);
draw_display();
print_info("display looping");
}
graphics_deinit();
print_info("display exiting");
return NULL;
}
/* - - - - - - - - - - - - - - - - - - - - */
static void draw_display(void) {
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
SDL_GL_SwapBuffers();
}
/* - - - - - - - - - - - - - - - - - - - - */
void graphics_init(void)
{
SDL_Init(SDL_INIT_VIDEO);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
g.surface = SDL_SetVideoMode(640, 480, 24, SDL_OPENGL);
}
void graphics_deinit(void)
{
SDL_Quit();
}