libsdl2pp / libsdl2pp Goto Github PK
View Code? Open in Web Editor NEWC++ bindings/wrapper for SDL2
Home Page: https://sdl2pp.amdmi3.ru
License: Other
C++ bindings/wrapper for SDL2
Home Page: https://sdl2pp.amdmi3.ru
License: Other
Suppose I want to fill a rectangle with some color. FillRect
member function expects a color in surface's format. There is conversion function, SDL_MapRGB
, but it expects SDL_PixelFormat*
. Surface::GetFormat
, however, returns only SDL_PixelFormat::format
, not the whole structure.
What is the preferred way to convert RGB values to surface's color that FillRect
expects?
surface.FillRect(rect, SDL_MapRGB(???, r, g, b));
Shall a method be provided to convert RGB to color value:
Surface::MapRGB(Uint8 r, Uint8 g, Uint8 b);
Or even a FillRect
overload taking RGB values?
Which automatically calls number of Copy() to fill specific rectangle with texture
Currently mixer documentation refer to SDL_mixer website. This is inconvenient, copy function descriptions here instead. While at it, recheck completeness of \throw items.
Several classes have the ability to open files using filenames. It would be nice to also have support opening files using std::istream.
All methods which take r/g/b/a should also take SDL_Color
Currently Renderer class only provides virtual destructor. It would be much more flexible, however, if more of its functions were virtual.
For example, I need a renderer for low-resolution game which automatically scales its 320x200 resolutions onto a bigger render area. This can be done inside SDL with SetViewport and SetScale, however this method has drawbacks:
Alternative methods include:
Both methods may be done transparently with custom Renderer derivative which overrides some operations, however for that to work really transparently, base Renderer functions should be virtual. virtual call has an overhead, but it is incomparably small to operations that Renderer class performs (heavyweight opengl operations which go through multiple layers of library calls). Performance testing would be nice though.
Drop GetX2/GetY2, instead implement:
Cursors (SDL_Cursor) are wrappable into SDL2pp object, however how SDL2 behaves when cursor is destroyed is poorly documented. This needs some investigation.
Not everything can be tested (for example, audio), but everything should be at least covered by a demo. cppcheck helps finding functions which are not used anywhere.
cppcheck -q --enable=unusedFunction . 2>&1 | sort
It'd be useful to properly implement C++11 move semantics. Will be easy, but the question is how empty (e.g. moved from) objects should behave:
Provide constructors for Wav:
Wav(nsamples, spec) to create silence of specified format for later filling and Wav(data, nsamples, spec) to load audio data from existing buffer.
flags
parameter is unused and should be set to zero. Do we need this parameter at all?
Mask parameters can take zero values meaning "default". Thus, the signature could be:
Surface::Surface(int width, int height, int depth,
Uint32 Rmask = 0, Uint32 Gmask = 0, Uint32 Bmask = 0, Uint32 Amask = 0);
Of course, I understand that changing the signature is a breaking change and not acceptable, thus an alternative overload can be added?
This happens for both gcc/libstdc++ and clang++/libc++, because experimental/optional
is only in C++14 standard and not in C++11, and both gcc
and clang
refuse to compile the test program with -std=c++11
flag.
Tested on Ubuntu 14.10 with gcc 4.9.1 and clang 3.5.0.
And the same with [[deprecated]]
.
I see two solutions:
-std=c++14
flag when possible.$ ./gui_rendering
PASSED: pixels.Test(0, 0, 1, 2, 3)
PASSED: pixels.Test3x3(10, 10, 0x020, 255, 128, 0)
PASSED: pixels.Test3x3(20, 20, 0x020, 0, 255, 128)
PASSED: pixels.Test3x3(30, 30, 0x020, 128, 0, 255)
PASSED: pixels.Test3x3(10, 20, 0x222, 255, 128, 0)
PASSED: pixels.Test3x3(20, 20, 0x222, 0, 255, 128)
PASSED: pixels.Test3x3(30, 20, 0x222, 128, 0, 255)
PASSED: pixels.Test3x3(10, 10, 0x032, 255, 128, 0)
PASSED: pixels.Test3x3(19, 10, 0x062, 255, 128, 0)
PASSED: pixels.Test3x3(10, 19, 0x230, 255, 128, 0)
FAILED: pixels.Test3x3(19, 19, 0x260, 255, 128, 0)
PASSED: pixels.Test3x3(30, 10, 0x032, 0, 255, 128)
PASSED: pixels.Test3x3(39, 10, 0x062, 0, 255, 128)
PASSED: pixels.Test3x3(30, 19, 0x230, 0, 255, 128)
FAILED: pixels.Test3x3(39, 19, 0x260, 0, 255, 128)
PASSED: pixels.Test3x3(10, 30, 0x032, 128, 0, 255)
PASSED: pixels.Test3x3(19, 30, 0x062, 128, 0, 255)
PASSED: pixels.Test3x3(10, 39, 0x230, 128, 0, 255)
FAILED: pixels.Test3x3(19, 39, 0x260, 128, 0, 255)
PASSED: pixels.Test3x3(30, 30, 0x032, 128, 192, 255)
PASSED: pixels.Test3x3(39, 30, 0x062, 128, 192, 255)
PASSED: pixels.Test3x3(30, 39, 0x230, 128, 192, 255)
FAILED: pixels.Test3x3(39, 39, 0x260, 128, 192, 255)
PASSED: pixels.Test3x3(10, 10, 0x033, 255, 128, 0)
PASSED: pixels.Test3x3(19, 10, 0x066, 255, 128, 0)
PASSED: pixels.Test3x3(10, 19, 0x330, 255, 128, 0)
PASSED: pixels.Test3x3(19, 19, 0x660, 255, 128, 0)
PASSED: pixels.Test3x3(30, 10, 0x033, 0, 255, 128)
PASSED: pixels.Test3x3(39, 10, 0x066, 0, 255, 128)
PASSED: pixels.Test3x3(30, 19, 0x330, 0, 255, 128)
PASSED: pixels.Test3x3(39, 19, 0x660, 0, 255, 128)
PASSED: pixels.Test3x3(10, 30, 0x033, 128, 0, 255)
PASSED: pixels.Test3x3(19, 30, 0x066, 128, 0, 255)
PASSED: pixels.Test3x3(10, 39, 0x330, 128, 0, 255)
PASSED: pixels.Test3x3(19, 39, 0x660, 128, 0, 255)
PASSED: pixels.Test3x3(30, 30, 0x033, 128, 192, 255)
PASSED: pixels.Test3x3(39, 30, 0x066, 128, 192, 255)
PASSED: pixels.Test3x3(30, 39, 0x330, 128, 192, 255)
PASSED: pixels.Test3x3(39, 39, 0x660, 128, 192, 255)
PASSED: pixels.Test3x3(10, 10, 0x033, 127, 127, 127)
PASSED: pixels.Test3x3(19, 10, 0x066, 127, 127, 127)
PASSED: pixels.Test3x3(10, 19, 0x330, 127, 127, 127)
PASSED: pixels.Test3x3(19, 19, 0x660, 127, 127, 127)
4 failures
What?
Document everything with doxygen
RWops which take another RWops and a range, and limit I/O operations with that range
Which will allow neat method chaining
SDL uses error buffer internally, which contents may change at any time, so error string should be copied into the exception
CustomRWops interface is imperfect:
RWops rw(MyCustomRWops(arg1, arg2));
Ideally, there should be a single RWops class, which works with SDL_rwops by default, but allows deriving custom classes with redefined read/write/close/seek operations. I remember some problems which didn't let me implement it this way from the start, maybe they could be solved on the second try.
If that's still impossible, above mentioned constructor should be at least turned into something like:
RWops rw = RWops::FromCustom<MyCustomRWops>(arg1, arg2);
Longer, but clearer and doesn't require MyCustomRWops to be movable or copyable.
Needed for SDL_image support
In addition to Lock/Unlock methodes, there could be a separate Lock object which does Lock in constructor and Unlock in destructor, and handles the duration of locking automatically.
It's a bit quirky, so I haven't implemented in with other SDL_mixer methods.
This satellite library has many alloc/free-style managed objects, so it's nice candidate for SDL2pp wrapper
I.e. IMG_Init and IMG_Quit similar to SDL2pp::SDL.
IMG_Init may load preload libraries for specifiic format support on start to save loading time, and IMG_Quit cleans things up (e.g. for valgrind).
Asserts checking that contained pointers are not null (e.g. misuse of moved-from objects) would be useful. Also, NDEBUG define should be set for the release build.
Should be quite similar to Texture
This is far beyond SDL scope, however such facility is very useful in the games are absolutely required for effective text renderer (see #38)
Currently mixer documentation refer to SDL_ttf website. This is inconvenient, copy function descriptions here instead. While at it, recheck completeness of \throw items.
We need c++11 style event handling mechanism instead of legacy switch-loop
As suggested by @rianhunter in #13, it'd be nice to move "valid" property out of Rect and Point into seprate "optional" entity. I plan to take implementation from libc++ as more readable.
With the latest libSDL2pp changes, it is obvious that we would benefit from C++1y features, for example: [[deprecated]]
attribute and experimental/optional
header. It's not easy, however, as using -std=c++1y would impose the same requirement on client code, but without it named features will be inaccessible (with the exception of that [[deprecated]]
is available on clang with -std=c++11). Probably an option for c++1y should be added + automatic checks for optional and deprecated which run regardless of set standard.
Instead of destination rectangle; width and height are taken from source rectangle or texture dimensions
How about SDL2_image, SDL2_mixer etc.. Wrappers?
These are too useful needed. Same interface as Point/Rect + conversion
Using SDL_ttf to render dynamic text in the game is ineffective, as each string is first rendered by freetype onto Surface (slow!), then surface data is converted into Texture and uploaded to GPU (also slow!). A facility is needed to cache glyphs on a texture and render them without calling SDL_ttf code. Texture atlas support is needed for this (#37)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.