I'm trying to program a triangle rasterizer and have problems with the right pixel values. When putting a the pixel value from one surface to another I use buffer(/direct) pixel access. My Problem is that when I "blit" the whole Image. The color values get swapped.
Here is the result picture:
tux drawn with custom blit routine
Here is a simplified version of the my code:
src = PySurface_AsSurface(sobj);
dest = PySurface_AsSurface(dobj);
uint32_t* src_buff = (uint32_t*) src->pixels;
uint32_t* dest_buff = (uint32_t*) dest->pixels;
SDL_LockSurface(dest);
SDL_LockSurface(src);
int x, y;
for(y = 0; y < src->h; y++) {
for(x = 0; x < src->w; x++) {
uint32_t c = src_buff[y * src->w + x];
dest_buff[(y + y1) * dest->w + (x + x1)] = c;
}
}
SDL_UnlockSurface(src);
SDL_UnlockSurface(dest);
Apparently the pixel order in the surfaces are different, but shouldn't they be all either big endian or little endian, because they are on the same machine?
Do I have to change the whole code, or is this normally a valid and quick and dirty way of doing things?
Thanks for help in advance.