in c++ SDL2 i would want to access pixels and draw on a 1-bit surface same way i do with a 8-bit surface but i'm missing something i don't see.
in 8-bit surface this works fine (the pixel take the expected color among palette->colors):
SDL_Surface * surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 8, SDL_PIXELFORMAT_INDEX8);
SDL_Color colors[2] = {{0, 0, 0, 255}, {255, 255, 255, 255}};
SDL_SetPaletteColors(surface->format->palette, colors, 0, 2);
Uint8* pixels = (Uint8*)surface->pixels;
for(int i = 0; i < pixelsCount; i++){
if(*geometrical condition*){
pixels[i]=1;
}else{
pixels[i]=0;
}
}
with a 1-bit surface i get a non 0 exit because of assignment (last if):
SDL_Surface * surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 1, SDL_PIXELFORMAT_INDEX1MSB);
SDL_Color colors[2] = {{0, 0, 0, 255}, {255, 255, 255, 255}};
SDL_SetPaletteColors(surface->format->palette, colors, 0, 2);
Uint8* pixels = (Uint8*)surface->pixels;
for(int i = 0; i < pixelsCount; i++){
if(*geometrical condition*){
pixels[i]=1;
}else{
pixels[i]=0;
}
}
What's the right pixel assignment in 1-bit case?
well, this worked for me, maybe it is not the best solution but:
remind, 1-bitperpixel surface, SDL_PIXELFORMAT_INDEX1MSB.