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

#define MOOSEFRAME_SIZE   (MOOSEPIC_W * MOOSEPIC_H)

Definition at line 30 of file testoverlay2.c.

Referenced by main().

#define MOOSEFRAMES_COUNT   10

Definition at line 31 of file testoverlay2.c.

Referenced by loop(), and main().

#define MOOSEPIC_H   88

Definition at line 28 of file testoverlay2.c.

Referenced by main().

#define MOOSEPIC_W   64

Definition at line 27 of file testoverlay2.c.

Referenced by loop(), and main().

Function Documentation

void loop ( )

Definition at line 178 of file testoverlay2.c.

References done, SDL_WindowEvent::event, fpsdelay, SDL_Rect::h, i, SDL_Event::key, SDL_KeyboardEvent::keysym, MooseFrame, MOOSEFRAMES_COUNT, MOOSEPIC_W, SDL_Event::motion, NULL, paused, 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_MouseMotionEvent::state, SDL_Keysym::sym, SDL_Event::type, SDL_Rect::w, SDL_Event::window, window_h, window_w, SDL_Rect::x, and SDL_Rect::y.

{
while (SDL_PollEvent(&event)) {
switch (event.type) {
displayrect.w = window_w = event.window.data1;
displayrect.h = window_h = event.window.data2;
}
break;
displayrect.x = event.button.x - window_w / 2;
displayrect.y = event.button.y - window_h / 2;
break;
if (event.motion.state) {
displayrect.x = event.motion.x - window_w / 2;
displayrect.y = event.motion.y - window_h / 2;
}
break;
if (event.key.keysym.sym == SDLK_SPACE) {
break;
}
if (event.key.keysym.sym != SDLK_ESCAPE) {
break;
}
case SDL_QUIT:
break;
}
}
#ifndef __EMSCRIPTEN__
#endif
if (!paused) {
i = (i + 1) % MOOSEFRAMES_COUNT;
}
#ifdef __EMSCRIPTEN__
if (done) {
emscripten_cancel_main_loop();
}
#endif
}
int main ( int  argc,
char **  argv 
)

Definition at line 236 of file testoverlay2.c.

References SDL_Color::b, ConvertRGBtoYUV(), done, fpsdelay, frame, free, SDL_Color::g, SDL_Rect::h, i, j, loop(), malloc, MooseFrame, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT, MOOSEPIC_H, MOOSEPIC_W, NULL, PrintUsage(), quit(), SDL_Color::r, SDL_atoi, SDL_CreateRenderer, SDL_CreateTexture, SDL_CreateWindow, SDL_DestroyRenderer, SDL_EventState, 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_PIXELFORMAT_YV12, SDL_RWclose, SDL_RWFromFile, SDL_RWread, SDL_TEXTUREACCESS_STREAMING, SDL_WINDOW_RESIZABLE, SDL_WINDOWPOS_UNDEFINED, SDL_Rect::w, window_h, window_w, SDL_Rect::x, and SDL_Rect::y.

{
Uint8 *RawMooseData;
int j;
int fps = 12;
int nodelay = 0;
int scale = 5;
/* Enable standard application logging */
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 3;
}
while (argc > 1) {
if (strcmp(argv[1], "-fps") == 0) {
if (argv[2]) {
fps = SDL_atoi(argv[2]);
if (fps == 0) {
"The -fps option requires an argument [from 1 to 1000], default is 12.\n");
quit(10);
}
if ((fps < 0) || (fps > 1000)) {
"The -fps option must be in range from 1 to 1000, default is 12.\n");
quit(10);
}
argv += 2;
argc -= 2;
} else {
"The -fps option requires an argument [from 1 to 1000], default is 12.\n");
quit(10);
}
} else if (strcmp(argv[1], "-nodelay") == 0) {
nodelay = 1;
argv += 1;
argc -= 1;
} else if (strcmp(argv[1], "-scale") == 0) {
if (argv[2]) {
scale = SDL_atoi(argv[2]);
if (scale == 0) {
"The -scale option requires an argument [from 1 to 50], default is 5.\n");
quit(10);
}
if ((scale < 0) || (scale > 50)) {
"The -scale option must be in range from 1 to 50, default is 5.\n");
quit(10);
}
argv += 2;
argc -= 2;
} else {
"The -fps option requires an argument [from 1 to 1000], default is 12.\n");
quit(10);
}
} else if ((strcmp(argv[1], "-help") == 0)
|| (strcmp(argv[1], "-h") == 0)) {
PrintUsage(argv[0]);
quit(0);
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unrecognized option: %s.\n", argv[1]);
quit(10);
}
break;
}
if (RawMooseData == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't allocate memory for movie !\n");
quit(1);
}
/* load the trojan moose images */
handle = SDL_RWFromFile("moose.dat", "rb");
if (handle == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't find the file moose.dat !\n");
free(RawMooseData);
quit(2);
}
SDL_RWread(handle, RawMooseData, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT);
SDL_RWclose(handle);
/* Create the window and renderer */
window = SDL_CreateWindow("Happy Moose",
if (!window) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError());
free(RawMooseData);
quit(4);
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (!renderer) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError());
free(RawMooseData);
quit(4);
}
if (!MooseTexture) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
free(RawMooseData);
quit(5);
}
/* Uncomment this to check vertex color with a YUV texture */
/* SDL_SetTextureColorMod(MooseTexture, 0xff, 0x80, 0x80); */
for (i = 0; i < MOOSEFRAMES_COUNT; i++) {
Uint8 MooseFrameRGB[MOOSEFRAME_SIZE*3];
Uint8 *rgb;
rgb = MooseFrameRGB;
frame = RawMooseData + i * MOOSEFRAME_SIZE;
for (j = 0; j < MOOSEFRAME_SIZE; ++j) {
rgb[0] = MooseColors[frame[j]].r;
rgb[1] = MooseColors[frame[j]].g;
rgb[2] = MooseColors[frame[j]].b;
rgb += 3;
}
0, 100);
}
free(RawMooseData);
/* set the start frame */
i = 0;
if (nodelay) {
fpsdelay = 0;
} else {
fpsdelay = 1000 / fps;
}
/* Ignore key up events, they don't even get filtered */
/* Loop, waiting for QUIT or RESIZE */
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, nodelay ? 0 : fps, 1);
#else
while (!done) {
loop();
}
#endif
quit(0);
return 0;
}
static void PrintUsage ( char *  argv0)
static

Definition at line 161 of file testoverlay2.c.

References SDL_Log.

Referenced by main().

{
SDL_Log("Usage: %s [arg] [arg] [arg] ...\n", argv0);
SDL_Log("\n");
SDL_Log("Where 'arg' is any of the following options:\n");
SDL_Log("\n");
SDL_Log(" -fps <frames per second>\n");
SDL_Log(" -nodelay\n");
SDL_Log(" -format <fmt> (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n");
SDL_Log(" -scale <scale factor> (initial scale of the overlay)\n");
SDL_Log(" -help (shows this help)\n");
SDL_Log("\n");
SDL_Log("Press ESC to exit, or SPACE to freeze the movie while application running.\n");
SDL_Log("\n");
}
static void quit ( int  rc)
static

Definition at line 154 of file testoverlay2.c.

References SDL_Quit.

{
exit(rc);
}

Variable Documentation

SDL_Rect displayrect

Definition at line 142 of file testoverlay2.c.

Definition at line 149 of file testoverlay2.c.

int fpsdelay
static

Definition at line 150 of file testoverlay2.c.

Referenced by loop(), and main().

int i

Definition at line 148 of file testoverlay2.c.

SDL_Color MooseColors[84]

Definition at line 33 of file testoverlay2.c.

Definition at line 140 of file testoverlay2.c.

Referenced by loop(), and main().

SDL_Texture* MooseTexture

Definition at line 141 of file testoverlay2.c.

int paused = 0

Definition at line 147 of file testoverlay2.c.

Referenced by loop().

SDL_Renderer* renderer

Definition at line 146 of file testoverlay2.c.

Definition at line 145 of file testoverlay2.c.

int window_h

Definition at line 144 of file testoverlay2.c.

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

int window_w

Definition at line 143 of file testoverlay2.c.

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