SDL  2.0
teststreaming.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include "SDL.h"
+ Include dependency graph for teststreaming.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

void quit (int rc)
void UpdateTexture (SDL_Texture *texture, int frame)
void loop ()
int main (int argc, char **argv)

Variables

SDL_Color MooseColors [84]
Uint8 MooseFrames [MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE]
SDL_Rendererrenderer
int frame
SDL_TextureMooseTexture
SDL_bool done = SDL_FALSE

Macro Definition Documentation

#define MOOSEFRAME_SIZE   (MOOSEPIC_W * MOOSEPIC_H)

Definition at line 30 of file teststreaming.c.

Referenced by main().

#define MOOSEFRAMES_COUNT   10

Definition at line 31 of file teststreaming.c.

Referenced by loop(), and main().

#define MOOSEPIC_H   88

Definition at line 28 of file teststreaming.c.

Referenced by main(), and UpdateTexture().

#define MOOSEPIC_W   64

Definition at line 27 of file teststreaming.c.

Referenced by main(), and UpdateTexture().

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 127 of file teststreaming.c.

References done, frame, loop(), MOOSEFRAME_SIZE, MooseFrames, MOOSEFRAMES_COUNT, MOOSEPIC_H, MOOSEPIC_W, NULL, quit(), SDL_CreateRenderer, SDL_CreateTexture, SDL_CreateWindow, SDL_DestroyRenderer, SDL_GetError, SDL_Init, SDL_INIT_VIDEO, SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, SDL_LogError, SDL_LogSetPriority, SDL_PIXELFORMAT_ARGB8888, SDL_RWclose, SDL_RWFromFile, SDL_RWread, SDL_TEXTUREACCESS_STREAMING, SDL_WINDOW_RESIZABLE, and SDL_WINDOWPOS_UNDEFINED.

{
/* Enable standard application logging */
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
/* load the 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");
quit(2);
}
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());
quit(3);
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (!renderer) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError());
quit(4);
}
if (!MooseTexture) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
quit(5);
}
/* Loop, waiting for QUIT or the escape key */
frame = 0;
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, 0, 1);
#else
while (!done) {
loop();
}
#endif
quit(0);
return 0;
}
void quit ( int  rc)

Definition at line 64 of file teststreaming.c.

References SDL_Quit.

Referenced by main(), and UpdateTexture().

{
exit(rc);
}
void UpdateTexture ( SDL_Texture texture,
int  frame 
)

Definition at line 70 of file teststreaming.c.

References SDL_Color::b, frame, SDL_Color::g, MooseFrames, MOOSEPIC_H, MOOSEPIC_W, NULL, quit(), SDL_Color::r, SDL_GetError, SDL_LockTexture, SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, and SDL_UnlockTexture.

Referenced by loop().

{
int row, col;
void *pixels;
int pitch;
if (SDL_LockTexture(texture, NULL, &pixels, &pitch) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't lock texture: %s\n", SDL_GetError());
quit(5);
}
for (row = 0; row < MOOSEPIC_H; ++row) {
dst = (Uint32*)((Uint8*)pixels + row * pitch);
for (col = 0; col < MOOSEPIC_W; ++col) {
color = &MooseColors[*src++];
*dst++ = (0xFF000000|(color->r<<16)|(color->g<<8)|color->b);
}
}
}

Variable Documentation

Definition at line 62 of file teststreaming.c.

int frame

Definition at line 60 of file teststreaming.c.

Referenced by loop(), main(), and UpdateTexture().

SDL_Color MooseColors[84]
Initial value:
{
{49, 49, 49, 255}, {66, 24, 0, 255}, {66, 33, 0, 255}, {66, 66, 66, 255},
{66, 115, 49, 255}, {74, 33, 0, 255}, {74, 41, 16, 255}, {82, 33, 8, 255},
{82, 41, 8, 255}, {82, 49, 16, 255}, {82, 82, 82, 255}, {90, 41, 8, 255},
{90, 41, 16, 255}, {90, 57, 24, 255}, {99, 49, 16, 255}, {99, 66, 24, 255},
{99, 66, 33, 255}, {99, 74, 33, 255}, {107, 57, 24, 255}, {107, 82, 41, 255},
{115, 57, 33, 255}, {115, 66, 33, 255}, {115, 66, 41, 255}, {115, 74, 0, 255},
{115, 90, 49, 255}, {115, 115, 115, 255}, {123, 82, 0, 255}, {123, 99, 57, 255},
{132, 66, 41, 255}, {132, 74, 41, 255}, {132, 90, 8, 255}, {132, 99, 33, 255},
{132, 99, 66, 255}, {132, 107, 66, 255}, {140, 74, 49, 255}, {140, 99, 16, 255},
{140, 107, 74, 255}, {140, 115, 74, 255}, {148, 107, 24, 255}, {148, 115, 82, 255},
{148, 123, 74, 255}, {148, 123, 90, 255}, {156, 115, 33, 255}, {156, 115, 90, 255},
{156, 123, 82, 255}, {156, 132, 82, 255}, {156, 132, 99, 255}, {156, 156, 156, 255},
{165, 123, 49, 255}, {165, 123, 90, 255}, {165, 132, 82, 255}, {165, 132, 90, 255},
{165, 132, 99, 255}, {165, 140, 90, 255}, {173, 132, 57, 255}, {173, 132, 99, 255},
{173, 140, 107, 255}, {173, 140, 115, 255}, {173, 148, 99, 255}, {173, 173, 173, 255},
{181, 140, 74, 255}, {181, 148, 115, 255}, {181, 148, 123, 255}, {181, 156, 107, 255},
{189, 148, 123, 255}, {189, 156, 82, 255}, {189, 156, 123, 255}, {189, 156, 132, 255},
{189, 189, 189, 255}, {198, 156, 123, 255}, {198, 165, 132, 255}, {206, 165, 99, 255},
{206, 165, 132, 255}, {206, 173, 140, 255}, {206, 206, 206, 255}, {214, 173, 115, 255},
{214, 173, 140, 255}, {222, 181, 148, 255}, {222, 189, 132, 255}, {222, 189, 156, 255},
{222, 222, 222, 255}, {231, 198, 165, 255}, {231, 231, 231, 255}, {239, 206, 173, 255}
}

Definition at line 33 of file teststreaming.c.

Definition at line 57 of file teststreaming.c.

Referenced by main(), and UpdateTexture().

SDL_Texture* MooseTexture

Definition at line 61 of file teststreaming.c.

SDL_Renderer* renderer

Definition at line 59 of file teststreaming.c.