Hello everyone,
According the the SFML documents it says
getPixelPtr() -
The returned value points to an array of RGBA pixels made of 8 bits integers components. The size of the array is width * height * 4 (getSize().x * getSize().y * 4). Warning: the returned pointer may become invalid if you modify the image, so you should never store it for too long. If the image is empty, a null pointer is returned.
So I'm interested how this works and if someone can give a bare minimum example? I find this all very interesting, especially how you can load a raw png file for example.
At the moment I am doing some raycasting and trying to figure out a way to make it more efficient because it's a bit slow (from the transfer to RGBA from ARGB) and I was wondering if this would be something to look too? When I am setting a pixel color I'm doing:
(loop rays)
(drawCeiling)
(calculate offset)
(loop wallTop to wallBottom)
auto texelColor = images[textureNum]->getPixel(textureOffsetX,textureOffsetY)
drawPixels(x,y,texelColor) // overloaded for sf::Uint32 and sf::Color
(draw floor)
----
void drawPixel(int x, int y, sf::Uint32 color) {
// The example I was learning from used ARGB so a nice gentleman gave me the convert
const sf::Uint32 rgbaPixel =
((color & 0xff000000) >> 24) | ((color & 0x00ffffff) << 8); // or to an RGBA uint32:
colorBuffer->setPixel(x,y,sf::Color(rgbaPixel));
}
void drawPixel(int x, int y, sf::Color color) {
colorBuffer->setPixel(x, y, color);
}
How would I do something simular using the Ptr function and I know it returns Uint8's, but the image it self is created 64x64 so I wouldn't multiple by 4 right?
Thanks, be safe and take care everyone.