So basically what i want to do is create a 2D tile based rendering system in C++ that renders each pixel on the screen manually. Rendering an individual pixel on the screen works just fine (or render the whole screen blue for example). But i want to load the individual pixel colours of my sprites out of a spritesheet image and heres my problem:
I am able to create the image and access the pixels of the image, however the individual pixel values seem to be wrong. (I compared the pixel values with the supposed hexadecimals on paint.net)
Heres my code for the spritesheet:
SpriteSheet::SpriteSheet(std::string path, int tileWidth, int tileHeight)
:
path(path),
tileWidth(tileWidth),
tileHeight(tileHeight)
{
image = IMG_Load(path.c_str());
if (image != NULL){
width = image->w;
height = image->h;
pixels = (Uint32 *) image->pixels;
std::cout <<std::hex << pixels[17] << std::dec << std::endl;
//this prints out: 3030303 when it should be FF007F46
}
else{
std::cout << "SpriteSheet couldnt be loaded!" << std::endl;
}
}
Note that the pixel format is: AARRGGBB
Edit: I tried using a ".jpg" instead of a ".png" and i got different colour values again, but still not the right ones.
Edit2: I'm pretty sure the pixel format in which my image is getting loaded in is wrong.
Any ideas how to get it to ARGB8888? I tried using SDL_ConvertSurface
and SDL_ConvertSurfaceFormat
but i can't seem to get it right.