annotate test/testdraw2.c @ 5275:7aba0406c273

Frank Zago to sdl The following patch fixes some of the bitrot for the Nintendo DS port. The support is still basic at the moment, but it allows to run the "general" test under the current head of tree (parent: 5269:11bd1585efb5 tip). Most of the patch is mine, but I integrated a couple changes that John Magnotti posted on Feb 1st.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 12 Feb 2011 11:36:56 -0800
parents d976b67150c5
children
rev   line source
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 /* Simple program: draw as many random objects on the screen as possible */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 #include <stdlib.h>
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 #include <stdio.h>
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 #include <time.h>
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 #include "common.h"
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 #define NUM_OBJECTS 100
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 static CommonState *state;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 static int num_objects;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14 static SDL_bool cycle_color;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 static SDL_bool cycle_alpha;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 static int cycle_direction = 1;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 static int current_alpha = 255;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18 static int current_color = 255;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 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
22 DrawPoints(SDL_Window * window, SDL_Renderer * renderer)
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 int i;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 int x, y;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 int window_w, window_h;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 /* Query the sizes */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 SDL_GetWindowSize(window, &window_w, &window_h);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30
2902
83c3a4b0e421 Fixed crash in testdraw2, added more points
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
31 for (i = 0; i < num_objects * 4; ++i) {
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 /* Cycle the color and alpha, if desired */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 if (cycle_color) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 current_color += cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 if (current_color < 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 current_color = 0;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 if (current_color > 255) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 current_color = 255;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 if (cycle_alpha) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 current_alpha += cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 if (current_alpha < 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 current_alpha = 0;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 if (current_alpha > 255) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 current_alpha = 255;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 }
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
55 SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 (Uint8) current_color, (Uint8) current_alpha);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 x = rand() % window_w;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 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
60 SDL_RenderDrawPoint(renderer, x, y);
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 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
65 DrawLines(SDL_Window * window, SDL_Renderer * renderer)
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 int i;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 int x1, y1, x2, y2;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 int window_w, window_h;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 /* Query the sizes */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 SDL_GetWindowSize(window, &window_w, &window_h);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 for (i = 0; i < num_objects; ++i) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 /* Cycle the color and alpha, if desired */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 if (cycle_color) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 current_color += cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 if (current_color < 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 current_color = 0;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 if (current_color > 255) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 current_color = 255;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 if (cycle_alpha) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 current_alpha += cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 if (current_alpha < 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 current_alpha = 0;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 if (current_alpha > 255) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 current_alpha = 255;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 }
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
98 SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 (Uint8) current_color, (Uint8) current_alpha);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 if (i == 0) {
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
102 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
103 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
104 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
105 SDL_RenderDrawLine(renderer, window_w / 2, 0, window_w / 2, window_h - 1);
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 } else {
3546
65848493e08e Allow points to be outside the window bounds, stress testing the clipping code.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
107 x1 = (rand() % (window_w*2)) - window_w;
65848493e08e Allow points to be outside the window bounds, stress testing the clipping code.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
108 x2 = (rand() % (window_w*2)) - window_w;
65848493e08e Allow points to be outside the window bounds, stress testing the clipping code.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
109 y1 = (rand() % (window_h*2)) - window_h;
65848493e08e Allow points to be outside the window bounds, stress testing the clipping code.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
110 y2 = (rand() % (window_h*2)) - 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
111 SDL_RenderDrawLine(renderer, x1, y1, x2, y2);
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 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
117 DrawRects(SDL_Window * window, SDL_Renderer * renderer)
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 int i;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 SDL_Rect rect;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 int window_w, window_h;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 /* Query the sizes */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 SDL_GetWindowSize(window, &window_w, &window_h);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125
2902
83c3a4b0e421 Fixed crash in testdraw2, added more points
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
126 for (i = 0; i < num_objects / 4; ++i) {
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 /* Cycle the color and alpha, if desired */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 if (cycle_color) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 current_color += cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 if (current_color < 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 current_color = 0;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 if (current_color > 255) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 current_color = 255;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 if (cycle_alpha) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 current_alpha += cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 if (current_alpha < 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 current_alpha = 0;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 if (current_alpha > 255) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 current_alpha = 255;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 }
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
150 SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 (Uint8) current_color, (Uint8) current_alpha);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 rect.w = rand() % (window_h / 2);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 rect.h = rand() % (window_h / 2);
3546
65848493e08e Allow points to be outside the window bounds, stress testing the clipping code.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
155 rect.x = (rand() % (window_w*2) - window_w) - (rect.w / 2);
65848493e08e Allow points to be outside the window bounds, stress testing the clipping code.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
156 rect.y = (rand() % (window_h*2) - window_h) - (rect.h / 2);
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
157 SDL_RenderFillRect(renderer, &rect);
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 int
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 main(int argc, char *argv[])
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 int i, done;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 SDL_Event event;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 Uint32 then, now, frames;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 /* Initialize parameters */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 num_objects = NUM_OBJECTS;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 /* Initialize test framework */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 state = CommonCreateState(argv, SDL_INIT_VIDEO);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 if (!state) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 return 1;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 for (i = 1; i < argc;) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 int consumed;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 consumed = CommonArg(state, i);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 if (consumed == 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 consumed = -1;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 if (SDL_strcasecmp(argv[i], "--blend") == 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 if (argv[i + 1]) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 blendMode = SDL_BLENDMODE_NONE;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 consumed = 2;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 blendMode = SDL_BLENDMODE_BLEND;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 consumed = 2;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 blendMode = SDL_BLENDMODE_ADD;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 consumed = 2;
5187
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5150
diff changeset
193 } 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
194 blendMode = SDL_BLENDMODE_MOD;
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5150
diff changeset
195 consumed = 2;
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 cycle_color = SDL_TRUE;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 consumed = 1;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 cycle_alpha = SDL_TRUE;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 consumed = 1;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 } else if (SDL_isdigit(*argv[i])) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 num_objects = SDL_atoi(argv[i]);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 consumed = 1;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 if (consumed < 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 fprintf(stderr,
5187
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5150
diff changeset
211 "Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n",
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 argv[0], CommonUsage(state));
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 return 1;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 i += consumed;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 if (!CommonInit(state)) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 return 2;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 /* Create the windows and initialize the renderers */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 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
223 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
224 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
225 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
226 SDL_RenderClear(renderer);
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228
4884
27ab20a36eba - added directx include path to VS2008 solution
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 3685
diff changeset
229 srand((unsigned int)time(NULL));
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 /* Main render loop */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 frames = 0;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 then = SDL_GetTicks();
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 done = 0;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 while (!done) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 /* Check for events */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 ++frames;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238 while (SDL_PollEvent(&event)) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 CommonEvent(state, &event, &done);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 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
242 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
243 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
244 SDL_RenderClear(renderer);
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245
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
246 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
247 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
248 DrawPoints(state->windows[i], renderer);
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249
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
250 SDL_RenderPresent(renderer);
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253
3371
438ba87e9578 Call CommonQuit() at exit has been added.
Mike Gorchak <lestat@i.com.ua>
parents: 2902
diff changeset
254 CommonQuit(state);
438ba87e9578 Call CommonQuit() at exit has been added.
Mike Gorchak <lestat@i.com.ua>
parents: 2902
diff changeset
255
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 /* Print out some timing information */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 now = SDL_GetTicks();
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 if (now > then) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 double fps = ((double) frames * 1000) / (now - then);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 printf("%2.2f frames per second\n", fps);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 return 0;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 /* vi: set ts=4 sw=4 expandtab: */