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 - Grundkurs

Pages: [1]
1
I have a hard time compiling SFML on my machine.
In the past i have done the following procedure like a 1000 times without having any issues, but now i receive the following error:
Quote
CMake Error at CMakeLists.txt:5 (find_package):
  Could not find a configuration file for package "SFML" that is compatible
  with requested version "2.5".

  The following configuration files were considered but not accepted:

    C:/Program Files (x86)/SFML/lib/cmake/SFML/SFMLConfig.cmake, version: 3.0.0



-- Configuring incomplete, errors occurred!
See also "C:/src/test/build/CMakeFiles/CMakeOutput.log".

I compiled SFML on different Windows Versions (10 and 11) and used different versions of mingw-w64 (from https://winlibs.com/), but i always get this error. I never had this issue before. The steps i did:
  • Get SFML from Github
  • Create Makefiles with CMake, using MinGW Makefiles as generator
  • run "mingw32-make install" in the CMake-Build-Folder that i need to select in CMake-GUI
I use this basic CMakeLists.txt-file to build the project:
Quote
cmake_minimum_required(VERSION 3.1)

project(SFMLTest)

## If you want to link SFML statically
# set(SFML_STATIC_LIBRARIES TRUE)

## In most cases better set in the CMake cache
# set(SFML_DIR "<sfml root prefix>/lib/cmake/SFML")

find_package(SFML 2.5 COMPONENTS graphics audio REQUIRED)
add_executable(SFMLTest main.cpp)
target_link_libraries(SFMLTest sfml-graphics sfml-audio)

Here a similar error-message has been discussed: https://github.com/SFML/SFML/issues/1593
OP stated at one point "You were right. I used the wrong compiler in this project. Thank you!", however i don't think this is the reason in my case why find_package() does not work anymore.

EDIT: When i did the exact same steps described above with the SFML-Source from here:
https://www.sfml-dev.org/files/SFML-2.5.1-sources.zip
the described error does not occure.

I also double-checked this. The error can be reproduced if i use the Github Source-Code. When i use the source from https://www.sfml-dev.org/files/SFML-2.5.1-sources.zip everything is ok. 

2
General / Can't compile SFML on Windows 11
« on: October 17, 2021, 07:38:24 pm »
[EDIT]
I could pinpoint the issue: https://winlibs.com/ offers two versions of the mingw-w64 compiler: One ships with UCRT runtime, the other with MSVCRT runtime. With MSVCRT runtime i had no compilation issues. Visual Studio Compiler also had no issues compiling SFML on Windows 11. So i guess its something with the UCRT runtime.
[/EDIT]


I tried to compile SFML on Windows 11 and it fails with the following error-message:

[ 79%] Building CXX object src/SFML/Graphics/CMakeFiles/sfml-graphics.dir/RenderTextureImpl.cpp.obj
[ 79%] Building CXX object src/SFML/Graphics/CMakeFiles/sfml-graphics.dir/RenderTextureImplFBO.cpp.obj
[ 80%] Building CXX object src/SFML/Graphics/CMakeFiles/sfml-graphics.dir/RenderTextureImplDefault.cpp.obj
[ 81%] Building RC object src/SFML/Graphics/CMakeFiles/sfml-graphics.dir/sfml-graphics.rc.obj
[ 82%] Linking CXX shared library ..\..\..\lib\sfml-graphics-2.dll
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Keen/Downloads/SFML-master/extlibs/libs-mingw/x64/libfreetype.a(sfnt.c.obj):sfnt.c:(.text+0x5614): undefined reference to `_setjmp'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Keen/Downloads/SFML-master/extlibs/libs-mingw/x64/libfreetype.a(smooth.c.obj):smooth.c:(.text+0x77a): undefined reference to `_setjmp'

collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [src\SFML\Graphics\CMakeFiles\sfml-graphics.dir\build.make:602: lib/sfml-graphics-2.dll] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:307: src/SFML/Graphics/CMakeFiles/sfml-graphics.dir/all] Error 2
mingw32-make: *** [makefile:155: all] Error 2


I did not have this issue on Windows 10 using the same procedure described below:

  • 1. I use mingw-w64 compiler from https://winlibs.com/ (GCC 11.2.0 + LLVM/Clang/LLD/LLDB 13.0.0 + MinGW-w64 9.0.0 - UCRT-Runtime)
  • 2. Download SFML from https://github.com/SFML/SFML
  • 3. generate CMake-Files for MinGW.
  • 4. in Build-Folder: "mingw32-make install"

It compiles until 82 % and than cannot find '_setjmp'.
Compilation of SFML always worked for me in the past, this is the first time that it cannot get through to 100 %. Maybe it has something to do with Win 11?

3
Network / Sending sf::Packet via asio fails partly
« on: September 09, 2021, 09:16:27 pm »
I programmed a pong multiplayer game using SFML, where i used sf::UdpSockets for transferring data between two PCs. It worked great. Next i wanted to check out how the result would look like if i used the asio network library for networking instead of the SFML Network-classes.

Here my first big issue was, that asio does not provide a class similar to sf::Packet that helps with serializing the data.
With SFML its so beautifully simple, for example if you want to store an enum and some data that belongs to the enum, you could just do:
enum class CommandsToServer{
        Connect, // empty
        Disconnect, // empty
        Data // Vector2f
};
...

sf::Packet packet;
packet << static_cast<uint8_t>(CommandsToServer::Data);
packet << x << y;

and send the packet to the server, where you unpack the content the same way you put it in.
uint8_t command;
uint8_t x, y;
// ... receive packet from socket ...
receivedPacket >> command >> x >> y;
CommandToServer commandToServer = static_cast<CommandToServer>(command);
 

Since i did not find a straightforward way to pack different types into an array, i just used sf::Packet again with the asio::ip::udp::socket.

This approach looks like this:
    m_packet << static_cast<uint8_t>(5);
    m_packet << static_cast<uint8_t>(6);
    m_socket.send_to(asio::buffer(m_packet.getData(), m_packet.getDataSize()), m_serverEndpoint);


So i just try to transfer two values over the network: 5 and 6.

On the server-side i use

std::array<char, 256> m_receiveBuffer;
...
// in some function
    m_socket.async_receive_from(
            asio::buffer(m_receiveBuffer), m_remoteEndpoint,
            std::bind(&Server::handle_receive, this,
                      std::placeholders::_1,
                      std::placeholders::_2));
 ...

void Server::handle_receive(const asio::error_code &error, std::size_t l_receivedBytes) {
    sf::Packet packet;
    std::cout << "received bytes: " << int(l_receivedBytes) << "\n"; // Output: received bytes 2
    packet.append(m_receiveBuffer.data(), l_receivedBytes);
    int num1; int num2;
    packet >> num1 >> num2;
    std::cout << num1 << ", " << num2 << ".\n"; // Output: 0, 0
    receiveData();
 
Console prints 0, 0. But if i start the debugger and set a breakpoint at the last std::cout-statement, i can see that
packet has the following members:
m_data
[ 0 ] = {char}5 '\005'
[ 1 ] = {char}6 '\006’
m_readPos = 0
m_sendPos = 0
m_isValid = false

Its strange because the values 5 and 6 have apparently been transferred successfully, since they are stored in the std::vector<char> container of sf::Packet. However, they don't get transferred via the >> operator into the variables num1 and num2. I don't know the reason why i cannot transfer the data out of the sf::Packet into the variables on the server-side.

4
General / SFML 2.5 CMake configuration
« on: February 19, 2020, 07:52:53 pm »
I have an issue with the new CMake Build Tool. It basically works, but there is a catch.
My CMakeLists.txt file of my SFML-Program looks as follows:
cmake_minimum_required(VERSION 3.10)
project(observer4)

set(CMAKE_CXX_STANDARD 17)
set(SFML_DIR "C:/SFML")
find_package(SFML COMPONENTS graphics window system)
add_executable(observer4 main.cpp )
target_link_libraries(observer4 sfml-graphics sfml-audio)
 
When run CMake everything works smoothly.
-- Found SFML 2.5.1 in C:/SFML
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Nextcloud/C++/observer4/cmake-build-debug


1. When I compile SFML Source-Code (v.2.5.1.) with CMAKE_BUILD_TYPE set to Debug and put everything to C:/SFML, and copy all newly created dll-files...
sfml-graphics-d-2.dll
sfml-audio-d-2.dll
sfml-network-d-2.dll
sfml-system-d-2.dll
sfml-window-d-2.dll
...to the cmake-build-debug-folder of my SFML-Program where the binary that is compiled in debug-mode will get created, everything works fine; the SFML-Application starts without hassle.

But when i now repeat compiling SFML with CMAKE_BUILD_TYPE set to Release, which adds the corresponding compiled "release-SFML-Files" to C:/SFML, the compilation of the SFML-Program in debug-mode suddenly breaks.
The compilation in debug-mode fails with:
Process finished with exit code -1073741515 (0xC0000135)

In the folder C:/SFML/libs this files resides:
libsfml-audio-d.a
libsfml-graphics-d.a
libsfml-main-d.a
libsfml-network-d.a
libsfml-system-d.a
libsfml-window-d.a
[all release and debug DLL-Files]
libsfml-audio.a
libsfml-graphics.a
libsfml-main.a
libsfml-network.a
libsfml-system.a
libsfml-window.a

I did not touch the debug-dll-files in the cmake-build-debug-folder of my SFML-Program where the binary is being compiled.

When i delete
libsfml-audio.a
libsfml-graphics.a
libsfml-main.a
libsfml-network.a
libsfml-system.a
libsfml-window.a
in C:/SFML/libs, which should be no problem, because i compile the SFML-Application in debug mode, the compiler throws this error:

mingw32-make.exe[2]: *** No rule to make target 'C:/SFML/lib/libsfml-graphics.a', needed by 'observer4.exe'.  Stop.
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:75: CMakeFiles/observer4.dir/all] Error 2
mingw32-make.exe: *** [Makefile:83: all] Error 2

Why does the compiler need C:/SFML/lib/libsfml-graphics.a' ? Im compiling in debug-mode...he should rely on C:/SFML/lib/libsfml-graphics-d.a'. Same goes for the other files. when i return libsfml-graphics.a from trash, he asks for libsfml-window.a, when i return the file, he asks for libsfml-system.a etc. until it finally throws
Process finished with exit code -1073741515 (0xC0000135)
when all release-files (libsfml-audio.a, libsfml-graphics.a, etc. are back.

The weirdest thing is:
Process finished with exit code -1073741515 (0xC0000135)
goes away and the SFMl-Program starts when i copy the release-dll-files (sfml-graphics-2.dll, sfml-window-2.dll etc.) to the cmake-build-debug-folder. In fact, i can even delete all the debug-dll-files.
The Application only needs the release-files though i compiled it in debug-mode.

This is default behaviour out of the box which does not occure when i use a FindSFML.cmake file. When using FindSFML.cmake i can have all SFML-files (debug & release) in C:/SFML/libs in one place and just use the debug-dll-files for the debug build and the release-dll-files for my release-build.

5
General / Odd stripes on different monitors
« on: February 03, 2020, 08:16:32 am »
Hey there,
I uploaded a picture where you can see the same program running on two different machines. The violett/blue background with the subtle sloping lines is intended and tile-based. The monitor in the background works perfectly fine, however it produces this strange stripes when running my sfml-based game. I don't know where to start for looking into a possible solution of the problem. Is this monitor-related, SFML-related or OpenGL-related?

6
SFML projects / Klonski Pilot - 2D Space Shooter
« on: February 16, 2017, 01:39:16 pm »
Hello there,
here is a game im working on for quite some time now:

The game already includes different levels with different enemy types and a shop after every level, where you can spend money to upgrade new lasers and missles. It also has joystick-input implemented, so you can play it with keyboard or xbox-pad 360 without having to switch the input method in the menu settings.
The Codebase discussed in the book "SFML-Game-Development-Book" (https://www.amazon.de/SFML-Game-Development-Jan-Haller/dp/1849696845) was a great resource and help for building it.
Let me know what you think so far.

7
SFML website / How to embed Youtube Videos in Forum Posts?
« on: February 16, 2017, 01:24:18 pm »
Hello There!
I cant figure out how to embed a youtube-video into a forum post.
For example:
i tried [YT]QiSgmamUSVw[/YT]
or [youtube: QiSgmamUSVw]
or [youtube]https://www.youtube.com/watch?v=QiSgmamUSVw[/youtube]
or [youtube]QiSgmamUSVw[/youtube]

but non of it works in the preview. However i saw multiple forum posts with embeded youtube videos. What did i miss?
Greetings

8
Window / Fullscreen randomly behaves like titlebar is still there
« on: December 01, 2015, 10:47:26 pm »
Hey guys,
When i open a sf::RenderWindow in Fullscreen-Mode, sometimes it displays the textured Sprite that has the same size as the window normally in full screen so the image covers the whole screen as its supposed to do. But sometimes, the image stays exactly at the same position as if there's still a titlebar in the window. I made an gif-animation so you can see it.
http://gifmaker.cc/PlayGIFAnimation.php?folder=2015120103PgDVv8II9BE8O6oKLsg2bf&file=output_QMBNol.gif
here are also some screenshots.

sf::Style::Default

sf::Style::Fullscreen with broken behaviour

sf::Style::Fullscreen with normal behaviour

Its coincidental if the fullscreen-mode starts normally or broken.
I compiled SFML 2.3.2 with gcc-5.2.1 and CMake using both CMAKE_BUILD_TYPE Debug and Release and put all *.so libs into /usr/lib/x86_64-linux-gnu. Im running Linux Mint 17.2 Cinnamon.
I don't know anymore what to do about this. At this state the Fullscreen-Mode is unusable :-(

9
Graphics / Transparency of glowing Point (Fragment-Shader)
« on: November 18, 2015, 01:57:17 pm »
Hey Folks,
currently im working on getting laser-shots in my game to glow.
My approach is to pass a vec2 containing the position of the laser to a fragment-shader.
At that position i create a glowing Point, so on the screen it looks like there's a glowing laser-shot at the particular position.
This looks ok for now and works fine: The point gets drawn at the correct positions and moves as expected.


The fragment-shader for this is:

uniform vec2 resolution;
uniform vec2 laserPos;

float R = 0.97;
float G = 0.77;
float B = 0.40;

void main() {

    vec2 q = gl_FragCoord.xy / resolution.xy;
    vec2 laserPos = laserPos / resolution;

    // "-1" transfers mouse.y to SFML-coordinate-system aligned position
    vec2 r = vec2(q.x - laserPos.x , q.y + laserPos.y - 1.);

    //size of radius    
        float col = 0.002 / length(r);


    gl_FragColor = vec4(col * R, col * G, col * B, 1.);

}

However my problem is, that if i create a sf::RectangleShape with the size of the window to draw the fragmentShader to, its drawn all black except the glowing point itsself.
So if i have a background-image that is drawn just before the rectangleShape, you can't see it because the rectangleShape paints the whole screen black except the glowing point.
How could i just draw the glowing point without all the blackness around it?
is my fragment-Shader flawed because it paints everything black or do i use the wrong "tool" on SFML-side to get the yellow-painted Glow drawn without anything else?
Unfortunately i ran out of ideas on this and hope someone may has some hint for me.

10
Feature requests / new sf::Sprite Method "void centerOrigin()"
« on: February 02, 2015, 01:41:05 pm »
Hey there,
i have a small feature request. Often i need to set the Origin of the Sprite to its center,
like
sprite.setOrigin(sprite.getLocalBounds().width / 2.f,
                (sprite.getLocalBounds().height / 2.f);

or as a function
void centerOrigin(sf::Sprite& sprite){
    sf::FloatRect bounds{sprite.getLocalBounds()};
    sprite.setOrigin(bounds.width /2.f, bounds.height /2.f);
}

it would be nice if the sf::Sprite class would provide a Method that sets the Origin to Center automatically, like:
sprite.centerOrigin();

11
Hey there,
i have some trouble understanding a certain template function used in the Codebase of the SFML Book. Its basically a straight c++ related question, however because its from the Codebase of the SFML Book i guess there is a high chance that here might be someone who have already seen this snipped of code and it may be appropriate to ask here about it:
1. template <typename GameObject, typename Function>
2. std::function<void(SceneNode&, sf::Time)> derivedAction(Function fn)
3. {
4.      return [=] (SceneNode& node, sf::Time dt)
5.      {
6.              // Check if cast is safe
7.              assert(dynamic_cast<GameObject*>(&node) != nullptr);
8.
9.              // Downcast node and invoke function on it
10.             fn(static_cast<GameObject&>(node), dt);
11. };
12.}

I was wondering why the return-Statement can use the "fn" Function-Object (line 10) passed by the Parameter of the template function (line 2) because when the lambda (line 4) is assigned to a std::function<...> object, that object itself would not be able to use the passed Function Object (line 2), because its not part of the lambda.

Because i had trouble understanding that, i tried to implement a more simple code example to see how this works.
//functor
class add2{
int number;
public:
        add2(int num) : number{num}{}
void operator()(int i){
        std::cout << i + number << "\n";
        }
};

template<typename Function>
std::function<void(int)> getFunction(Function fn){
        return [=] (int number)
        {
        fn(number);
        };
}

template<typename Function>
std::function<void(int)> getFunction(){
        return [=] (int number)
        {
        Function fn{2};
        fn(number);
        };
}

int main(){
//std::function<void(int)> function = getFunction<add2>(add2{2}); //error
//std::function<void(int)> function = getFunction<add2>(); //works

std::vector<int> numbers ={5,6,7,8};
for_each(numbers.begin(), numbers.end(), function);

return 0;
}
 

The first template function breaks with the message "error: passing 'const add2' as 'this' argument of 'void add::operator()(int)' discards qualifiers [-fpermissive]". The second one works fine as expected. My guess why at least the second function works is, because i create the Functor-Object within the return statement of the lambda the method that gets assigned to that lambda can access the Functor-Object because its part of the lambda. It just makes no sense to me that the code from the book works but my first template function does not :-(

12
General / Processing User Input
« on: September 11, 2014, 05:41:27 pm »
Hello there,
i'm writing a small application for displaying sprite-animations. I wrote the application once some months ago where i fetched the user input via the console and after gathering all important information it opened the sfml-window, loaded automatically the sprite sheet and displayed the animation at variable speed. Everything worked well but it was kind of ugly that the application was divided into two parts: The Console-Part and the SFML-Part. So i started to rewrite the Application where i fetched the user-input not in Console-Window mode but in sfml itsself. This looks now this way:
https://www.youtube.com/watch?v=jvdD38c_k94&feature=youtu.be

However the code i wrote to accomplish this is very tedious and kind of feels wrong so i was hoping someone might point me in to the right direction how to implement it better.
basically i concatenate all typed sf::keys from the user to a std::string variable and when the player presses Return it gets assigned to a "complete-String" variable which i use for processing the input.

Because there is several data that has to be collected via input (like
1.Question "a) load new sprite sheet, b) load last opened sprite sheet"
if User press a) ...
2.Question: Type Name of Sprite Sheet
if User inputs "Name.png" check if Name.png exists in folder etc.
3.Question....

So if player presses "a" the second question gets displayed, if the user answers second question appropriately the 3rd question gets displayed and so on...
i tried to solve this with a linked List of Option-Elements. They all inherit from
base class Option
class Option
{
public:
        Option();
        virtual ~Option();

        virtual std::string getStr() = 0;
        virtual Option* processInput(const std::string& input) = 0;
        Option* error;
        Option* next;
        Option* last;
};

So the implementation of the first questions looks like this:
#include "RootOption.h" //RootOption inherits from class Option
RootOption::RootOption()
{
}
RootOption::~RootOption()
{
}
std::string RootOption::getStr()
        {
        return std::string{ "a) load new sprite sheet\nb) load last opened sprite sheet" };
        }

Option* RootOption::processInput(const std::string& input)
        {
        if (input == "a" && next != nullptr) return next;
        return this;
        }
 

the parameter of processInput() is the complete String of the user-input that got passed to this method.
So if player presses "a", the next question gets displayed.
The call-side looks like this:
void Inputter::getUserInput() //method gets only invoked when player presses Return
        {
        currentOption = currentOption->processInput(mCompleteStr); //compute input in Option-Class
                                                                                                //and return appropriate next Option-Class
        println(mDisplayText, currentOption->getStr()); //print message of new Option
        }
 

This approach leads to a ton of different "Option classes" that inherits from Base Option Class and with it comes a lot of text and files and its not very flexible and horrible to code with. Unfortunately i dont have any idea how to make the traversing through the different questions and collecting information from the user more straight forward. Maybe someone has a good idea how to approach this kind of logic?

Pages: [1]
anything