annotate Xcode-iPhoneOS/Template/SDL Application/main.c @ 4820:1768f88d5af9

Added Windows build files for testshape.
author egottlieb
date Sun, 01 Aug 2010 23:26:37 -0400
parents 20326ba2bda2
children b6c7a6b07ebf
rev   line source
3277
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 * rectangles.c
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 * written by Holmes Futrell
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 * use however you want
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 */
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 #include "SDL.h"
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 #include <time.h>
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 #define SCREEN_WIDTH 320
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 #define SCREEN_HEIGHT 480
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 int
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14 randomInt(int min, int max)
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 {
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 return min + rand() % (max - min + 1);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 }
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 void
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 render(void)
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 {
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 Uint8 r, g, b;
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 /* Come up with a random rectangle */
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 SDL_Rect rect;
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 rect.w = randomInt(64, 128);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 rect.h = randomInt(64, 128);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 rect.x = randomInt(0, SCREEN_WIDTH);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 rect.y = randomInt(0, SCREEN_HEIGHT);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 /* Come up with a random color */
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 r = randomInt(50, 255);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 g = randomInt(50, 255);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 b = randomInt(50, 255);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 /* Fill the rectangle in the color */
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 SDL_RenderFill(r, g, b, 255, &rect);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 /* update screen */
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 SDL_RenderPresent();
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 }
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 int
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 main(int argc, char *argv[])
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 {
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 SDL_WindowID windowID;
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 int done;
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 SDL_Event event;
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 /* initialize SDL */
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 printf("Could not initialize SDL\n");
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 }
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 /* seed random number generator */
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 srand(time(NULL));
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 /* create window and renderer */
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 windowID =
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 if (windowID == 0) {
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 printf("Could not initialize Window\n");
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 }
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 if (SDL_CreateRenderer(windowID, -1, 0) != 0) {
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 printf("Could not create renderer\n");
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 }
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 /* Fill screen with black */
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 SDL_RenderFill(0, 0, 0, 0, NULL);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 /* Enter render loop, waiting for user to quit */
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 done = 0;
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 while (!done) {
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 while (SDL_PollEvent(&event)) {
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 if (event.type == SDL_QUIT) {
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 done = 1;
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 }
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 }
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 render();
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 SDL_Delay(1);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 }
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 /* shutdown SDL */
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 SDL_Quit();
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 return 0;
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 }