mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-05 20:05:59 -04:00
Use surface in example
This commit is contained in:
parent
fff166becd
commit
79300dea2b
@ -27,6 +27,7 @@
|
|||||||
#include <SDL2pp/Window.hh>
|
#include <SDL2pp/Window.hh>
|
||||||
#include <SDL2pp/Renderer.hh>
|
#include <SDL2pp/Renderer.hh>
|
||||||
#include <SDL2pp/Texture.hh>
|
#include <SDL2pp/Texture.hh>
|
||||||
|
#include <SDL2pp/Surface.hh>
|
||||||
#include <SDL2pp/Exception.hh>
|
#include <SDL2pp/Exception.hh>
|
||||||
|
|
||||||
using namespace SDL2pp;
|
using namespace SDL2pp;
|
||||||
@ -36,9 +37,16 @@ int Run() {
|
|||||||
Window window("libSDL2pp demo: loading", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_RESIZABLE);
|
Window window("libSDL2pp demo: loading", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_RESIZABLE);
|
||||||
Renderer render(window, -1, SDL_RENDERER_ACCELERATED);
|
Renderer render(window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
|
|
||||||
// Load sprite texture
|
// Load sprite texture; sprite1 and sprite2 are actually the same
|
||||||
Texture sprite(render, TESTDATA_DIR "/test.png");
|
// however first one is loaded directly into texture, and second
|
||||||
sprite.SetBlendMode(SDL_BLENDMODE_BLEND);
|
// one is loaded through an intermediary surface
|
||||||
|
Surface surf(TESTDATA_DIR "/test.png");
|
||||||
|
|
||||||
|
Texture sprite1(render, TESTDATA_DIR "/test.png");
|
||||||
|
Texture sprite2(render, surf);
|
||||||
|
|
||||||
|
sprite1.SetBlendMode(SDL_BLENDMODE_BLEND);
|
||||||
|
sprite2.SetBlendMode(SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
render.SetDrawBlendMode(SDL_BLENDMODE_BLEND);
|
render.SetDrawBlendMode(SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
@ -55,9 +63,9 @@ int Run() {
|
|||||||
|
|
||||||
// Simple copy
|
// Simple copy
|
||||||
float angle = SDL_GetTicks() / 5000.0 * 2.0 * M_PI;
|
float angle = SDL_GetTicks() / 5000.0 * 2.0 * M_PI;
|
||||||
render.Copy(sprite, NullOpt, Rect(320 - 64, 240 - 64, 128, 128), angle / M_PI * 180.0);
|
render.Copy(sprite1, NullOpt, Rect(320 - 64, 240 - 64, 128, 128), angle / M_PI * 180.0);
|
||||||
render.Copy(sprite, NullOpt, Rect(320 - 32 + sin(angle) * 40, 240 - 32 + cos(angle) * 40, 64, 64));
|
render.Copy(sprite1, NullOpt, Rect(320 - 32 + sin(angle) * 40, 240 - 32 + cos(angle) * 40, 64, 64));
|
||||||
render.Copy(sprite, NullOpt, Rect(320 - 32 - sin(angle) * 40, 240 - 32 - cos(angle) * 40, 64, 64));
|
render.Copy(sprite2, NullOpt, Rect(320 - 32 - sin(angle) * 40, 240 - 32 - cos(angle) * 40, 64, 64));
|
||||||
|
|
||||||
render.Present();
|
render.Present();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user