1 /*
2
3 TestABGR.c: test GFX behavior on byteordering
4
5 (C) A. Schiffler, 2005, zlib License
6
7 */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <math.h>
13 #include <time.h>
14
15 #include "SDL.h"
16
17 #ifdef WIN32
18 #include <windows.h>
19 #include "SDL_gfxPrimitives.h"
20 #else
21 #include "SDL/SDL_gfxPrimitives.h"
22 #endif
23
24 #define WIDTH 400
25 #define HEIGHT 424
26
WaitForEvent()27 void WaitForEvent()
28 {
29 int done;
30 SDL_Event event;
31
32 /* Check for events */
33 done = 0;
34 while (!done) {
35 SDL_PollEvent(&event);
36 switch (event.type) {
37 case SDL_KEYDOWN:
38 case SDL_QUIT:
39 done = 1;
40 break;
41 }
42 SDL_Delay(100);
43 }
44 }
45
main(int argc,char * argv[])46 int main(int argc, char *argv[])
47 {
48 SDL_Surface *screen;
49 Uint8 video_bpp;
50 Uint32 videoflags;
51 char title[64];
52 char message[64];
53 SDL_Rect r;
54 int y;
55 SDL_Surface* s;
56
57 /* Define masking bytes */
58 Uint32 mask1 = 0xff000000;
59 Uint32 mask2 = 0x00ff0000;
60 Uint32 mask3 = 0x0000ff00;
61 Uint32 mask4 = 0x000000ff;
62
63 /* Generate title+message strings */
64 sprintf (title, "TestABGR - v%i.%i.%i", SDL_GFXPRIMITIVES_MAJOR, SDL_GFXPRIMITIVES_MINOR, SDL_GFXPRIMITIVES_MICRO);
65 sprintf (message, "%s", "Left:RGBA Right:ABGR Top:Solid Bottom:Transparent");
66
67 /* Initialize SDL */
68 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
69 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
70 exit(1);
71 }
72 atexit(SDL_Quit);
73
74 video_bpp = 32;
75 videoflags = SDL_SWSURFACE | SDL_SRCALPHA | SDL_RESIZABLE;
76 while ( argc > 1 ) {
77 --argc;
78 if ( strcmp(argv[argc-1], "-bpp") == 0 ) {
79 video_bpp = atoi(argv[argc]);
80 --argc;
81 } else
82 if ( strcmp(argv[argc], "-hw") == 0 ) {
83 videoflags |= SDL_HWSURFACE;
84 } else
85 if ( strcmp(argv[argc], "-warp") == 0 ) {
86 videoflags |= SDL_HWPALETTE;
87 } else
88 if ( strcmp(argv[argc], "-fullscreen") == 0 ) {
89 videoflags |= SDL_FULLSCREEN;
90 } else {
91 fprintf(stderr,
92 "Usage: %s [-bpp N] [-warp] [-hw] [-fullscreen]\n",
93 argv[0]);
94 exit(1);
95 }
96 }
97
98 /* Set video mode */
99 if ( (screen=SDL_SetVideoMode(WIDTH, HEIGHT, video_bpp, videoflags)) == NULL ) {
100 fprintf(stderr, "Couldn't set %ix%i %i bpp video mode: %s\n",WIDTH,HEIGHT,video_bpp,SDL_GetError());
101 exit(2);
102 }
103
104 /* Use alpha blending */
105 SDL_SetAlpha(screen, SDL_SRCALPHA, 0);
106
107 /* Set title for window */
108 SDL_WM_SetCaption(title,title);
109
110 /* Draw some white stripes as background */
111 for (y=0; y<400; y += 20) {
112 boxRGBA(SDL_GetVideoSurface(), 0, y+10, 400, y+20, 255, 255, 255, 255);
113 }
114
115 /* Solid color test */
116 s = SDL_CreateRGBSurface(0, 200, 200, 32, mask1, mask2, mask3, mask4);
117 filledEllipseRGBA(s, 0, 0, 100, 100, 255, 0, 0, 255); // red
118 r.x = 0; r.y = 0;
119 SDL_BlitSurface(s, 0, SDL_GetVideoSurface(), &r);
120
121 s = SDL_CreateRGBSurface(0, 200, 200, 32, mask1, mask2, mask3, mask4);
122 filledEllipseRGBA(s, 0, 0, 100, 100, 0, 255, 0, 255); // green
123 r.x = 0; r.y = 100;
124 SDL_BlitSurface(s, 0, SDL_GetVideoSurface(), &r);
125
126 s = SDL_CreateRGBSurface(0, 200, 200, 32, mask1, mask2, mask3, mask4);
127 filledEllipseRGBA(s, 0, 0, 100, 100, 0, 0, 255, 255); // blue
128 r.x = 100; r.y = 0;
129 SDL_BlitSurface(s, 0, SDL_GetVideoSurface(), &r);
130
131 s = SDL_CreateRGBSurface(0, 200, 200, 32, mask1, mask2, mask3, mask4);
132 filledEllipseRGBA(s, 0, 0, 100, 100, 255, 255, 255, 255); // white
133 r.x = 100; r.y = 100;
134 SDL_BlitSurface(s, 0, SDL_GetVideoSurface(), &r);
135
136 s = SDL_CreateRGBSurface(0, 200, 200, 32, mask4, mask3, mask2, mask1);
137 filledEllipseRGBA(s, 0, 0, 100, 100, 255, 0, 0, 255); // red
138 r.x = 200; r.y = 0;
139 SDL_BlitSurface(s, 0, SDL_GetVideoSurface(), &r);
140
141 s = SDL_CreateRGBSurface(0, 200, 200, 32, mask4, mask3, mask2, mask1);
142 filledEllipseRGBA(s, 0, 0, 100, 100, 0, 255, 0, 255); // green
143 r.x = 200; r.y = 100;
144 SDL_BlitSurface(s, 0, SDL_GetVideoSurface(), &r);
145
146 s = SDL_CreateRGBSurface(0, 200, 200, 32, mask4, mask3, mask2, mask1);
147 filledEllipseRGBA(s, 0, 0, 100, 100, 0, 0, 255, 255); // blue
148 r.x = 300; r.y = 0;
149 SDL_BlitSurface(s, 0, SDL_GetVideoSurface(), &r);
150
151 s = SDL_CreateRGBSurface(0, 200, 200, 32, mask4, mask3, mask2, mask1);
152 filledEllipseRGBA(s, 0, 0, 100, 100, 255, 255, 255, 255); // white
153 r.x = 300; r.y = 100;
154 SDL_BlitSurface(s, 0, SDL_GetVideoSurface(), &r);
155
156
157 /* Transparent color test */
158 s = SDL_CreateRGBSurface(0, 200, 200, 32, mask1, mask2, mask3, mask4);
159 filledEllipseRGBA(s, 0, 0, 100, 100, 255, 0, 0, 200); // red+trans
160 r.x = 0; r.y = 200;
161 SDL_BlitSurface(s, 0, SDL_GetVideoSurface(), &r);
162
163 s = SDL_CreateRGBSurface(0, 200, 200, 32, mask1, mask2, mask3, mask4);
164 filledEllipseRGBA(s, 0, 0, 100, 100, 0, 255, 0, 200); // green+trans
165 r.x = 0; r.y = 300;
166 SDL_BlitSurface(s, 0, SDL_GetVideoSurface(), &r);
167
168 s = SDL_CreateRGBSurface(0, 200, 200, 32, mask1, mask2, mask3, mask4);
169 filledEllipseRGBA(s, 0, 0, 100, 100, 0, 0, 255, 200); // blue+trans
170 r.x = 100; r.y = 200;
171 SDL_BlitSurface(s, 0, SDL_GetVideoSurface(), &r);
172
173 s = SDL_CreateRGBSurface(0, 200, 200, 32, mask1, mask2, mask3, mask4);
174 filledEllipseRGBA(s, 0, 0, 100, 100, 255, 255, 255, 200); // white+trans
175 r.x = 100; r.y = 300;
176 SDL_BlitSurface(s, 0, SDL_GetVideoSurface(), &r);
177
178 s = SDL_CreateRGBSurface(0, 200, 200, 32, mask4, mask3, mask2, mask1);
179 filledEllipseRGBA(s, 0, 0, 100, 100, 255, 0, 0, 200); // red+trans
180 r.x = 200; r.y = 200;
181 SDL_BlitSurface(s, 0, SDL_GetVideoSurface(), &r);
182
183 s = SDL_CreateRGBSurface(0, 200, 200, 32, mask4, mask3, mask2, mask1);
184 filledEllipseRGBA(s, 0, 0, 100, 100, 0, 255, 0, 200); // green+trans
185 r.x = 200; r.y = 300;
186 SDL_BlitSurface(s, 0, SDL_GetVideoSurface(), &r);
187
188 s = SDL_CreateRGBSurface(0, 200, 200, 32, mask4, mask3, mask2, mask1);
189 filledEllipseRGBA(s, 0, 0, 100, 100, 0, 0, 255, 200); // blue+trans
190 r.x = 300; r.y = 200;
191 SDL_BlitSurface(s, 0, SDL_GetVideoSurface(), &r);
192
193 s = SDL_CreateRGBSurface(0, 200, 200, 32, mask4, mask3, mask2, mask1);
194 filledEllipseRGBA(s, 0, 0, 100, 100, 255, 255, 255, 200); // white+trans
195 r.x = 300; r.y = 300;
196 SDL_BlitSurface(s, 0, SDL_GetVideoSurface(), &r);
197
198 stringRGBA (screen, WIDTH/2-4*strlen(message),HEIGHT-12,message,255,255,255,255);
199
200 SDL_Flip(SDL_GetVideoSurface());
201
202 WaitForEvent();
203
204 return 0;
205 }
206