Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - SFMLNewGuy

Pages: [1] 2 3 ... 5
1
Graphics / Understanding how to create X type of Shader?
« on: January 04, 2022, 03:48:08 am »
I just had a quick question? How do people typically figure out different types of shader effects (2D)? Say you want an explosion, or a wind effect, or a fountain? How do people figure this out? Do they just find out the formulas that emulate X type of effect?

Is there a general place where you can find templates of just about anything you can think of? Like a plug-in-play almost where you can fiddle with the variables?

Thanks.

2
Graphics / Re: Vertex Array shapes
« on: March 31, 2021, 02:41:38 pm »
So I just took the same sf::VertexArray container and after trying it as Quad, changed the colors and drew it as a sf::LineStrip.

It sort of worked? Except I have lines running diagonally through the rectangles as well. I tried all the various sf::Lines types just to make sure. I'm sure this is an easy fix?

3
Graphics / Vertex Array shapes
« on: March 31, 2021, 02:32:02 pm »
Hello,

As of right now, I'm using Rectangles as a Tile Map as textures aren't of importance right now. It was a simple transparent fillColor, 1.f outline, sf::White outline color. So I'm trying to use VertexArray without textures (sf::Quad). Everything was fine until I realized I don't think colors work like that now.

So would I add an extra 4 lines over the current square to create an outline? Perhaps, just draw the same quad coordinates as lines? I'm just making sure there isn't an easier way.

Thanks

4
General discussions / Re: Why would I choose SFML over SDL2?
« on: December 24, 2020, 02:31:13 am »
Hello,

When I first started to program I went back and forth over SDL and SFML. Multiple times I would decide, "Nah, I like the other better you can do X or Y easier."

You will find a lot of games (industry even) made with SDL and it has been around A LOT longer and has a bigger community. What you will find is SDL feels more like working with C, or at least that's what I felt like to me. It's written in C behind the scenes. I also felt like it gave you a lot more control in certain aspects. It's harder to use for sure. I can't recall exactly what I loved more about it off the top of my head. This might not be a fact, but I believe they are done with it as well and SFML keeps improving and older games become outdated. But because of that, you won't ever have to find the correct version like SFML.

SFML is laid out very nicely using objects and just so simple to work with C++. I've committed to SFML long term, I'm not 100% that was the right move or not, but both are great libraries. A lot of people sure have helped me here including the founders.

Either way, you can complete an awesome 2D game with any of them and I suggest you actually build a small little engine using both. Build the same game even with the different libraries. It seems people will live or die with one or the other.

BOOKS I highly suggest in order:

(SFML)
Beginning C++ Game Programming 2nd Edition:
 (Creates LumberJack game, Pong, Zombie Arena Shooter, 2 player shapes game, space invaders at the end)
SFML Game Development By Example by Raimonday Pupius (easily my favorite) :
 (Bouncing Mushroom, Snake, 2D platformer, Design Patterns, Components, complex GUI System, RPG, Online RPG) it also has a follow-up book called Mastering SFML, which goes into OpenGL and shaders and building a map editor)
SFML Game Development:

 Journey through making a top-down airplane shooter (and multiplayer), and gives you a good idea of the progression on making a complete project and making a cool game engine with some design patterns. Goes through some shaders for the missiles
Procedural Content Generation using C++:
(Teaches A*, Maze Generation, and applying new stuff to a barebone action roguelike engine. It's a really basic game engine though) but explaining A* and randomization was very helpful
SFML Essentials:
(Basic game loop, and running through what SFML offers and show off some animations, shaders, and multiplayer)
C++ Game Development By Example, Siddharh Shekar:
I never finished this book, it's really great for beginners though, and would help anyone. It creates a phone like a side scroller game. It leads into OpenGL later
You will find some amazing YouTube videos and stuff on Udemy as well. Specifically, a guy who made an Action RPG from scratch (200 videos or something).

NOTE: I would NOT recommend SFML Blueprint, at all. I tried many times to give it a chance. Just no.  :-X But if you really must, the first few chapters on asteroids are very nice.

SDL:
Foo's Tutorials: -
Search it up on google, it's a great starting point
The Black Art of Multiplatform Game Programming, Jazon Yamamoto C:
Really awesome SDL book, progresses a game engine, paddle game, tilemaps, scene management, factory design and script,s and finishes with a really cool horizontal side scroller space game.
Game Programming in C++ Creating 3D Games (Game Design), Sanjay Madhav -
 Teaching you some really cool things and does an asteroid project, pathfinding, tiles, and eventually leads into OpenGL from SDL.
SDL Game Development, Shaun Mitchell:
 This was a good book to read when I first started SDL, but I had a lot of trouble with it at the time because stuff was outdated.


5
Graphics / Re: sf::ConvexShape and sf::Mouse
« on: December 24, 2020, 01:52:16 am »
Thanks Laurent,

Quote
I don't understand the question. How can you compare that to sf::CircleShape, since you can't set the position of the circle's points like you do with a convex Shape?

Yeah, sorry for not explaining that better. I just thought since you can set the position of the sf::CircleShape(10,3) and it takes into consideration the origin and local points already that sf::ConvexShape would do the same? Does that make more sense? I thought it would be the same based on being derived from shape. Unless I'm just not understanding it correctly.

Or was it purposely left like that because at specific times you would need it to not take the position and origin into account? It's the only reason I could think of and I don't know why setPosition wouldn't take it all into account? Maybe that's a stupid question  :-[, sorry  ;D?

Thanks Laurent.

PS: Random question about this message board, how do you highlight a word on here so that it has the quote backdrop behind it but still stays in the sentence? Usually, where I make a word bold, people put that quote backdrop behind it too make it easier to read.

TLDR; Why are the setPosition functions of sf::ConvexShape and sf::CircleShape different? One takes into account the local and origin and the other you have to manually add them. In what type of situation would you need it like that? Thanks

6
Graphics / Re: sf::ConvexShape and sf::Mouse
« on: December 22, 2020, 08:42:52 pm »
EDIT: I got the mouse to be pin-point, by removing the origin, but my question regarding it would still be nice to be answered. Thanks

Hey Laurent,

Thanks for helping me again, hope you are doing well. Do you mind explaining why it can't have an origin and position? I understand that they are local coordinates and then the setPosition puts them where you want.

I got the mouse position relative to the window and then subtracted the position of the triangle. It's pretty close, but based on what you said, it requires some change to be exact/pin-point. I'm also confused about why this is different than using like sf::CircleShape(10,3) and doesn't respond with the mouse the same?

The reason I'm not using the circle shape for a triangle is I didn't see a way to set individual points, thus I'm using sf::ConvexShape.

Below is a picture of my project. The white arrow is approximately where my mouse is.

Uploaded picture: https://ibb.co/7zGXd2K
Source Code: https://codeshare.io/5v3xw4

7
Graphics / sf::ConvexShape and sf::Mouse
« on: December 21, 2020, 09:20:00 pm »
Hello,

Hope you all are doing well and getting ready for the holidays. I had a quick question regarding sf::ConvexShape.

sf::Vector2f startPos{ 0,0 };
        sf::ConvexShape shape{ 3 };
        shape.setPoint(0, { 100,0 });
        shape.setPoint(1, { 100,100 });
        shape.setPoint(2, startPos);

        shape.setFillColor(sf::Color::Transparent);
        shape.setOutlineThickness(5.f);
        shape.setOutlineColor({ 120,0,0 });
        shape.setOrigin(150, 150);
        shape.setPosition(640, 384);

and in update:
auto mousePos = sf::Mouse::getPosition(window);
if(clicked)
        shape.setPoint(2, sf::Vector2f(mousePos));
 

Now all I'm trying to do is have point 2 follow the mouse position. The mouse position seems way off though. I'm not using a view, it's just a barebone project. I've tried sf::Mouse::getPosition(window), I've tried using mapPixelToCoords(sf::Mouse::getPosition(window)). But mapCoordsToPixel has got me the most accurate results, yet still it's off.

Anyone see what my problem could be? I'm trying to setup a little sandbox to really get familiar and have a good understanding with cos/sin.

Thanks!

8
General / Re: Moving a point around a falling circle
« on: December 14, 2020, 12:53:10 pm »
Hey Laurent,

Appreciate the input. When I put it radians I get no change for some reason, which makes me think I'm not doing something right. As of now, I got it working a lot better. The ball bounces off the ground and "I THINK" the line is spinning around the ball based on the angle. When it lands and is static the 2nd line spasms out.

{
circle.setPosition(m_position.x , m_position.y);
circle.setRadius(radius);
circle.setOutlineThickness(0.5f);
circle.setOutlineColor(sf::Color::White);
circle.setFillColor(sf::Color::Transparent);
//circle.setOrigin(radius / 2.f, radius / 2.f);
/*
        p.x = circle_center.x + circle_radius * cos(angle_in_rad);
        p.y = circle_center.y + circle_radius * sin(angle_in_rad);
        sf::Vector2f p{ (circle.getRadius() / 2.f) + circle.getRadius() * cosf(fAngle),
                        (circle.getRadius() / 2.f) + circle.getRadius() * sinf(fAngle) };
*/

sf::Vector2f p1{ circle.getPosition().x + circle.getRadius(),
                 circle.getPosition().y + circle.getRadius()  };       
sf::Vector2f p2{ circle.getPosition().x + circle.getRadius() / 2.f + circle.getRadius(),
                 circle.getPosition().y + circle.getRadius() / 2.f + circle.getRadius()};
float angle = (atan2f(m_velocity.y, m_velocity.x) * 180) / 3.14159;
// angle = toRadians(angle);
const sf::Vector2f newPos{ radius * cosf(angle) + p2.x,
                           radius * sinf(angle) + p2.y };
               
engine->getWindow()->drawLine(p1, newPos, sf::Color::Yellow); // sf::Lines
engine->getWindow()->draw(circle);
}
 

Any additional help would be appreciated.

9
General / Moving a point around a falling circle
« on: December 14, 2020, 10:37:57 am »
Hello,

This is where my lack of knowledge of math affects me the most. So I have a regular circle that appears where you click the mouse and begins to fall using basic velocity and acceleration.

I have a line created in the middle of the circle to represent the angle the circle is falling. I can't seem to get the last point to rotate around the circle. At the moment I'm just trying to have it follow the circle's path just in general.

circle.setPosition(m_position.x - fOffsetX, m_position.y - fOffsetY);
circle.setRadius(radius);
circle.setOutlineThickness(0.5f);
circle.setOutlineColor(sf::Color::White);
circle.setFillColor(sf::Color::Transparent);
float angle = (atan2(circle.getPosition().y ,   circle.getPosition().x ) * 180) / 3.141;
circle.rotate(angle);

sf::Vector2f l1{ circle.getPosition().x + circle.getRadius() , circle.getPosition().y + circle.getRadius() };
sf::Vector2f l2{ circle.getPosition().x + circle.getRadius() * 2 , circle.getPosition().y + circle.getRadius() };

drawLine(l1, l2, sf::Color Yellow)
 

Without telling you every single cosf and sinf formula I configured (aka probably made up) for 'l2' can anyone just tell me off the top of their head how I would accomplish this? Perhaps explaining quickly why would be awesome.

Thanks, everyone have a great week and be safe.

10
Graphics / Texture loadFromFile every frame.
« on: December 04, 2020, 10:03:12 pm »
Hello,

So I'm getting more and more familiar with sf::RenderTexture. It has REALLY helped with this current project since it requires drawing millions of pixels. I finally got it to run smooth switching to it. What I am concerned about is the texture loading the sf::image being drawn to every frame.

It's running great, as I said, but I'm just wondering if this is 'okay' to do and if not, what would be the appropriate solution? Is loading from the image 'okay', but loading up a new texture from a file different? I'm just curious about the future and if I had more stuff going on it would cause problems.

Thanks

void Worms_Part1::onDraw() {

        for (int y = worldMin.y; y <= worldMax.y; ++y) {
                for (int x = worldMin.x; x <= worldMax.x; ++x) {
                        const sf::Vector2i p(x, y);
                        if (m_map.isInBounds(p)) {

                                m_image.setPixel(x, y, m_map(p).isLand ? sf::Color(58, 110, 45) : sf::Color(45, 198, 198));
                        }
                }
        }

        m_renderTexture.clear();
       
        m_texture.loadFromImage(m_image);
        m_renderTexture.draw(sf::Sprite(m_texture));
        m_renderTexture.display();
       
        m_renderSprite.setTexture(m_renderTexture.getTexture());
        window.draw(m_renderSprite);
}

11
Graphics / RenderTexture and editting pixels Help
« on: November 22, 2020, 12:37:32 am »
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.

12
General discussions / Re: Menu, and text table library for simple UI?
« on: November 22, 2020, 12:13:24 am »
There really isn't much out there, but this was a good start for me. I had the best experience with TGUI.

https://blog.rubenwardy.com/2020/01/21/creating-game-guis-in-sfml/

Another one I'll mention, which I've loved the most is the GUI System from the book SFML Game Development By Example. He walks you through a pretty sweet system that you can easily expand upon. It has all the basic widgets and if you get the source for his Master SFML version, he expands on it a bit more.


13
Graphics / Re: Little help with 'getPixelPtr()'
« on: October 22, 2020, 03:49:44 am »
Thanks a lot! I appreciate all the information. I plan to mess around with it more this weekend!

Thanks again!

14
Graphics / Re: Little help with 'getPixelPtr()'
« on: October 19, 2020, 05:07:52 am »
Hey Fallahn,

Sorry to get back late. Had a personal emergency that is all good now!

So I uploaded it to GitHub for you! I appreciate the help by the way and on the previous message!

https://github.com/LedLoaf/RaycastingSFML

15
Graphics / Little help with 'getPixelPtr()'
« on: October 13, 2020, 09:14:30 am »
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.

Pages: [1] 2 3 ... 5
anything