Mercurial > sdl-ios-xcode
annotate test/testintersections.c @ 5198:bb45ecd958d8
Renamed files for consistency
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 05 Feb 2011 12:01:11 -0800 |
parents | d976b67150c5 |
children |
rev | line source |
---|---|
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 /* Simple program: draw as many random objects on the screen as possible */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 #include <stdlib.h> |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 #include <stdio.h> |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 #include <time.h> |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 #include "common.h" |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 #define SWAP(typ,a,b) do{typ t=a;a=b;b=t;}while(0) |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 #define NUM_OBJECTS 100 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 static CommonState *state; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 static int num_objects; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 static SDL_bool cycle_color; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 static SDL_bool cycle_alpha; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 static int cycle_direction = 1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 static int current_alpha = 255; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 static int current_color = 255; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 void |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
23 DrawPoints(SDL_Window * window, SDL_Renderer * renderer) |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 int i; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 int x, y; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 int window_w, window_h; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 /* Query the sizes */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 SDL_GetWindowSize(window, &window_w, &window_h); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 for (i = 0; i < num_objects * 4; ++i) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 /* Cycle the color and alpha, if desired */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 if (cycle_color) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 current_color += cycle_direction; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 if (current_color < 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 current_color = 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 cycle_direction = -cycle_direction; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 if (current_color > 255) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 current_color = 255; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 cycle_direction = -cycle_direction; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 if (cycle_alpha) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 current_alpha += cycle_direction; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 if (current_alpha < 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 current_alpha = 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 cycle_direction = -cycle_direction; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 if (current_alpha > 255) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 current_alpha = 255; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 cycle_direction = -cycle_direction; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 } |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
56 SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color, |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 (Uint8) current_color, (Uint8) current_alpha); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 x = rand() % window_w; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 y = rand() % window_h; |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
61 SDL_RenderDrawPoint(renderer, x, y); |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 #define MAX_LINES 16 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 int num_lines = 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 SDL_Rect lines[MAX_LINES]; |
2997 | 68 static int |
69 add_line(int x1, int y1, int x2, int y2) | |
70 { | |
71 if (num_lines >= MAX_LINES) | |
72 return 0; | |
73 if ((x1 == x2) && (y1 == y2)) | |
74 return 0; | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 printf("adding line (%d, %d), (%d, %d)\n", x1, y1, x2, y2); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 lines[num_lines].x = x1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 lines[num_lines].y = y1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 lines[num_lines].w = x2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 lines[num_lines].h = y2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 return ++num_lines; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 void |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
87 DrawLines(SDL_Window * window, SDL_Renderer * renderer) |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 int i; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 int x1, y1, x2, y2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 int window_w, window_h; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 /* Query the sizes */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 SDL_GetWindowSize(window, &window_w, &window_h); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 for (i = 0; i < num_lines; ++i) { |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
97 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 if (i == -1) { |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
100 SDL_RenderDrawLine(renderer, 0, 0, window_w - 1, window_h - 1); |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
101 SDL_RenderDrawLine(renderer, 0, window_h - 1, window_w - 1, 0); |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
102 SDL_RenderDrawLine(renderer, 0, window_h / 2, window_w - 1, window_h / 2); |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
103 SDL_RenderDrawLine(renderer, window_w / 2, 0, window_w / 2, window_h - 1); |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 } else { |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
105 SDL_RenderDrawLine(renderer, lines[i].x, lines[i].y, lines[i].w, lines[i].h); |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 #define MAX_RECTS 16 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 int num_rects = 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 SDL_Rect rects[MAX_RECTS]; |
2997 | 113 static int |
114 add_rect(int x1, int y1, int x2, int y2) | |
115 { | |
116 if (num_rects >= MAX_RECTS) | |
117 return 0; | |
118 if ((x1 == x2) || (y1 == y2)) | |
119 return 0; | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 |
2997 | 121 if (x1 > x2) |
122 SWAP(int, x1, x2); | |
123 if (y1 > y2) | |
124 SWAP(int, y1, y2); | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 |
2997 | 126 printf("adding rect (%d, %d), (%d, %d) [%dx%d]\n", x1, y1, x2, y2, |
127 x2 - x1, y2 - y1); | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 rects[num_rects].x = x1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 rects[num_rects].y = y1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 rects[num_rects].w = x2 - x1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 rects[num_rects].h = y2 - y1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 return ++num_rects; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 static void |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
138 DrawRects(SDL_Window * window, SDL_Renderer * renderer) |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 int i; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 int window_w, window_h; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 /* Query the sizes */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 SDL_GetWindowSize(window, &window_w, &window_h); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 for (i = 0; i < num_rects; ++i) { |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
147 SDL_SetRenderDrawColor(renderer, 255, 127, 0, 255); |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
148 SDL_RenderFillRect(renderer, &rects[i]); |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 static void |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
153 DrawRectLineIntersections(SDL_Window * window, SDL_Renderer * renderer) |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 int i, j, window_w, window_h; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 /* Query the sizes */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 SDL_GetWindowSize(window, &window_w, &window_h); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 for (i = 0; i < num_rects; i++) |
2997 | 161 for (j = 0; j < num_lines; j++) { |
162 int x1, y1, x2, y2; | |
163 SDL_Rect r; | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 |
2997 | 165 r = rects[i]; |
166 x1 = lines[j].x; | |
167 y1 = lines[j].y; | |
168 x2 = lines[j].w; | |
169 y2 = lines[j].h; | |
170 | |
171 if (SDL_IntersectRectAndLine(&r, &x1, &y1, &x2, &y2)) { | |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
172 SDL_SetRenderDrawColor(renderer, 0, 255, 55, 255); |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
173 SDL_RenderDrawLine(renderer, x1, y1, x2, y2); |
2997 | 174 } |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 static void |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
179 DrawRectRectIntersections(SDL_Window * window, SDL_Renderer * renderer) |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 int i, j; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 for (i = 0; i < num_rects; i++) |
2997 | 184 for (j = i + 1; j < num_rects; j++) { |
185 SDL_Rect r; | |
186 if (SDL_IntersectRect(&rects[i], &rects[j], &r)) { | |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
187 SDL_SetRenderDrawColor(renderer, 255, 200, 0, 255); |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
188 SDL_RenderFillRect(renderer, &r); |
2997 | 189 } |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 int |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 main(int argc, char *argv[]) |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 int mouse_begin_x = -1, mouse_begin_y = -1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 int i, done; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 SDL_Event event; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 Uint32 then, now, frames; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 /* Initialize parameters */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 num_objects = NUM_OBJECTS; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 /* Initialize test framework */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 state = CommonCreateState(argv, SDL_INIT_VIDEO); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 if (!state) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 return 1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
208 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 for (i = 1; i < argc;) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
210 int consumed; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 consumed = CommonArg(state, i); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 if (consumed == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 consumed = -1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
215 if (SDL_strcasecmp(argv[i], "--blend") == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 if (argv[i + 1]) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 if (SDL_strcasecmp(argv[i + 1], "none") == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
218 blendMode = SDL_BLENDMODE_NONE; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
219 consumed = 2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
220 } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 blendMode = SDL_BLENDMODE_BLEND; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 consumed = 2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
223 } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 blendMode = SDL_BLENDMODE_ADD; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 consumed = 2; |
5187
d976b67150c5
Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents:
5150
diff
changeset
|
226 } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) { |
d976b67150c5
Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents:
5150
diff
changeset
|
227 blendMode = SDL_BLENDMODE_MOD; |
d976b67150c5
Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents:
5150
diff
changeset
|
228 consumed = 2; |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 cycle_color = SDL_TRUE; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 consumed = 1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
235 cycle_alpha = SDL_TRUE; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 consumed = 1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
237 } else if (SDL_isdigit(*argv[i])) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 num_objects = SDL_atoi(argv[i]); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 consumed = 1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
240 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
241 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
242 if (consumed < 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 fprintf(stderr, |
5187
d976b67150c5
Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents:
5150
diff
changeset
|
244 "Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n", |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 argv[0], CommonUsage(state)); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
246 return 1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
247 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
248 i += consumed; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
249 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
250 if (!CommonInit(state)) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
251 return 2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
252 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
253 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
254 /* Create the windows and initialize the renderers */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
255 for (i = 0; i < state->num_windows; ++i) { |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
256 SDL_Renderer *renderer = state->renderers[i]; |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
257 SDL_SetRenderDrawBlendMode(renderer, blendMode); |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
258 SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF); |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
259 SDL_RenderClear(renderer); |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
260 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
261 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
262 srand(time(NULL)); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
263 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
264 /* Main render loop */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
265 frames = 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
266 then = SDL_GetTicks(); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
267 done = 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
268 while (!done) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
269 /* Check for events */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
270 ++frames; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 while (SDL_PollEvent(&event)) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 CommonEvent(state, &event, &done); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
273 switch (event.type) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
274 case SDL_MOUSEBUTTONDOWN: |
4465
3e69e077cb95
Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
275 mouse_begin_x = event.button.x; |
3e69e077cb95
Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
276 mouse_begin_y = event.button.y; |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 break; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
278 case SDL_MOUSEBUTTONUP: |
4465
3e69e077cb95
Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
279 if (event.button.button == 3) |
3e69e077cb95
Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
280 add_line(mouse_begin_x, mouse_begin_y, event.button.x, |
3e69e077cb95
Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
281 event.button.y); |
3e69e077cb95
Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
282 if (event.button.button == 1) |
3e69e077cb95
Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
283 add_rect(mouse_begin_x, mouse_begin_y, event.button.x, |
3e69e077cb95
Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
284 event.button.y); |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
285 break; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 case SDL_KEYDOWN: |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
287 switch (event.key.keysym.sym) { |
2997 | 288 case 'l': |
289 if (event.key.keysym.mod & KMOD_SHIFT) | |
290 num_lines = 0; | |
291 else | |
292 add_line(rand() % 640, rand() % 480, rand() % 640, | |
293 rand() % 480); | |
294 break; | |
295 case 'r': | |
296 if (event.key.keysym.mod & KMOD_SHIFT) | |
297 num_rects = 0; | |
298 else | |
299 add_rect(rand() % 640, rand() % 480, rand() % 640, | |
300 rand() % 480); | |
301 break; | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
302 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 break; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
304 default: |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 break; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 for (i = 0; i < state->num_windows; ++i) { |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
309 SDL_Renderer *renderer = state->renderers[i]; |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
310 SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF); |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
311 SDL_RenderClear(renderer); |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
313 DrawRects(state->windows[i], renderer); |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
314 DrawPoints(state->windows[i], renderer); |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
315 DrawRectRectIntersections(state->windows[i], renderer); |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
316 DrawLines(state->windows[i], renderer); |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
317 DrawRectLineIntersections(state->windows[i], renderer); |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
319 SDL_RenderPresent(renderer); |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
320 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
321 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
322 |
3371
438ba87e9578
Call CommonQuit() at exit has been added.
Mike Gorchak <lestat@i.com.ua>
parents:
2997
diff
changeset
|
323 CommonQuit(state); |
438ba87e9578
Call CommonQuit() at exit has been added.
Mike Gorchak <lestat@i.com.ua>
parents:
2997
diff
changeset
|
324 |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
325 /* Print out some timing information */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
326 now = SDL_GetTicks(); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
327 if (now > then) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
328 double fps = ((double) frames * 1000) / (now - then); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 printf("%2.2f frames per second\n", fps); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
330 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
331 return 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
332 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
333 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
334 /* vi: set ts=4 sw=4 expandtab: */ |