Comments (4)
What's your use case, if I may ask? https://wiki.libsdl.org/SDL2/SDL_Palette says one should never allocate palette manually (yet there are SDL_(Alloc|Free)Palette
functions exactly for this case, hmm), so it doesn't look like there's need for SDL_Palette
wrapper. May it be that only SetSurfacePalette(SDL_Palette*)
method for Surface
is actually needed?
from libsdl2pp.
My use case is rendering 8-bit surfaces with palette 🙈 (I'm rewriting one of the old DOS RPGs in modern c++)
DOS games often use palette animations etc, so I need to modify palettes and explicitly assign them to surfaces.
RAII palette class/setter you mention would be nice to have 👍
from libsdl2pp.
Thanks for clarification, but that doesn't really answer the main question of whether you use AllocPalette. Code excerpt could also be useful
from libsdl2pp.
sorry, I use it like this:
Palette::Palette() : _id(0), _index(0) {
common_palette = Resource::load(Resource::ResCommonPalette);
if (common_palette.size() != 0x40 * 3)
throw Exception("invalid palette.000 size: " + std::to_string(common_palette.size()));
_palette = SDL_AllocPalette(256);
if (!_palette)
throw SDL2pp::Exception("SDL_AllocPalette");
}
void Palette::rotate() {
++_index;
SDL_Color colors[0x100];
for(auto i = _ranges.begin(); i != _ranges.end(); ++i) {
unsigned start = i->first, size = i->second;
for(unsigned c = 0; c < size; ++c) {
unsigned new_c = start + ((c - _index) % size);
uint8_t *src = new_c >= 0xc0?
common_palette.data() + (new_c - 0xc0) * 3:
palette.data() + new_c * 3;
SDL_Color &color = colors[c];
color.r = *src++;
color.g = *src++;
color.b = *src++;
}
SDL_SetPaletteColors(_palette, colors, start, size);
}
}
Palette::~Palette()
{ SDL_FreePalette(_palette); }
later I use SetSurfacePalette
to associate palette with surface and it's working fine :)
from libsdl2pp.
Related Issues (20)
- Mingw64 & MSYS2 ; unable to compile libSDL2pp (linking to stdlib failed) HOT 3
- Mix_Init: MP3 support not available HOT 4
- Malformed build command HOT 2
- Compile errors from SDL2pp/external/libcpp_optional.hh HOT 2
- Error compiling example(and any other program) HOT 5
- Cant Compile SDL2PP HOT 2
- Error when using Cmake on Windows HOT 1
- Problem in VS Code. HOT 2
- modern C++ library should use modern CMake
- how to compile with emscripten? HOT 4
- Examples UB: exception out of main HOT 4
- Update bundling instructions in readme
- Bump C++ version in the repository description
- Linking failed on macos HOT 2
- Error when linking under MinGW
- Missing cmake file HOT 1
- CMake error finding SDL_image HOT 4
- SDL2pp.hh cannot find a directory to SDL_stdinc.h HOT 14
- Will there be a SDL2pp wrapper over Vulkan? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libsdl2pp.