Johannes Bauer schrieb:
What am I doing wrong?
Some code to demonstrate the problem - I still don’t see any solution.
This is weird.
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include “SDL.h”
SDL_Surface *init(int Width, int Height) {
Uint32 RMask, GMask, BMask, AMask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
RMask = 0xff000000;
GMask = 0x00ff0000;
BMask = 0x0000ff00;
AMask = 0x000000ff;
#else
RMask = 0x000000ff;
GMask = 0x0000ff00;
BMask = 0x00ff0000;
AMask = 0xff000000;
#endif
SDL_Surface *SubSurface = SDL_CreateRGBSurface(SDL_SWSURFACE |
SDL_SRCALPHA, Width, Height, 32, RMask, GMask, BMask, AMask);
// SDL_SetAlpha(SubSurface, SDL_SRCALPHA, SDL_ALPHA_OPAQUE);
return SubSurface;
}
void dump(SDL_Surface x) {
Uint8 r, g, b, a;
SDL_GetRGBA(((Uint32)x->pixels)[0], x->format, &r, &g, &b, &a);
printf(“RGBA %2x %2x %2x %2x\n”, r, g, b, a);
}
int main(int argc, char **argv) {
SDL_Init(SDL_INIT_VIDEO);
{
SDL_Surface *src, *dst;
src = init(1, 1);
dst = init(1, 1);
((Uint32*)(src->pixels))[0] = 0x11223344;
((Uint32*)(dst->pixels))[0] = 0x0;
SDL_BlitSurface(src, NULL, dst, NULL);
dump(src);
dump(dst);
SDL_FreeSurface(src);
SDL_FreeSurface(dst);
}
SDL_Quit();
return 0;
}
So it should blit “src” on “dst”. What it outputs is:
RGBA 44 33 22 11
RGBA 0 0 0 0
This is way weird. Shouldn’t it output something like
RGBA 3 2 1 0
I’m pretty desperate right now. This is like the most basic primitive
SDL offers and I get it to work most of the time (my game works,
actually) - but currently I’m incredibly stuck. Did it all just work by
accident so far?
Greetings,
Johannes