Hello,
So I've been translating projects from a great
YouTuber named Javidx9, to SFML. This project
"Line Of Sight" is the project I'm translating to SFML. At the end of the video, he uses a light_cast.png sprite (cool effect) that follows the mouse, and pixels are used to put the shadow over it.
He defines the variables like this (directly from the source), and this has been the most difficult part figuring out what is a
sf::Image, sf::Sprite, sf::Texture, sf::RenderTexture.olc::Sprite *sprLightCast;
olc::Sprite *buffLightRay;
olc::Sprite *buffLightTex;
On initialization:
sprLightCast = new olc::Sprite("light_cast.png");
// Create some screen-sized off-screen buffers for lighting effect
buffLightTex = new olc::Sprite(ScreenWidth(), ScreenHeight());
buffLightRay = new olc::Sprite(ScreenWidth(), ScreenHeight());
return true;
On userUpdate, which also draws. https://github.com/OneLoneCoder/olcPixelGameEngine/blob/master/Videos/OneLoneCoder_PGE_ShadowCasting2D.cpp#L434 (lines 434 to 444)
...
// Clear offscreen buffer for sprite
SetDrawTarget(buffLightTex);
Clear(olc::BLACK);
// Draw "Radial Light" sprite to offscreen buffer, centered around
// source location (the mouse coordinates, buffer is 512x512)
DrawSprite(fSourceX - 255, fSourceY - 255, sprLightCast);
// Clear offsecreen buffer for rays
SetDrawTarget(buffLightRay);
Clear(olc::BLANK);
On userUpdate, which also draws. https://github.com/OneLoneCoder/olcPixelGameEngine/blob/master/Videos/OneLoneCoder_PGE_ShadowCasting2D.cpp#L473 (473-477)
...
// Wherever rays exist in ray sprite, copy over radial light sprite pixels
SetDrawTarget(nullptr);
for (int x = 0; x < ScreenWidth(); x++)
for (int y = 0; y < ScreenHeight(); y++)
if (buffLightRay->GetPixel(x, y).r > 0)
Draw(x, y, buffLightTex->GetPixel(x, y));
So defining these variables correctly has been my problem. It looks like
buffLightRay would be a
sf::Image and
buffLightText, but I'm getting hung up on the last portion where I need to change the pixel. I believe his
draw() function is drawing a single pixel, which I have an equivalent function. The reason I thought I needed a
sf::RenderTexture was that he mentioned an offscreen drawing. But, I don't think I need that?
Hope that makes sense, thank you have a great day.