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.


Topics - Martin Lefevre

Pages: [1]
1
Graphics / Cannot call draw() from constant RenderTarget object.
« on: April 14, 2020, 05:49:02 pm »
Hi,
I made a function that is supposed to draw a text on a RenderTarget. But I an error message saying that "No instance of overloaded function could be found.". Here is my function:
void DrawStringInBox(const sf::RenderTarget &xindox, const std::string& String, const sf::Font& font) {
        sf::Text text(String, font);
        xindox.draw(text);
}

But, it works fine when I remove the const before the RenderTarget:
void DrawStringInBox(sf::RenderTarget &xindox, const std::string& String, const sf::Font& font) {
        sf::Text text(String, font);
        xindox.draw(text);
}

Why? Isn't draw() a const function? And if it isn't, why wouldn't it be?

2
Network / Cannot read from Packet.
« on: April 02, 2020, 07:06:09 pm »
Hi,

While reading the tutorial about packets, I tried to do my own project to test it. So, I made a peer-to-peer connection between two computers (it works! ^^), and I sent a packet from one to the other... The problem is when I try to read from the packet: the >> operator always returns false.
Here is the code:

On the sender's side:

#include <sfml/network.hpp>

sf::UdpSocket UdpS;

namespace Contact
{
         sf::IpAddress Ip;
        unsigned short Port;
};

int main() {
        UdpS.setBlocking(false);

        //Establishes P2P connection,
       //and finds the other contact's IP and port.
       //Also binds UdpS.
      //Returns true here.
        if (!Connect()) {
                std::cout << "Connection error." << std::endl;
                return 1;
        }
        std::cout << "Connected." << std::endl;

        sf::Uint16 u = 5;
        sf::Packet pack; pack << u;
        if (UdpS.send(pack, Contact::Ip, Contact::Port) != sf::Socket::Done) {
                std::cout << "Failure." << std::endl;
        }
        std::cout << "Sent" << std::endl; //Sent is printed, thus the packet is sent correctly.
}



And on the recipient's side:

#include <sfml/network.hpp>

sf::UdpSocket UdpS;

namespace Contact
{
         sf::IpAddress Ip;
        unsigned short Port;
};

int main() {
        UdpS.setBlocking(false);
        //Establishes P2P connection,
       //and finds the other contact's IP and port.
       //Also binds UdpS.
      //Returns true here.
        if (!Connect()) {
                std::cout << "Connection error." << std::endl;
                return 1;
        }
        std::cout << "Connected.   " << std::endl;

        UdpS.setBlocking(true);
        sf::Packet pack;
        if (UdpS.receive(pack, Contact::Ip, Contact::Port) != sf::Socket::Done) { return 1; }
       
        sf::Uint16 i;
        if (!(pack >> i)) { std::cout << "Reading failed." << std::endl; return 1; } //Reading failed is printed.
       
}

3
 Hi,

I was trying to compile a static version of SFML with CMake for Visual Studio 2019, I think I followed the tutorial (https://www.sfml-dev.org/tutorials/2.5/compile-with-cmake.php) correctly. The problem is that once I open the CMake generated solution to finally build SFML, I see that I cannot switch the solution configuration to x86, thus preventing me to build SFML in 32-bits.

Here are all the steps I did to compile SFML with CMake:

Firstly, I downloaded the SFML source code,
then, I opened CMake, chose the SFML file as source code and a build folder to put built files into.
Then, I clicked on configure, chose Visual studio 16 2019 as generator, and clicked on finish.
Once the configuring done, I unchecked BUILD_SHARED_LIBS, checked SFML_USE_STATIC_STD_LIBS, clicked on configure, then generate. Once everything is done, I clicked on the Open_Project button which opens the generated Visual Studio solution.

And there is the issue: I cannot switch the project's configuration to something else than x64...

What did I do wrong?

Pages: [1]
anything