SDL 2.0
testoverlay2.c File Reference
#include "SDL.h"
#include "testyuv_cvt.h"
+ Include dependency graph for testoverlay2.c:

Go to the source code of this file.

Macros

#define MOOSEPIC_W   64
 
#define MOOSEPIC_H   88
 
#define MOOSEFRAME_SIZE   (MOOSEPIC_W * MOOSEPIC_H)
 
#define MOOSEFRAMES_COUNT   10
 

Functions

static void quit (int rc)
 
static void PrintUsage (char *argv0)
 
void loop ()
 
int main (int argc, char **argv)
 

Variables

SDL_Color MooseColors [84]
 
Uint8 MooseFrame [MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE *2]
 
SDL_TextureMooseTexture
 
SDL_Rect displayrect
 
int window_w
 
int window_h
 
SDL_Windowwindow
 
SDL_Rendererrenderer
 
int paused = 0
 
int i
 
SDL_bool done = SDL_FALSE
 
static int fpsdelay
 

Macro Definition Documentation

◆ MOOSEFRAME_SIZE

#define MOOSEFRAME_SIZE   (MOOSEPIC_W * MOOSEPIC_H)

Definition at line 30 of file testoverlay2.c.

◆ MOOSEFRAMES_COUNT

#define MOOSEFRAMES_COUNT   10

Definition at line 31 of file testoverlay2.c.

◆ MOOSEPIC_H

#define MOOSEPIC_H   88

Definition at line 28 of file testoverlay2.c.

◆ MOOSEPIC_W

#define MOOSEPIC_W   64

Definition at line 27 of file testoverlay2.c.

Function Documentation

◆ loop()

void loop ( void  )

Definition at line 178 of file testoverlay2.c.

179{
181
182 while (SDL_PollEvent(&event)) {
183 switch (event.type) {
184 case SDL_WINDOWEVENT:
185 if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
187 displayrect.w = window_w = event.window.data1;
188 displayrect.h = window_h = event.window.data2;
189 }
190 break;
192 displayrect.x = event.button.x - window_w / 2;
193 displayrect.y = event.button.y - window_h / 2;
194 break;
195 case SDL_MOUSEMOTION:
196 if (event.motion.state) {
197 displayrect.x = event.motion.x - window_w / 2;
198 displayrect.y = event.motion.y - window_h / 2;
199 }
200 break;
201 case SDL_KEYDOWN:
202 if (event.key.keysym.sym == SDLK_SPACE) {
203 paused = !paused;
204 break;
205 }
206 if (event.key.keysym.sym != SDLK_ESCAPE) {
207 break;
208 }
209 case SDL_QUIT:
210 done = SDL_TRUE;
211 break;
212 }
213 }
214
215#ifndef __EMSCRIPTEN__
217#endif
218
219 if (!paused) {
220 i = (i + 1) % MOOSEFRAMES_COUNT;
221
223 }
227
228#ifdef __EMSCRIPTEN__
229 if (done) {
230 emscripten_cancel_main_loop();
231 }
232#endif
233}
#define SDL_RenderPresent
#define SDL_PollEvent
#define SDL_UpdateTexture
#define SDL_RenderClear
#define SDL_Delay
#define SDL_RenderCopy
#define SDL_RenderSetViewport
@ SDL_MOUSEMOTION
Definition: SDL_events.h:105
@ SDL_QUIT
Definition: SDL_events.h:60
@ SDL_WINDOWEVENT
Definition: SDL_events.h:92
@ SDL_MOUSEBUTTONDOWN
Definition: SDL_events.h:106
@ SDL_KEYDOWN
Definition: SDL_events.h:96
@ SDLK_ESCAPE
Definition: SDL_keycode.h:55
@ SDLK_SPACE
Definition: SDL_keycode.h:58
struct _cl_event * event
@ SDL_TRUE
Definition: SDL_stdinc.h:164
@ SDL_WINDOWEVENT_RESIZED
Definition: SDL_video.h:155
#define NULL
Definition: begin_code.h:167
int h
Definition: SDL_rect.h:80
int w
Definition: SDL_rect.h:80
int y
Definition: SDL_rect.h:79
int x
Definition: SDL_rect.h:79
#define MOOSEFRAMES_COUNT
Definition: testoverlay2.c:31
SDL_Rect displayrect
Definition: testoverlay2.c:142
#define MOOSEPIC_W
Definition: testoverlay2.c:27
Uint8 MooseFrame[MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE *2]
Definition: testoverlay2.c:140
SDL_Texture * MooseTexture
Definition: testoverlay2.c:141
int window_w
Definition: testoverlay2.c:143
int window_h
Definition: testoverlay2.c:144
int paused
Definition: testoverlay2.c:147
SDL_Renderer * renderer
Definition: testoverlay2.c:146
SDL_bool done
Definition: testoverlay2.c:149
static int fpsdelay
Definition: testoverlay2.c:150
int i
Definition: testoverlay2.c:148
General event structure.
Definition: SDL_events.h:558

References displayrect, done, fpsdelay, SDL_Rect::h, i, MooseFrame, MOOSEFRAMES_COUNT, MOOSEPIC_W, MooseTexture, NULL, paused, renderer, SDL_Delay, SDL_KEYDOWN, SDL_MOUSEBUTTONDOWN, SDL_MOUSEMOTION, SDL_PollEvent, SDL_QUIT, SDL_RenderClear, SDL_RenderCopy, SDL_RenderPresent, SDL_RenderSetViewport, SDL_TRUE, SDL_UpdateTexture, SDL_WINDOWEVENT, SDL_WINDOWEVENT_RESIZED, SDLK_ESCAPE, SDLK_SPACE, SDL_Rect::w, window_h, window_w, SDL_Rect::x, and SDL_Rect::y.

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 236 of file testoverlay2.c.

237{
238 Uint8 *RawMooseData;
241 int j;
242 int fps = 12;
243 int nodelay = 0;
244 int scale = 5;
245
246 /* Enable standard application logging */
248
249 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
250 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
251 return 3;
252 }
253
254 while (argc > 1) {
255 if (SDL_strcmp(argv[1], "-fps") == 0) {
256 if (argv[2]) {
257 fps = SDL_atoi(argv[2]);
258 if (fps == 0) {
260 "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
261 quit(10);
262 }
263 if ((fps < 0) || (fps > 1000)) {
265 "The -fps option must be in range from 1 to 1000, default is 12.\n");
266 quit(10);
267 }
268 argv += 2;
269 argc -= 2;
270 } else {
272 "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
273 quit(10);
274 }
275 } else if (SDL_strcmp(argv[1], "-nodelay") == 0) {
276 nodelay = 1;
277 argv += 1;
278 argc -= 1;
279 } else if (SDL_strcmp(argv[1], "-scale") == 0) {
280 if (argv[2]) {
281 scale = SDL_atoi(argv[2]);
282 if (scale == 0) {
284 "The -scale option requires an argument [from 1 to 50], default is 5.\n");
285 quit(10);
286 }
287 if ((scale < 0) || (scale > 50)) {
289 "The -scale option must be in range from 1 to 50, default is 5.\n");
290 quit(10);
291 }
292 argv += 2;
293 argc -= 2;
294 } else {
296 "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
297 quit(10);
298 }
299 } else if ((SDL_strcmp(argv[1], "-help") == 0)
300 || (SDL_strcmp(argv[1], "-h") == 0)) {
301 PrintUsage(argv[0]);
302 quit(0);
303 } else {
304 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unrecognized option: %s.\n", argv[1]);
305 quit(10);
306 }
307 break;
308 }
309
311 if (RawMooseData == NULL) {
312 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't allocate memory for movie !\n");
313 quit(1);
314 }
315
316 /* load the trojan moose images */
317 handle = SDL_RWFromFile("moose.dat", "rb");
318 if (handle == NULL) {
319 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't find the file moose.dat !\n");
320 SDL_free(RawMooseData);
321 quit(2);
322 }
323
325
327
328 /* Create the window and renderer */
331 window = SDL_CreateWindow("Happy Moose",
336 if (!window) {
337 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError());
338 SDL_free(RawMooseData);
339 quit(4);
340 }
341
343 if (!renderer) {
344 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError());
345 SDL_free(RawMooseData);
346 quit(4);
347 }
348
350 if (!MooseTexture) {
351 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
352 SDL_free(RawMooseData);
353 quit(5);
354 }
355 /* Uncomment this to check vertex color with a YUV texture */
356 /* SDL_SetTextureColorMod(MooseTexture, 0xff, 0x80, 0x80); */
357
358 for (i = 0; i < MOOSEFRAMES_COUNT; i++) {
359 Uint8 MooseFrameRGB[MOOSEFRAME_SIZE*3];
360 Uint8 *rgb;
361 Uint8 *frame;
362
363 rgb = MooseFrameRGB;
364 frame = RawMooseData + i * MOOSEFRAME_SIZE;
365 for (j = 0; j < MOOSEFRAME_SIZE; ++j) {
366 rgb[0] = MooseColors[frame[j]].r;
367 rgb[1] = MooseColors[frame[j]].g;
368 rgb[2] = MooseColors[frame[j]].b;
369 rgb += 3;
370 }
373 0, 100);
374 }
375
376 SDL_free(RawMooseData);
377
378 /* set the start frame */
379 i = 0;
380 if (nodelay) {
381 fpsdelay = 0;
382 } else {
383 fpsdelay = 1000 / fps;
384 }
385
386 displayrect.x = 0;
387 displayrect.y = 0;
390
391 /* Ignore key up events, they don't even get filtered */
393
394 /* Loop, waiting for QUIT or RESIZE */
395#ifdef __EMSCRIPTEN__
396 emscripten_set_main_loop(loop, nodelay ? 0 : fps, 1);
397#else
398 while (!done) {
399 loop();
400 }
401#endif
402
404 quit(0);
405 return 0;
406}
#define SDL_INIT_VIDEO
Definition: SDL.h:79
#define SDL_GetError
#define SDL_DestroyRenderer
#define SDL_CreateWindow
#define SDL_CreateTexture
#define SDL_GetYUVConversionModeForResolution
#define SDL_CreateRenderer
#define SDL_RWread
#define SDL_malloc
#define SDL_EventState
#define SDL_LogSetPriority
#define SDL_LogError
#define SDL_free
#define SDL_strcmp
#define SDL_RWFromFile
#define SDL_Init
#define SDL_atoi
#define SDL_RWclose
@ SDL_KEYUP
Definition: SDL_events.h:97
#define SDL_IGNORE
Definition: SDL_events.h:757
@ SDL_LOG_PRIORITY_INFO
Definition: SDL_log.h:106
@ SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66
GLenum GLenum GLenum GLenum GLenum scale
@ SDL_PIXELFORMAT_YV12
Definition: SDL_pixels.h:277
@ SDL_TEXTUREACCESS_STREAMING
Definition: SDL_render.h:94
uint8_t Uint8
Definition: SDL_stdinc.h:179
#define SDL_WINDOWPOS_UNDEFINED
Definition: SDL_video.h:130
@ SDL_WINDOW_RESIZABLE
Definition: SDL_video.h:105
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
Definition: SDL_x11sym.h:50
EGLImageKHR EGLint EGLint * handle
Definition: eglext.h:937
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
Uint8 r
Definition: SDL_pixels.h:297
Uint8 b
Definition: SDL_pixels.h:299
Uint8 g
Definition: SDL_pixels.h:298
The type used to identify a window.
Definition: SDL_sysvideo.h:74
#define MOOSEPIC_H
Definition: testoverlay2.c:28
static void quit(int rc)
Definition: testoverlay2.c:154
static void PrintUsage(char *argv0)
Definition: testoverlay2.c:161
SDL_Color MooseColors[84]
Definition: testoverlay2.c:33
SDL_Window * window
Definition: testoverlay2.c:145
#define MOOSEFRAME_SIZE
Definition: testoverlay2.c:30
void loop()
Definition: testoverlay2.c:178
int frame
Definition: teststreaming.c:60
SDL_bool ConvertRGBtoYUV(Uint32 format, Uint8 *src, int pitch, Uint8 *out, int w, int h, SDL_YUV_CONVERSION_MODE mode, int monochrome, int luminance)
Definition: testyuv_cvt.c:262

References SDL_Color::b, ConvertRGBtoYUV(), displayrect, done, fpsdelay, frame, SDL_Color::g, SDL_Rect::h, i, j, loop(), MooseColors, MooseFrame, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT, MOOSEPIC_H, MOOSEPIC_W, MooseTexture, NULL, PrintUsage(), quit(), SDL_Color::r, renderer, SDL_atoi, SDL_CreateRenderer, SDL_CreateTexture, SDL_CreateWindow, SDL_DestroyRenderer, SDL_EventState, SDL_free, SDL_GetError, SDL_GetYUVConversionModeForResolution, SDL_IGNORE, SDL_Init, SDL_INIT_VIDEO, SDL_KEYUP, SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, SDL_LogError, SDL_LogSetPriority, SDL_malloc, SDL_PIXELFORMAT_YV12, SDL_RWclose, SDL_RWFromFile, SDL_RWread, SDL_strcmp, SDL_TEXTUREACCESS_STREAMING, SDL_WINDOW_RESIZABLE, SDL_WINDOWPOS_UNDEFINED, SDL_Rect::w, window, window_h, window_w, SDL_Rect::x, and SDL_Rect::y.

◆ PrintUsage()

static void PrintUsage ( char *  argv0)
static

Definition at line 161 of file testoverlay2.c.

162{
163 SDL_Log("Usage: %s [arg] [arg] [arg] ...\n", argv0);
164 SDL_Log("\n");
165 SDL_Log("Where 'arg' is any of the following options:\n");
166 SDL_Log("\n");
167 SDL_Log(" -fps <frames per second>\n");
168 SDL_Log(" -nodelay\n");
169 SDL_Log(" -format <fmt> (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n");
170 SDL_Log(" -scale <scale factor> (initial scale of the overlay)\n");
171 SDL_Log(" -help (shows this help)\n");
172 SDL_Log("\n");
173 SDL_Log("Press ESC to exit, or SPACE to freeze the movie while application running.\n");
174 SDL_Log("\n");
175}
#define SDL_Log

References SDL_Log.

Referenced by main().

◆ quit()

static void quit ( int  rc)
static

Definition at line 154 of file testoverlay2.c.

155{
156 SDL_Quit();
157 exit(rc);
158}
#define SDL_Quit

References SDL_Quit.

Referenced by main().

Variable Documentation

◆ displayrect

SDL_Rect displayrect

Definition at line 142 of file testoverlay2.c.

Referenced by loop(), and main().

◆ done

Definition at line 149 of file testoverlay2.c.

Referenced by loop(), and main().

◆ fpsdelay

int fpsdelay
static

Definition at line 150 of file testoverlay2.c.

Referenced by loop(), and main().

◆ i

int i

Definition at line 148 of file testoverlay2.c.

Referenced by loop(), and main().

◆ MooseColors

SDL_Color MooseColors[84]

Definition at line 33 of file testoverlay2.c.

Referenced by main().

◆ MooseFrame

Definition at line 140 of file testoverlay2.c.

Referenced by loop(), and main().

◆ MooseTexture

SDL_Texture* MooseTexture

Definition at line 141 of file testoverlay2.c.

Referenced by loop(), and main().

◆ paused

int paused = 0

Definition at line 147 of file testoverlay2.c.

Referenced by loop().

◆ renderer

SDL_Renderer* renderer

Definition at line 146 of file testoverlay2.c.

Referenced by loop(), and main().

◆ window

Definition at line 145 of file testoverlay2.c.

Referenced by main().

◆ window_h

int window_h

Definition at line 144 of file testoverlay2.c.

Referenced by loop(), main(), MoveSprites(), and SDL_CreateRenderer().

◆ window_w

int window_w

Definition at line 143 of file testoverlay2.c.

Referenced by loop(), main(), MoveSprites(), and SDL_CreateRenderer().