mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-03-20 15:51:07 +01:00
Use PNG files for tests and examples
These are much smaller than the previous BMP files Fixes https://github.com/libsdl-org/SDL/issues/14159
This commit is contained in:
@@ -31,7 +31,7 @@ if(NOT CMAKE_VERSION VERSION_LESS 3.20)
|
||||
set(example_bin_dir "${example_bin_dir}$<$<BOOL:${is_multi_config}>:/$<CONFIG>>")
|
||||
endif()
|
||||
|
||||
file(GLOB RESOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/*.bmp ${CMAKE_CURRENT_SOURCE_DIR}/../test/*.wav ${CMAKE_CURRENT_SOURCE_DIR}/../test/*.hex)
|
||||
file(GLOB RESOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/*.png ${CMAKE_CURRENT_SOURCE_DIR}/../test/*.wav ${CMAKE_CURRENT_SOURCE_DIR}/../test/*.hex)
|
||||
|
||||
set(RESOURCE_FILE_NAMES)
|
||||
set(RESOURCE_FILES_BINDIR)
|
||||
@@ -131,17 +131,17 @@ add_sdl_example_executable(renderer-primitives SOURCES renderer/02-primitives/pr
|
||||
add_sdl_example_executable(renderer-lines SOURCES renderer/03-lines/lines.c)
|
||||
add_sdl_example_executable(renderer-points SOURCES renderer/04-points/points.c)
|
||||
add_sdl_example_executable(renderer-rectangles SOURCES renderer/05-rectangles/rectangles.c)
|
||||
add_sdl_example_executable(renderer-textures SOURCES renderer/06-textures/textures.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.bmp)
|
||||
add_sdl_example_executable(renderer-textures SOURCES renderer/06-textures/textures.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.png)
|
||||
add_sdl_example_executable(renderer-streaming-textures SOURCES renderer/07-streaming-textures/streaming-textures.c)
|
||||
add_sdl_example_executable(renderer-rotating-textures SOURCES renderer/08-rotating-textures/rotating-textures.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.bmp)
|
||||
add_sdl_example_executable(renderer-scaling-textures SOURCES renderer/09-scaling-textures/scaling-textures.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.bmp)
|
||||
add_sdl_example_executable(renderer-geometry SOURCES renderer/10-geometry/geometry.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.bmp)
|
||||
add_sdl_example_executable(renderer-color-mods SOURCES renderer/11-color-mods/color-mods.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.bmp)
|
||||
add_sdl_example_executable(renderer-viewport SOURCES renderer/14-viewport/viewport.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.bmp)
|
||||
add_sdl_example_executable(renderer-cliprect SOURCES renderer/15-cliprect/cliprect.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.bmp)
|
||||
add_sdl_example_executable(renderer-read-pixels SOURCES renderer/17-read-pixels/read-pixels.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.bmp)
|
||||
add_sdl_example_executable(renderer-rotating-textures SOURCES renderer/08-rotating-textures/rotating-textures.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.png)
|
||||
add_sdl_example_executable(renderer-scaling-textures SOURCES renderer/09-scaling-textures/scaling-textures.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.png)
|
||||
add_sdl_example_executable(renderer-geometry SOURCES renderer/10-geometry/geometry.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.png)
|
||||
add_sdl_example_executable(renderer-color-mods SOURCES renderer/11-color-mods/color-mods.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.png)
|
||||
add_sdl_example_executable(renderer-viewport SOURCES renderer/14-viewport/viewport.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.png)
|
||||
add_sdl_example_executable(renderer-cliprect SOURCES renderer/15-cliprect/cliprect.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.png)
|
||||
add_sdl_example_executable(renderer-read-pixels SOURCES renderer/17-read-pixels/read-pixels.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.png)
|
||||
add_sdl_example_executable(renderer-debug-text SOURCES renderer/18-debug-text/debug-text.c)
|
||||
add_sdl_example_executable(renderer-affine-textures SOURCES renderer/19-affine-textures/affine-textures.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.bmp)
|
||||
add_sdl_example_executable(renderer-affine-textures SOURCES renderer/19-affine-textures/affine-textures.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.png)
|
||||
add_sdl_example_executable(audio-simple-playback SOURCES audio/01-simple-playback/simple-playback.c)
|
||||
add_sdl_example_executable(audio-simple-playback-callback SOURCES audio/02-simple-playback-callback/simple-playback-callback.c)
|
||||
add_sdl_example_executable(audio-load-wav SOURCES audio/03-load-wav/load-wav.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.wav)
|
||||
@@ -149,11 +149,11 @@ add_sdl_example_executable(audio-multiple-streams SOURCES audio/04-multiple-stre
|
||||
add_sdl_example_executable(audio-planar-data SOURCES audio/05-planar-data/planar-data.c)
|
||||
add_sdl_example_executable(input-joystick-polling SOURCES input/01-joystick-polling/joystick-polling.c)
|
||||
add_sdl_example_executable(input-joystick-events SOURCES input/02-joystick-events/joystick-events.c)
|
||||
add_sdl_example_executable(input-gamepad-polling SOURCES input/03-gamepad-polling/gamepad-polling.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/gamepad_front.bmp)
|
||||
add_sdl_example_executable(input-gamepad-polling SOURCES input/03-gamepad-polling/gamepad-polling.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/gamepad_front.png)
|
||||
add_sdl_example_executable(input-gamepad-events SOURCES input/04-gamepad-events/gamepad-events.c)
|
||||
add_sdl_example_executable(camera-read-and-draw SOURCES camera/01-read-and-draw/read-and-draw.c)
|
||||
add_sdl_example_executable(pen-drawing-lines SOURCES pen/01-drawing-lines/drawing-lines.c)
|
||||
add_sdl_example_executable(asyncio-load-bitmaps SOURCES asyncio/01-load-bitmaps/load-bitmaps.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.bmp ${CMAKE_CURRENT_SOURCE_DIR}/../test/gamepad_front.bmp ${CMAKE_CURRENT_SOURCE_DIR}/../test/speaker.bmp ${CMAKE_CURRENT_SOURCE_DIR}/../test/icon2x.bmp)
|
||||
add_sdl_example_executable(asyncio-load-bitmaps SOURCES asyncio/01-load-bitmaps/load-bitmaps.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.png ${CMAKE_CURRENT_SOURCE_DIR}/../test/gamepad_front.png ${CMAKE_CURRENT_SOURCE_DIR}/../test/speaker.png ${CMAKE_CURRENT_SOURCE_DIR}/../test/icon2x.png)
|
||||
add_sdl_example_executable(misc-power SOURCES misc/01-power/power.c)
|
||||
add_sdl_example_executable(misc-clipboard SOURCES misc/02-clipboard/clipboard.c)
|
||||
add_sdl_example_executable(demo-snake SOURCES demo/01-snake/snake.c)
|
||||
@@ -165,7 +165,7 @@ add_sdl_example_executable(demo-bytepusher SOURCES demo/04-bytepusher/bytepusher
|
||||
# - Add a new example in examples/
|
||||
# - Run python VisualC/examples/generate.py
|
||||
# - Take note of the newly generated .vcxproj files
|
||||
# - Modify the .vcxproj files if necessary (adding content such as BMP or WAV files)
|
||||
# - Modify the .vcxproj files if necessary (adding content such as PNG or WAV files)
|
||||
# - Open VisualC/SDL.sln in Visual Studio or JetBrains Rider
|
||||
# - Locate the appropriate folder in the Solution Explorer
|
||||
# - Add the newly generated projects: Right click -> Add -> Existing project...
|
||||
|
||||
@@ -71,16 +71,16 @@ everything consistent. You can ignore it.
|
||||
|
||||
This is how Ryan is doing it currently.
|
||||
|
||||
- `rm -f frame*.bmp`
|
||||
- `rm -f frame*.png`
|
||||
- Temporarily add `#include "../../save-rendering-to-bitmaps.h"` after any SDL
|
||||
includes in the example program.
|
||||
- Launch the example app, interact with it, let it run for a few seconds, quit.
|
||||
- This will dump a "frameX.bmp" file for each frame rendered.
|
||||
- This will dump a "frameX.png" file for each frame rendered.
|
||||
- Make a video in webp format from the bitmaps (this assumes the bitmaps were
|
||||
stored at 60fps, you might have to tweak).
|
||||
|
||||
```bash
|
||||
ffmpeg -framerate 60 -pattern_type glob -i 'frame*.bmp' -loop 0 -quality 40 -r 10 -frames:v 40 onmouseover.webp
|
||||
ffmpeg -framerate 60 -pattern_type glob -i 'frame*.png' -loop 0 -quality 40 -r 10 -frames:v 40 onmouseover.webp
|
||||
```
|
||||
|
||||
You might need to start in the middle of the video, or mess with quality or
|
||||
@@ -89,6 +89,6 @@ This is how Ryan is doing it currently.
|
||||
pngquant for massive file size reduction without any obvious loss in quality:
|
||||
|
||||
```bash
|
||||
convert frame00000.bmp cvt.png ; pngquant cvt.png --output thumbnail.png ; rm -f cvt.png
|
||||
convert frame00000.png cvt.png ; pngquant cvt.png --output thumbnail.png ; rm -f cvt.png
|
||||
```
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ static SDL_Renderer *renderer = NULL;
|
||||
static SDL_AsyncIOQueue *queue = NULL;
|
||||
|
||||
#define TOTAL_TEXTURES 4
|
||||
static const char * const bmps[TOTAL_TEXTURES] = { "sample.bmp", "gamepad_front.bmp", "speaker.bmp", "icon2x.bmp" };
|
||||
static const char * const pngs[TOTAL_TEXTURES] = { "sample.png", "gamepad_front.png", "speaker.png", "icon2x.png" };
|
||||
static SDL_Texture *textures[TOTAL_TEXTURES];
|
||||
static const SDL_FRect texture_rects[TOTAL_TEXTURES] = {
|
||||
{ 116, 156, 408, 167 },
|
||||
@@ -44,12 +44,12 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
/* Load some .bmp files asynchronously from wherever the app is being run from, put them in the same queue. */
|
||||
for (i = 0; i < SDL_arraysize(bmps); i++) {
|
||||
/* Load some .png files asynchronously from wherever the app is being run from, put them in the same queue. */
|
||||
for (i = 0; i < SDL_arraysize(pngs); i++) {
|
||||
char *path = NULL;
|
||||
SDL_asprintf(&path, "%s%s", SDL_GetBasePath(), bmps[i]); /* allocate a string of the full file path */
|
||||
SDL_asprintf(&path, "%s%s", SDL_GetBasePath(), pngs[i]); /* allocate a string of the full file path */
|
||||
/* you _should) check for failure, but we'll just go on without files here. */
|
||||
SDL_LoadFileAsync(path, queue, (void *) bmps[i]); /* attach the filename as app-specific data, so we can see it later. */
|
||||
SDL_LoadFileAsync(path, queue, (void *) pngs[i]); /* attach the filename as app-specific data, so we can see it later. */
|
||||
SDL_free(path);
|
||||
}
|
||||
|
||||
@@ -72,18 +72,18 @@ SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
SDL_AsyncIOOutcome outcome;
|
||||
int i;
|
||||
|
||||
if (SDL_GetAsyncIOResult(queue, &outcome)) { /* a .bmp file load has finished? */
|
||||
if (SDL_GetAsyncIOResult(queue, &outcome)) { /* a .png file load has finished? */
|
||||
if (outcome.result == SDL_ASYNCIO_COMPLETE) {
|
||||
/* this might be _any_ of the bmps; they might finish loading in any order. */
|
||||
for (i = 0; i < SDL_arraysize(bmps); i++) {
|
||||
/* this might be _any_ of the pngs; they might finish loading in any order. */
|
||||
for (i = 0; i < SDL_arraysize(pngs); i++) {
|
||||
/* this doesn't need a strcmp because we gave the pointer from this array to SDL_LoadFileAsync */
|
||||
if (outcome.userdata == bmps[i]) {
|
||||
if (outcome.userdata == pngs[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i < SDL_arraysize(bmps)) { /* (just in case.) */
|
||||
SDL_Surface *surface = SDL_LoadBMP_IO(SDL_IOFromConstMem(outcome.buffer, (size_t) outcome.bytes_transferred), true);
|
||||
if (i < SDL_arraysize(pngs)) { /* (just in case.) */
|
||||
SDL_Surface *surface = SDL_LoadPNG_IO(SDL_IOFromConstMem(outcome.buffer, (size_t) outcome.bytes_transferred), true);
|
||||
if (surface) { /* the renderer is not multithreaded, so create the texture here once the data loads. */
|
||||
textures[i] = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
if (!textures[i]) {
|
||||
|
||||
@@ -36,7 +36,7 @@ static SDL_Gamepad *gamepad = NULL;
|
||||
/* This function runs once at startup. */
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
char *bmp_path = NULL;
|
||||
char *png_path = NULL;
|
||||
SDL_Surface *surface = NULL;
|
||||
|
||||
SDL_SetAppMetadata("Example Input Gamepad Polling", "1.0", "com.example.input-gamepad-polling");
|
||||
@@ -60,15 +60,15 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
times) with data from a bitmap file. */
|
||||
|
||||
/* SDL_Surface is pixel data the CPU can access. SDL_Texture is pixel data the GPU can access.
|
||||
Load a .bmp into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&bmp_path, "%sgamepad_front.bmp", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadBMP(bmp_path);
|
||||
Load a .png into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&png_path, "%sgamepad_front.png", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadPNG(png_path);
|
||||
if (!surface) {
|
||||
SDL_Log("Couldn't load bitmap: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
SDL_free(bmp_path); /* done with this, the file is loaded. */
|
||||
SDL_free(png_path); /* done with this, the file is loaded. */
|
||||
|
||||
texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
if (!texture) {
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
This example creates an SDL window and renderer, loads a texture from a
|
||||
.bmp file, and then draws it a few times each frame.
|
||||
.png file, and then draws it a few times each frame.
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ static int texture_height = 0;
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
SDL_Surface *surface = NULL;
|
||||
char *bmp_path = NULL;
|
||||
char *png_path = NULL;
|
||||
|
||||
SDL_SetAppMetadata("Example Renderer Textures", "1.0", "com.example.renderer-textures");
|
||||
|
||||
@@ -42,15 +42,15 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
times) with data from a bitmap file. */
|
||||
|
||||
/* SDL_Surface is pixel data the CPU can access. SDL_Texture is pixel data the GPU can access.
|
||||
Load a .bmp into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&bmp_path, "%ssample.bmp", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadBMP(bmp_path);
|
||||
Load a .png into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&png_path, "%ssample.png", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadPNG(png_path);
|
||||
if (!surface) {
|
||||
SDL_Log("Couldn't load bitmap: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
SDL_free(bmp_path); /* done with this, the file is loaded. */
|
||||
SDL_free(png_path); /* done with this, the file is loaded. */
|
||||
|
||||
texture_width = surface->w;
|
||||
texture_height = surface->h;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
This example creates an SDL window and renderer, loads a texture from a .bmp
|
||||
This example creates an SDL window and renderer, loads a texture from a .png
|
||||
file, and then draws it, rotating around the center of the screen.
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ static int texture_height = 0;
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
SDL_Surface *surface = NULL;
|
||||
char *bmp_path = NULL;
|
||||
char *png_path = NULL;
|
||||
|
||||
SDL_SetAppMetadata("Example Renderer Rotating Textures", "1.0", "com.example.renderer-rotating-textures");
|
||||
|
||||
@@ -42,15 +42,15 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
times) with data from a bitmap file. */
|
||||
|
||||
/* SDL_Surface is pixel data the CPU can access. SDL_Texture is pixel data the GPU can access.
|
||||
Load a .bmp into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&bmp_path, "%ssample.bmp", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadBMP(bmp_path);
|
||||
Load a .png into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&png_path, "%ssample.png", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadPNG(png_path);
|
||||
if (!surface) {
|
||||
SDL_Log("Couldn't load bitmap: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
SDL_free(bmp_path); /* done with this, the file is loaded. */
|
||||
SDL_free(png_path); /* done with this, the file is loaded. */
|
||||
|
||||
texture_width = surface->w;
|
||||
texture_height = surface->h;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
This example creates an SDL window and renderer, loads a texture from a .bmp
|
||||
This example creates an SDL window and renderer, loads a texture from a .png
|
||||
file, and then draws it, scaling it up and down.
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ static int texture_height = 0;
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
SDL_Surface *surface = NULL;
|
||||
char *bmp_path = NULL;
|
||||
char *png_path = NULL;
|
||||
|
||||
SDL_SetAppMetadata("Example Renderer Scaling Textures", "1.0", "com.example.renderer-scaling-textures");
|
||||
|
||||
@@ -42,15 +42,15 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
times) with data from a bitmap file. */
|
||||
|
||||
/* SDL_Surface is pixel data the CPU can access. SDL_Texture is pixel data the GPU can access.
|
||||
Load a .bmp into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&bmp_path, "%ssample.bmp", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadBMP(bmp_path);
|
||||
Load a .png into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&png_path, "%ssample.png", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadPNG(png_path);
|
||||
if (!surface) {
|
||||
SDL_Log("Couldn't load bitmap: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
SDL_free(bmp_path); /* done with this, the file is loaded. */
|
||||
SDL_free(png_path); /* done with this, the file is loaded. */
|
||||
|
||||
texture_width = surface->w;
|
||||
texture_height = surface->h;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
This example creates an SDL window and renderer, loads a texture from a .bmp
|
||||
This example creates an SDL window and renderer, loads a texture from a .png
|
||||
file, and then draws geometry (arbitrary polygons) using it.
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ static int texture_height = 0;
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
SDL_Surface *surface = NULL;
|
||||
char *bmp_path = NULL;
|
||||
char *png_path = NULL;
|
||||
|
||||
SDL_SetAppMetadata("Example Renderer Geometry", "1.0", "com.example.renderer-geometry");
|
||||
|
||||
@@ -42,15 +42,15 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
times) with data from a bitmap file. */
|
||||
|
||||
/* SDL_Surface is pixel data the CPU can access. SDL_Texture is pixel data the GPU can access.
|
||||
Load a .bmp into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&bmp_path, "%ssample.bmp", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadBMP(bmp_path);
|
||||
Load a .png into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&png_path, "%ssample.png", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadPNG(png_path);
|
||||
if (!surface) {
|
||||
SDL_Log("Couldn't load bitmap: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
SDL_free(bmp_path); /* done with this, the file is loaded. */
|
||||
SDL_free(png_path); /* done with this, the file is loaded. */
|
||||
|
||||
texture_width = surface->w;
|
||||
texture_height = surface->h;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
This example creates an SDL window and renderer, loads a texture from a
|
||||
.bmp file, and then draws it a few times each frame, adjusting the colors.
|
||||
.png file, and then draws it a few times each frame, adjusting the colors.
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ static int texture_height = 0;
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
SDL_Surface *surface = NULL;
|
||||
char *bmp_path = NULL;
|
||||
char *png_path = NULL;
|
||||
|
||||
SDL_SetAppMetadata("Example Renderer Color Mods", "1.0", "com.example.renderer-color-mods");
|
||||
|
||||
@@ -42,15 +42,15 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
times) with data from a bitmap file. */
|
||||
|
||||
/* SDL_Surface is pixel data the CPU can access. SDL_Texture is pixel data the GPU can access.
|
||||
Load a .bmp into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&bmp_path, "%ssample.bmp", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadBMP(bmp_path);
|
||||
Load a .png into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&png_path, "%ssample.png", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadPNG(png_path);
|
||||
if (!surface) {
|
||||
SDL_Log("Couldn't load bitmap: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
SDL_free(bmp_path); /* done with this, the file is loaded. */
|
||||
SDL_free(png_path); /* done with this, the file is loaded. */
|
||||
|
||||
texture_width = surface->w;
|
||||
texture_height = surface->h;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
This example creates an SDL window and renderer, loads a texture
|
||||
from a .bmp file, and then draws it a few times each frame, adjusting
|
||||
from a .png file, and then draws it a few times each frame, adjusting
|
||||
the viewport before each draw.
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ static int texture_height = 0;
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
SDL_Surface *surface = NULL;
|
||||
char *bmp_path = NULL;
|
||||
char *png_path = NULL;
|
||||
|
||||
SDL_SetAppMetadata("Example Renderer Viewport", "1.0", "com.example.renderer-viewport");
|
||||
|
||||
@@ -42,15 +42,15 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
times) with data from a bitmap file. */
|
||||
|
||||
/* SDL_Surface is pixel data the CPU can access. SDL_Texture is pixel data the GPU can access.
|
||||
Load a .bmp into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&bmp_path, "%ssample.bmp", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadBMP(bmp_path);
|
||||
Load a .png into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&png_path, "%ssample.png", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadPNG(png_path);
|
||||
if (!surface) {
|
||||
SDL_Log("Couldn't load bitmap: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
SDL_free(bmp_path); /* done with this, the file is loaded. */
|
||||
SDL_free(png_path); /* done with this, the file is loaded. */
|
||||
|
||||
texture_width = surface->w;
|
||||
texture_height = surface->h;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
This example creates an SDL window and renderer, loads a texture
|
||||
from a .bmp file, and stretches it across the window. Each frame, we move
|
||||
from a .png file, and stretches it across the window. Each frame, we move
|
||||
the clipping rectangle around, so only a small square of the texture is
|
||||
actually drawn.
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ static Uint64 last_time = 0;
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
SDL_Surface *surface = NULL;
|
||||
char *bmp_path = NULL;
|
||||
char *png_path = NULL;
|
||||
|
||||
SDL_SetAppMetadata("Example Renderer Clipping Rectangle", "1.0", "com.example.renderer-cliprect");
|
||||
|
||||
@@ -53,15 +53,15 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
times) with data from a bitmap file. */
|
||||
|
||||
/* SDL_Surface is pixel data the CPU can access. SDL_Texture is pixel data the GPU can access.
|
||||
Load a .bmp into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&bmp_path, "%ssample.bmp", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadBMP(bmp_path);
|
||||
Load a .png into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&png_path, "%ssample.png", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadPNG(png_path);
|
||||
if (!surface) {
|
||||
SDL_Log("Couldn't load bitmap: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
SDL_free(bmp_path); /* done with this, the file is loaded. */
|
||||
SDL_free(png_path); /* done with this, the file is loaded. */
|
||||
|
||||
texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
if (!texture) {
|
||||
|
||||
@@ -32,7 +32,7 @@ static int converted_texture_height = 0;
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
SDL_Surface *surface = NULL;
|
||||
char *bmp_path = NULL;
|
||||
char *png_path = NULL;
|
||||
|
||||
SDL_SetAppMetadata("Example Renderer Read Pixels", "1.0", "com.example.renderer-read-pixels");
|
||||
|
||||
@@ -51,15 +51,15 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
times) with data from a bitmap file. */
|
||||
|
||||
/* SDL_Surface is pixel data the CPU can access. SDL_Texture is pixel data the GPU can access.
|
||||
Load a .bmp into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&bmp_path, "%ssample.bmp", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadBMP(bmp_path);
|
||||
Load a .png into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&png_path, "%ssample.png", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadPNG(png_path);
|
||||
if (!surface) {
|
||||
SDL_Log("Couldn't load bitmap: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
SDL_free(bmp_path); /* done with this, the file is loaded. */
|
||||
SDL_free(png_path); /* done with this, the file is loaded. */
|
||||
|
||||
texture_width = surface->w;
|
||||
texture_height = surface->h;
|
||||
|
||||
@@ -25,7 +25,7 @@ static int texture_height = 0;
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
SDL_Surface *surface = NULL;
|
||||
char *bmp_path = NULL;
|
||||
char *png_path = NULL;
|
||||
|
||||
SDL_SetAppMetadata("Example Renderer Affine Textures", "1.0", "com.example.renderer-affine-textures");
|
||||
|
||||
@@ -44,15 +44,15 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
times) with data from a bitmap file. */
|
||||
|
||||
/* SDL_Surface is pixel data the CPU can access. SDL_Texture is pixel data the GPU can access.
|
||||
Load a .bmp into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&bmp_path, "%ssample.bmp", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadBMP(bmp_path);
|
||||
Load a .png into a surface, move it to a texture from there. */
|
||||
SDL_asprintf(&png_path, "%ssample.png", SDL_GetBasePath()); /* allocate a string of the full file path */
|
||||
surface = SDL_LoadPNG(png_path);
|
||||
if (!surface) {
|
||||
SDL_Log("Couldn't load bitmap: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
SDL_free(bmp_path); /* done with this, the file is loaded. */
|
||||
SDL_free(png_path); /* done with this, the file is loaded. */
|
||||
|
||||
texture_width = surface->w;
|
||||
texture_height = surface->h;
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
/*
|
||||
This is for generating thumbnails and videos of examples. Just include it
|
||||
temporarily and let it override SDL_RenderPresent, etc, and it'll dump each
|
||||
frame rendered to a new .bmp file.
|
||||
frame rendered to a new .png file.
|
||||
*/
|
||||
|
||||
static bool SAVERENDERING_SDL_RenderPresent(SDL_Renderer *renderer)
|
||||
@@ -33,9 +33,9 @@ static bool SAVERENDERING_SDL_RenderPresent(SDL_Renderer *renderer)
|
||||
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "Failed to read pixels for frame #%u! (%s)", framenum, SDL_GetError());
|
||||
} else {
|
||||
char fname[64];
|
||||
SDL_snprintf(fname, sizeof (fname), "frame%05u.bmp", framenum);
|
||||
if (!SDL_SaveBMP(surface, fname)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "Failed to save bmp for frame #%u! (%s)", framenum, SDL_GetError());
|
||||
SDL_snprintf(fname, sizeof (fname), "frame%05u.png", framenum);
|
||||
if (!SDL_SavePNG(surface, fname)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "Failed to save png for frame #%u! (%s)", framenum, SDL_GetError());
|
||||
}
|
||||
SDL_DestroySurface(surface);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user