Giter Club home page Giter Club logo

libsdl2pp's Issues

Provide a convenient way to convert to Surface's pixel format

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?

FillCopy method

Which automatically calls number of Copy() to fill specific rectangle with texture

Complete SDL_mixer-related documentation

Currently mixer documentation refer to SDL_mixer website. This is inconvenient, copy function descriptions here instead. While at it, recheck completeness of \throw items.

std::istream support

Several classes have the ability to open files using filenames. It would be nice to also have support opening files using std::istream.

virtualize Renderer class

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:

  • SetScale will affect horizontal and vertical lines (e.g. with 2x scale, vertical line will be 2 pixels wide), while diagonal lines won't be affected
  • SetScale works BEFORE SetViewport, so to place scaled 320x200 screen in your window you'll need to think in scaled coords

Alternative methods include:

  • Scale all rendering operations instead (sprites will be scaled, lines will be not)
  • Render onto intermediate target, then place it on the screen (both sprites and lines will be scaled)

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.

More (and more consistent) Rect side and corner getters/setters

Drop GetX2/GetY2, instead implement:

  • Get{Left,Right,Top,Bottom}
  • Set{Left,Right,Top,Bottom} (scaling size correspondingly)
  • Set{TopLeft,TopRight,BottomLeft,BottomRight} (scaling size correspondingly)
  • Move{Left,Right,Top,Bottom,TopLeft,TopRight,BottomLeft,BottomRight} (not changing size)

Cursors support

Cursors (SDL_Cursor) are wrappable into SDL2pp object, however how SDL2 behaves when cursor is destroyed is poorly documented. This needs some investigation.

Cover all functions with tests and/or demos

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

  • AudioDevice.cc (5 left)
  • AudioSpec.cc (1 left)
  • Exception.cc (1 left)
  • Font.cc (25 left)
  • Mixer.cc (9 left)
  • RWops.cc (4 left)
  • Renderer.cc (16 left)
  • SDL.cc (3 left)
  • SDLImage.cc (2 left)
  • Surface.cc (10 left)
  • SurfaceLock.cc (3 left)
  • Texture.cc (2 left)
  • Window.cc (24 left)

C++11 move semantics support

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:

  • be a no-op (impossible for some operations, e.g. Point::GetX())
  • throw exceptions
  • die with assert()'s which are only compiled in in debug version
  • die with assert()'s which are always compiled in
  • any of above, selectable during library compilation

Wav: empty ctor and ctor from existing data

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.

Surface constructor parameters

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?

experimental/optional is not detected and used even if present

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:

  • Use -std=c++14 flag when possible.
  • Since optional is bundled anyway always use the bundled version.

I can't pass test.

$ ./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?

967fd8659ea164fe4c636714348e7c0f

Documentation improvements

  • Document remaining classes, namely custom RWops
  • Document deleted constructors and assigments
  • Proofread generated documentation
  • Run all documentation through spelling checker
  • Add title page
  • Add travis check for doxygen warnings
  • Add in/out specifiers for function params

SliceRWops

RWops which take another RWops and a range, and limit I/O operations with that range

CustomRWops refactoring

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.

Implement Texture locking

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.

SDL_ttf support

This satellite library has many alloc/free-style managed objects, so it's nice candidate for SDL2pp wrapper

SDL_Image initialization 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 all over the place

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.

Texture atlas support

This is far beyond SDL scope, however such facility is very useful in the games are absolutely required for effective text renderer (see #38)

Complete SDL_ttf-related documentation

Currently mixer documentation refer to SDL_ttf website. This is inconvenient, copy function descriptions here instead. While at it, recheck completeness of \throw items.

Optional support

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.

c++1y support

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.

Texture-based text renderer

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.