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

◆ MOOSEFRAME_SIZE

#define MOOSEFRAME_SIZE   (MOOSEPIC_W * MOOSEPIC_H)

Definition at line 30 of file teststreaming.c.

◆ MOOSEFRAMES_COUNT

#define MOOSEFRAMES_COUNT   10

Definition at line 31 of file teststreaming.c.

◆ MOOSEPIC_H

#define MOOSEPIC_H   88

Definition at line 28 of file teststreaming.c.

◆ MOOSEPIC_W

#define MOOSEPIC_W   64

Definition at line 27 of file teststreaming.c.

Function Documentation

◆ loop()

void loop ( )

Definition at line 95 of file teststreaming.c.

96 {
98 
99  while (SDL_PollEvent(&event)) {
100  switch (event.type) {
101  case SDL_KEYDOWN:
102  if (event.key.keysym.sym == SDLK_ESCAPE) {
103  done = SDL_TRUE;
104  }
105  break;
106  case SDL_QUIT:
107  done = SDL_TRUE;
108  break;
109  }
110  }
111 
112  frame = (frame + 1) % MOOSEFRAMES_COUNT;
114 
118 
119 #ifdef __EMSCRIPTEN__
120  if (done) {
121  emscripten_cancel_main_loop();
122  }
123 #endif
124 }

References done, frame, MOOSEFRAMES_COUNT, MooseTexture, NULL, renderer, SDL_KEYDOWN, SDL_PollEvent, SDL_QUIT, SDL_RenderClear, SDL_RenderCopy, SDL_RenderPresent, SDL_TRUE, SDLK_ESCAPE, and UpdateTexture().

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 127 of file teststreaming.c.

128 {
130  SDL_RWops *handle;
131 
132  /* Enable standard application logging */
134 
135  if (SDL_Init(SDL_INIT_VIDEO) < 0) {
136  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
137  return 1;
138  }
139 
140  /* load the moose images */
141  handle = SDL_RWFromFile("moose.dat", "rb");
142  if (handle == NULL) {
143  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't find the file moose.dat !\n");
144  quit(2);
145  }
148 
149 
150  /* Create the window and renderer */
151  window = SDL_CreateWindow("Happy Moose",
154  MOOSEPIC_W*4, MOOSEPIC_H*4,
156  if (!window) {
157  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError());
158  quit(3);
159  }
160 
162  if (!renderer) {
163  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError());
164  quit(4);
165  }
166 
168  if (!MooseTexture) {
169  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
170  quit(5);
171  }
172 
173  /* Loop, waiting for QUIT or the escape key */
174  frame = 0;
175 
176 #ifdef __EMSCRIPTEN__
177  emscripten_set_main_loop(loop, 0, 1);
178 #else
179  while (!done) {
180  loop();
181  }
182 #endif
183 
185 
186  quit(0);
187  return 0;
188 }

References done, frame, loop(), MOOSEFRAME_SIZE, MooseFrames, MOOSEFRAMES_COUNT, MOOSEPIC_H, MOOSEPIC_W, MooseTexture, NULL, quit(), renderer, 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.

◆ quit()

void quit ( int  rc)

Definition at line 64 of file teststreaming.c.

65 {
66  SDL_Quit();
67  exit(rc);
68 }

References SDL_Quit.

Referenced by main(), and UpdateTexture().

◆ UpdateTexture()

void UpdateTexture ( SDL_Texture texture,
int  frame 
)

Definition at line 70 of file teststreaming.c.

71 {
73  Uint8 *src;
74  Uint32 *dst;
75  int row, col;
76  void *pixels;
77  int pitch;
78 
79  if (SDL_LockTexture(texture, NULL, &pixels, &pitch) < 0) {
80  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't lock texture: %s\n", SDL_GetError());
81  quit(5);
82  }
84  for (row = 0; row < MOOSEPIC_H; ++row) {
85  dst = (Uint32*)((Uint8*)pixels + row * pitch);
86  for (col = 0; col < MOOSEPIC_W; ++col) {
87  color = &MooseColors[*src++];
88  *dst++ = (0xFF000000|(color->r<<16)|(color->g<<8)|color->b);
89  }
90  }
92 }

References frame, MooseColors, MooseFrames, MOOSEPIC_H, MOOSEPIC_W, NULL, quit(), SDL_GetError, SDL_LockTexture, SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, and SDL_UnlockTexture.

Referenced by loop().

Variable Documentation

◆ done

Definition at line 62 of file teststreaming.c.

Referenced by loop(), and main().

◆ frame

int frame

Definition at line 60 of file teststreaming.c.

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

◆ MooseColors

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.

Referenced by UpdateTexture().

◆ MooseFrames

Definition at line 57 of file teststreaming.c.

Referenced by main(), and UpdateTexture().

◆ MooseTexture

SDL_Texture* MooseTexture

Definition at line 61 of file teststreaming.c.

Referenced by loop(), and main().

◆ renderer

SDL_Renderer* renderer

Definition at line 59 of file teststreaming.c.

Referenced by loop(), and main().

SDL_PIXELFORMAT_ARGB8888
@ SDL_PIXELFORMAT_ARGB8888
Definition: SDL_pixels.h:248
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:179
MOOSEPIC_H
#define MOOSEPIC_H
Definition: teststreaming.c:28
SDL_GetError
#define SDL_GetError
Definition: SDL_dynapi_overrides.h:113
SDL_RenderPresent
#define SDL_RenderPresent
Definition: SDL_dynapi_overrides.h:346
SDL_PollEvent
#define SDL_PollEvent
Definition: SDL_dynapi_overrides.h:122
SDL_LOG_CATEGORY_APPLICATION
@ SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66
NULL
#define NULL
Definition: begin_code.h:164
handle
EGLImageKHR EGLint EGLint * handle
Definition: eglext.h:937
MOOSEFRAMES_COUNT
#define MOOSEFRAMES_COUNT
Definition: teststreaming.c:31
SDL_WINDOWPOS_UNDEFINED
#define SDL_WINDOWPOS_UNDEFINED
Definition: SDL_video.h:130
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
SDL_KEYDOWN
@ SDL_KEYDOWN
Definition: SDL_events.h:96
SDL_CreateWindow
#define SDL_CreateWindow
Definition: SDL_dynapi_overrides.h:514
SDL_RWread
#define SDL_RWread(ctx, ptr, size, n)
Definition: SDL_rwops.h:187
SDL_LogError
#define SDL_LogError
Definition: SDL_dynapi_overrides.h:36
SDL_WINDOW_RESIZABLE
@ SDL_WINDOW_RESIZABLE
Definition: SDL_video.h:105
SDL_UnlockTexture
#define SDL_UnlockTexture
Definition: SDL_dynapi_overrides.h:318
row
GLenum GLenum void * row
Definition: SDL_opengl_glext.h:3138
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:74
dst
GLenum GLenum dst
Definition: SDL_opengl_glext.h:1737
SDLK_ESCAPE
@ SDLK_ESCAPE
Definition: SDL_keycode.h:55
renderer
SDL_Renderer * renderer
Definition: teststreaming.c:59
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
quit
void quit(int rc)
Definition: teststreaming.c:64
SDL_RenderCopy
#define SDL_RenderCopy
Definition: SDL_dynapi_overrides.h:343
color
GLuint color
Definition: SDL_opengl_glext.h:1148
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
loop
void loop()
Definition: teststreaming.c:95
SDL_RWFromFile
#define SDL_RWFromFile
Definition: SDL_dynapi_overrides.h:351
SDL_QUIT
@ SDL_QUIT
Definition: SDL_events.h:60
frame
int frame
Definition: teststreaming.c:60
SDL_LockTexture
#define SDL_LockTexture
Definition: SDL_dynapi_overrides.h:317
SDL_Quit
#define SDL_Quit
Definition: SDL_dynapi_overrides.h:58
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
MooseTexture
SDL_Texture * MooseTexture
Definition: teststreaming.c:61
pixels
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
MOOSEPIC_W
#define MOOSEPIC_W
Definition: teststreaming.c:27
SDL_RWclose
#define SDL_RWclose(ctx)
Definition: SDL_rwops.h:189
SDL_INIT_VIDEO
#define SDL_INIT_VIDEO
Definition: SDL.h:79
SDL_LOG_PRIORITY_INFO
@ SDL_LOG_PRIORITY_INFO
Definition: SDL_log.h:106
src
GLenum src
Definition: SDL_opengl_glext.h:1737
SDL_LogSetPriority
#define SDL_LogSetPriority
Definition: SDL_dynapi_overrides.h:236
SDL_RenderClear
#define SDL_RenderClear
Definition: SDL_dynapi_overrides.h:334
SDL_Color
Definition: SDL_pixels.h:296
MooseColors
SDL_Color MooseColors[84]
Definition: teststreaming.c:33
MooseFrames
Uint8 MooseFrames[MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE]
Definition: teststreaming.c:57
SDL_Event
General event structure.
Definition: SDL_events.h:558
done
SDL_bool done
Definition: teststreaming.c:62
SDL_CreateRenderer
#define SDL_CreateRenderer
Definition: SDL_dynapi_overrides.h:301
SDL_Init
#define SDL_Init
Definition: SDL_dynapi_overrides.h:54
SDL_DestroyRenderer
#define SDL_DestroyRenderer
Definition: SDL_dynapi_overrides.h:348
SDL_TEXTUREACCESS_STREAMING
@ SDL_TEXTUREACCESS_STREAMING
Definition: SDL_render.h:94
texture
GLenum GLenum GLuint texture
Definition: SDL_opengl_glext.h:1178
SDL_RWops
Definition: SDL_rwops.h:53
MOOSEFRAME_SIZE
#define MOOSEFRAME_SIZE
Definition: teststreaming.c:30
SDL_CreateTexture
#define SDL_CreateTexture
Definition: SDL_dynapi_overrides.h:306
UpdateTexture
void UpdateTexture(SDL_Texture *texture, int frame)
Definition: teststreaming.c:70