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

Recent Posts

Pages: 1 2 [3] 4 5 ... 10
21
Network / [Solved] UDP receive method not compiling
« Last post by Guido_Ion on May 06, 2025, 12:35:22 am »
I'm following the tutorial Communicating with sockets for SFML 3.0 and I get this compiler error on the receive method

"no instance of overloaded function matches the argument list"

this is part of my code
Code: [Select]
#define IP 191, 168, 1, 50
#define PORT 54000
...
    sf::UdpSocket socket;
    sf::IpAddress sender(IP); // I had to add the IP here because it gave me an error if I left it like in the tutorial

    std::uint16_t x;
    std::string s;
    double d;
    sf::Packet packet;
    packet >> x >> s >> d;

    ...

    if (socket.receive(packet, sender, PORT) != sf::Socket::Status::Done)
    {
        //  error
    }

It won't tell me which is the incorrect argument, maybe it's the sender that is now sf::optional?
Was the tutorial 3.0 for networking not updated from 2.5?

I have some years of experience in C++ and SFML but I'm new to networking.
22
Graphics / Re: SDL_RenderCopyEx equivalent
« Last post by Hapax on May 05, 2025, 10:45:24 pm »
Everything kojack said would be the first things I would check. Did that fix it for you?

It looks suspiciously like you're using SFML 2..  ;D

I noticed that you're using integers for positions so could those positions be pixel positions instead of co-ordinates? If so, make sure your view is correct and convert between the types if necessary.

Also, consider if you are drawing in the range of the window.

sf::Sprite::rotate takes a float (in SFML 2) so you could just pass it as a float.

All in all, remember that for each frame, you must:
window.clear();
window.draw(someObject);
window.display();

If you're using a render texture, you'd need to:
//RENDER TEXTURE: clear, draw, display
renderTexture.clear();
renderTexture.draw(someObject);
renderTexture.display();

// use a "render" sprite to draw the render texture
renderSprite.setTexture(renderTexture.getTexture());

// WINDOW: clear, draw, display
window.clear();
window.draw(renderSprite);
window.display();
23
SFML wiki / Re: Tutorial - Understanding Text Bounds
« Last post by Hapax on May 05, 2025, 10:31:16 pm »
Thank you!

It comes up so often and is something I'd been meaning to do for a while. I thought someone else might have already done it by now.

With the "blockquote" sections, are you suggesting that, for you, they are less noticeable? I agree with this and is the intention. I consider them "notes" and the entire tutorial should be able to be read without them; they are there for extra information. Maybe, "tip" might be appropriate if going along the alert route.

I actually intentionally avoided going into the baseline definition too much since it brings with it questions, namely "how do I find the baseline of my text?" and SFML doesn't actually give the ability to answer this question. The baseline in the example(s) is the bottom of bounds when the string is just "x", for example.
Sphinx is a good one indeed. Capitals, high lower-case letters, tittles, descenders etc.. :)

I thought I had explained why there is an offset but it seems that I had not. Or, at least, not until you slowly get through the examples. So, I have added an extra note to explain the overall idea behind it (immediately after the sentence you mentioned).
24
SFML wiki / Re: Tutorial - Understanding Text Bounds
« Last post by eXpl0it3r on May 05, 2025, 03:37:22 pm »
Nice!

It's something I've been thinking about on how to best integrate into the existing tutorials, since it's a source of error for many.

I find the highlighting using quote blocks having the opposite effect on me. maybe using Alerts, as GitHub Markdown defines them, could be useful element: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts

Maybe the "Text Bounds" section becomes easier to follow, if you start up explaining what a baseline is and tha it should be advantageous to align text to it. In the past when I explained this, I often used that "Sphinx" image from Wikipedia to explain the baseline concept, but not sure it would fit here: https://en.wikipedia.org/wiki/Baseline_(typography)

Quote
However, with text, the visible text can be offset from that origin. Therefore, its (local) position is almost never (0, 0).
I think here it would help to explain why that offsets exists, before explaining how the position is calculated.
25
Window / Re: trouble running sample code from tutorial
« Last post by eXpl0it3r on May 04, 2025, 09:31:21 pm »
I don't see -std=c++17 on the build command.

For VS Code (and other IDEs) we recommend the CMake template: https://github.com/SFML/cmake-sfml-project
26
Window / Re: trouble running sample code from tutorial
« Last post by dwfunk4475 on May 04, 2025, 06:06:30 pm »
C++ is set. IDE is VS Code

terminal output:

Code: [Select]
Executing task: C/C++: g++.exe build active file

Starting build...
cmd /c chcp 65001>nul && C:\msys64\mingw64\bin\g++.exe -fdiagnostics-color=always -g C:\VSCode_Projects\Timber\myWindow.cpp -o C:\VSCode_Projects\Timber\myWindow.exe
C:\VSCode_Projects\Timber\myWindow.cpp: In function 'int main()':
C:\VSCode_Projects\Timber\myWindow.cpp:11:36: error: qualified-id in declaration before 'event'
   11 |         while (const std::optional event = window.pollEvent())
      |                                    ^~~~~
C:\VSCode_Projects\Timber\myWindow.cpp:14:17: error: 'event' was not declared in this scope
   14 |             if (event->is<sf::Event::Closed>())
      |                 ^~~~~
C:\VSCode_Projects\Timber\myWindow.cpp:14:46: error: expected primary-expression before ')' token
   14 |             if (event->is<sf::Event::Closed>())
      |                                              ^

Build finished with error(s).

 *  The terminal process terminated with exit code: -1.
 *  Terminal will be reused by tasks, press any key to close it.


27
Graphics / Re: SDL_RenderCopyEx equivalent
« Last post by kojack on May 04, 2025, 05:39:29 pm »
When drawing onto a render texture, you need to call the render texture's display() at the end to finalise it, otherwise you won't see the result.
Try putting destination.display(); after the draw.

(Also, are you drawing the render texture onto the window? You didn't show the code where that is being done so could also be an issue)
28
Graphics / SDL_RenderCopyEx equivalent
« Last post by bufalo1973 on May 04, 2025, 05:10:14 pm »
I'm trying to update a game made in C with SDL to C++ with SFML and I have some code I think it's right but I don't know enough yet of SFML to know it's right. It's a replacemente for SDL_RenderCopyEx. The problem is the window gets created but nothing shows on screen. Maybe it's a bigger problem in my code but I think it's better to check if the base is right before checking higher level.

The code is:

sf::IntRect getBox(const sf::RenderTexture &texture, int orig_x, int orig_y)
{
    sf::IntRect result;
    result.left = orig_x;
    result.top = orig_y;
    result.width = texture.getSize().x;
    result.height = texture.getSize().y;
    return result;
}

sf::IntRect getBox(const sf::Texture &texture, int orig_x, int orig_y)
{
    sf::IntRect result;
    result.left = orig_x;
    result.top = orig_y;
    result.width = texture.getSize().x;
    result.height = texture.getSize().y;
    return result;
}

void RenderCopyEx(sf::RenderTexture &destination, sf::Texture &texture, sf::IntRect srcrect, sf::IntRect dstrect, const double angle, sf::Vector2i center, bool flip)
{
    if(srcrect.width == 0 && srcrect.height == 0)
        srcrect = getBox(texture);
    if(dstrect.width == 0 && dstrect.height == 0)
        dstrect = getBox(destination);
    sf::Sprite sprite;
    sprite.setTexture(texture);
    sprite.setTextureRect(srcrect);
    sprite.setOrigin(center.x, center.y);
    sprite.rotate(angle);
    if(flip)
        sprite.scale(-1, 1);
    sprite.move(dstrect.left, dstrect.top);
    destination.draw(sprite);
}
 

Thank you everyone for reading  :)
29
General / Re: 15 unresolved externals
« Last post by GavinWilliams on May 04, 2025, 07:06:10 am »
I think I've fixed it. Not sure what was happening at first when I was using the 32 bit 'package'. But I ended up with a mixed configuration, once I updated the paths to the 64 bit sfml installation, I got it running in 64 bit mode. That's fine for me, as I'm introducing my 10 year old to C++ and I want to use sfml as a framework so that he doesn't have to build a Win32 application layer & rendering engine. I think that's all just too much for him right now, whereas with sfml he can transfer his skills with MS Makecode & C# console. And the architecture doesn't matter to much.
30
General / 15 unresolved externals
« Last post by GavinWilliams on May 04, 2025, 04:20:03 am »
I've followed the Visual Studio setup. Intellisense is picking up the libraries but I have 15 unresolved externals (link errors) in the error list.

Just to go over what I've done...

* Downloaded the 32 bit sfml package for windows
* Copied the sfml files to G:\Tools\SFML-3.0.0\
* Set C++ Language Standard = Cpp17
* Set C++ / General / Additional Include Directories = G:\Tools\SFML-3.0.0\include
* Set Linker / General / Additional Library Directories = G:\Tools\SFML-3.0.0\lib
* Set Linker / Input / Additional Dependencies (Debug) = sfml-system-d.lib;sfml-graphics-d.lib;sfml-audio-d.lib;sfml-network-d.lib;sfml-window-d.lib;%(AdditionalDependencies)
* Set Linker / Input / Additional Dependencies (Release) = sfml-system.lib;sfml-graphics.lib;sfml-audio.lib;sfml-network.lib;sfml-window.lib;%(AdditionalDependencies)
* Copied sfml-audio-3.dll, sfml-audio-d-3.dll, etc to <soln>/x64/Debug

I get the following errors...

unresolved external symbol "__declspec(dllimport) public: bool __cdecl sf::WindowBase::isOpen(void)const " (__imp_?isOpen@WindowBase@sf@@QEBA_NXZ) referenced in function main

unresolved external symbol "__declspec(dllimport) public: class std::optional<class sf::Event> __cdecl sf::WindowBase::pollEvent(void)" (__imp_?pollEvent@WindowBase@sf@@QEAA?AV?$optional@VEvent@sf@@@std@@XZ) referenced in function main

unresolved external symbol "__declspec(dllimport) public: static struct sf::RenderStates const sf::RenderStates::Default" (__imp_?Default@RenderStates@sf@@2U12@B) referenced in function main

unresolved external symbol "__declspec(dllimport) public: virtual void __cdecl sf::Window::close(void)" (__imp_?close@Window@sf@@UEAAXXZ) referenced in function main

unresolved external symbol "__declspec(dllimport) public: virtual __cdecl sf::CircleShape::~CircleShape(void)" (__imp_??1CircleShape@sf@@UEAA@XZ) referenced in function main

etc

Just some extra info, if I change the build to target x86 I get squiggles under everything.

I've also tried the 64 bit sfml files to match up with the target architecture, but it's the same linker issue.

Regarding the tutorial page - it says nothing about the architecture, maybe the author assumes we should know if 32 bit applications can run on x64 - sound right to me. Another thing, at the end of the tutorial it says...

'don't forget to copy the SFML DLLs to same directory as your compiled executable' - why would we forget if we never even thought of it?! After all, didn't I just copy sfml to my dev drive and link to it. And at the start of the tutorial it says...

'You can then unpack the SFML archive wherever you like. Copying headers and libraries to your installation of Visual Studio is not recommended, it's better to keep libraries in their own separate location' - I guess they don't mean the dll's as well - though it doesn't say anything about that.

Release build works, but debug build doesn't.
Pages: 1 2 [3] 4 5 ... 10