Comments (22)
Are these 8-bit surfaces?
from sdl.
Format of the surface is SDL_PIXELFORMAT_ARGB8888.
from sdl.
Same thing happened to me, and I thought it was because I've been using the wrong format all this time. I changed it to SDL_PIXELFORMAT_RGBA32
and it works now.
from sdl.
Format is obtained from
SDL_Texture* uiTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_UNKNOWN, SDL_TEXTUREACCESS_STREAMING, width, height);
format = SDL_GetNumberProperty(SDL_GetTextureProperties(uiTexture), SDL_PROP_TEXTURE_FORMAT_NUMBER, NULL);
SDL_Surface* sdlscrn = SDL_CreateSurface(width, height, format);
Forcing format to SDL_PIXELFORMAT_RGBA32 does not fix the problem and causes wrong colours.
from sdl.
@0x1F9F1, is this related to the blitter changes?
from sdl.
After some testing it seems this commit caused the regression: 875c4f0
from sdl.
Can you see where indexed format surfaces are being used in your code?
from sdl.
It might be this:
/*-----------------------------------------------------------------------*/
/**
* Load an 1 plane XBM into a 8 planes SDL_Surface.
*/
static SDL_Surface *SDLGui_LoadXBM(int w, int h, const Uint8 *pXbmBits)
{
SDL_Surface *bitmap;
Uint8 *dstbits;
const Uint8 *srcbits;
int x, y, srcpitch;
int mask;
srcbits = pXbmBits;
/* Allocate the bitmap */
bitmap = SDL_CreateSurface(w, h, SDL_GetPixelFormatForMasks(8, 0, 0, 0, 0));
if (bitmap == NULL)
{
Log_Printf(LOG_ERROR, "SDLGui: failed to allocate bitmap: %s", SDL_GetError());
return NULL;
}
srcpitch = ((w + 7) / 8);
dstbits = (Uint8 *)bitmap->pixels;
mask = 1;
/* Copy the pixels */
for (y = 0 ; y < h ; y++)
{
for (x = 0 ; x < w ; x++)
{
dstbits[x] = (srcbits[x / 8] & mask) ? 1 : 0;
mask <<= 1;
mask |= (mask >> 8);
mask &= 0xFF;
}
dstbits += bitmap->pitch;
srcbits += srcpitch;
}
return bitmap;
}
from sdl.
That's very likely. Are you assuming a palette on there?
The other possibility, since I noticed the issue is with text, is that you're using SDL_ttf and haven't updated to the latest code.
from sdl.
Okay, so a change we just made is that 8-bit surfaces do not get a palette by default now; the idea is that trying to blit from an indexed surface without a palette will just memcpy() the indices instead of try to map the colors, which can be very useful when you instead to have a destination surface where you're adjusting the palette and just want to fill in the new data from another surface without mapping colors during the blit.
(This is apparently how DirectDraw does it, too.)
The quickest fix: apply a palette to the new thing!
SDL_Palette *palette = SDL_CreatePalette(2);
if (palette) {
/* Create a black and white bitmap palette */
palette->colors[0].r = 0xFF;
palette->colors[0].g = 0xFF;
palette->colors[0].b = 0xFF;
palette->colors[1].r = 0x00;
palette->colors[1].g = 0x00;
palette->colors[1].b = 0x00;
SDL_SetSurfacePalette(surface, palette);
SDL_DestroyPalette(palette);
}
@slouken will have to say if I screwed up that code completely, it's untested.
(Also, @slouken, README-migration really needs a code example for this.)
But my suspicion is that SDL_ttf just needs to be updated and it'll solve this problem.
from sdl.
This is the biggest change likely to bite people unexpectedly in SDL3. I'm really tempted to roll it back.
from sdl.
I'm okay with a rollback, but the one-time fix for things bit by this is dirt-simple and extremely localized.
Maybe a separate function that explicitly creates a surface without a palette would be better though, so you don't get a surprising result from the usual path, and only use it when you definitely want it? I think the new behavior is good, but it could be that the default isn't.
from sdl.
That's true, maybe documentation is enough. I'll add a note to README-migration.md and see how that goes.
from sdl.
FWIW, having the new behavior is as simple as SDL_SetSurfacePalette(surface, NULL);
after you create it.
from sdl.
But, having a palette on a surface isn't very useful until you set the colors, so you might as well set the palette explicitly. If people are doing that, they're much more likely to either not need to set one, or set a palette already shared with other surfaces, so creating one initially is just wasteful.
from sdl.
Maybe it would be helpful to add SDL_CreatePaletteForSurface(surface)
, which automatically creates it with the right number of entries for the bit depth?
from sdl.
@icculus: Thank you for the code. This fixes my issue. But I think it would be great if there was a simpler solution.
/* Create a black and white bitmap palette */
palette = SDL_CreatePalette(2);
if (palette == NULL)
{
Log_Printf(LOG_ERROR, "SDLGui: failed to allocate palette: %s", SDL_GetError());
return NULL;
}
palette->colors[0].r = palette->colors[0].g = palette->colors[0].b = 255;
palette->colors[1].r = palette->colors[1].g = palette->colors[1].b = 0;
SDL_SetSurfacePalette(bitmap, palette);
SDL_DestroyPalette(palette);
In case it still matters: SDL_ttf is not used.
from sdl.
Update: Seems this one works too:
/* Create an all white bitmap palette */
palette = SDL_CreatePalette(1<<8);
if (palette == NULL)
{
Log_Printf(LOG_ERROR, "SDLGui: failed to allocate palette: %s", SDL_GetError());
return NULL;
}
SDL_SetSurfacePalette(bitmap, palette);
SDL_DestroyPalette(palette);
from sdl.
I've made it even simpler, adding SDL_CreateSurfacePalette():
/* Create an all white bitmap palette */
if (!SDL_CreateSurfacePalette(bitmap))
{
Log_Printf(LOG_ERROR, "SDLGui: failed to allocate palette: %s", SDL_GetError());
SDL_DestroySurface(bitmap);
return NULL;
}
from sdl.
In any case, with the new utility function and documentation in README-migration.md, I think we're in a good place now.
Thanks!
from sdl.
from sdl.
You'd have to have two calls anyway, one to create a surface with a palette, and one to get the palette. This way the order of operations is simple and obvious. You create the surface, you create the palette, you take that palette and set colors, and you move on.
from sdl.
Related Issues (20)
- Should SDL_GAMECONTROLLERCONFIG be SDL_GAMEPADCONFIG? HOT 1
- No implementations for SDL libraries found.
- [SDL_video] SDL_GetWindowPixelFormat still returns Uint32 instead of an SDL_PixelFormat value HOT 4
- Suggestion to consider modularity of SDL and separate libraries HOT 2
- Patching with SDL_migration.cocci does not work HOT 2
- SDL_SINT64_C vs SDL_INT64_C define mistake
- SDL2: sometimes linux automatically rescales window to a minimum size HOT 1
- Memory Leak with Newest SDL3 HOT 10
- Windows CI failing in icon.h creation
- SDL renderer "ERROR: Could not get a framebuffer" when running a SDL-release-2.30.5 program on a Debian system without X. HOT 4
- Rename some Get/Set functions to match the new naming style HOT 5
- Incorrect usage of GetStringUTFChars/NewStringUTF in android jni code
- SDL_Renderer vulkan backend fails while re-entering the app on android HOT 3
- Gamepad not recognized by SDL but via Linux and gtk HOT 2
- Clarification of thread safety of SDL_GetStringRule HOT 4
- [Suggestion] Make SDL_GetWindowOpacity() return the opacity value, instead of using an out parameter. HOT 2
- Is SDL_GetWinRTFSPath() still needed? HOT 1
- ios wrong documents path
- Emscripten input callbacks HOT 1
- Locale change causes Android app to restart, despite configChanges settings
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 sdl.