forked from csnwc/Data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_neillsdl2.c
50 lines (36 loc) · 1.23 KB
/
demo_neillsdl2.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
#include <stdio.h>
#include <stdlib.h>
#include "neillsdl2.h"
#define RECTSIZE 20
#define MILLISECONDDELAY 20
int main(void)
{
SDL_Simplewin sw;
SDL_Rect rectangle;
rectangle.w = RECTSIZE;
rectangle.h = RECTSIZE;
Neill_SDL_Init(&sw);
do{
SDL_Delay(MILLISECONDDELAY);
/* Choose a random colour, a mixture of red, green and blue. */
Neill_SDL_SetDrawColour(&sw, rand()%SDL_8BITCOLOUR,
rand()%SDL_8BITCOLOUR,
rand()%SDL_8BITCOLOUR);
/* Filled Rectangle, fixed size, random position */
rectangle.x = rand()%(WWIDTH-RECTSIZE);
rectangle.y = rand()%(WHEIGHT-RECTSIZE);
SDL_RenderFillRect(sw.renderer, &rectangle);
/* Unfilled Rectangle, fixed size, random position */
rectangle.x = rand()%(WWIDTH-RECTSIZE);
rectangle.y = rand()%(WHEIGHT-RECTSIZE);
SDL_RenderDrawRect(sw.renderer, &rectangle);
Neill_SDL_UpdateScreen(&sw);
/* Has anyone pressed ESC or killed the SDL window ?
Must be called frequently - it's the only way of escaping */
Neill_SDL_Events(&sw);
}while(!sw.finished);
/* Clear up graphics subsystems */
SDL_Quit();
atexit(SDL_Quit);
return 0;
}