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

Pages: [1] 2
1
Great that you figured it out! I think this explanation would be much better published on the community wiki alongside similar topics.

For the website we'd need a French translation, a proper formatting, more in-depth point plus screenshots and the guarantee that you're going to maintain it as long as possible (at least multiple years). If you can bring all this to the table, then feel free to provide a pull request on our website repository. :)

You will be pleased to know that the Windows section of Compile And Link SFML With Qt Creator now has my findings on there.

2
General / Re: Issues getting SFML to work with the QT IDE
« on: February 18, 2018, 09:16:17 pm »
The point is more that it's no needed, but it will work regardless. GCC will automatically add the lib prefix and .a suffix, so -lsfml-audio-s-d is equivalent to -llibsfml-audio-s-d.a

Oh, that's pretty awesome. I guessed that the .a would be added but I didn't realise that the lib was also added.

3
General / [Request] [IDE Configuration] QT Config to go onto the Main Site
« on: February 18, 2018, 09:14:22 pm »
After spending a day working through and trying (and eventually succeeding) to get QT to work with SFML, I wouldn't wish the frustration I have had today upon anyone. Hence, I wish to provide the configuration steps for QT so that it can be put onto a page on the main SFML website alongside the configuration for MinGW and MSVC.

Here goes



  • Download the Source for the SFML version you intend to use and extract it to a folder
    • Open QT Creator
    • Go to: Tools->Options->Build & Run->CMake and make sure that CMake has been either Autodetected or manually set
  • Go to the Welcome tab and click the "Open Project..." button
  • Look for the CMakelists.txt file in the SFML source folder
  • Click on the Projects icon on the left hand side of the IDE. Choose Build Settings from the Build And Run menu. Scroll down to and expand the Build Environment roll-out in order to look for the PATH variable. Make sure that the following exists in the Path variable: C:\QtSDK\mingw\bin;C:\qtsdk\qt\bin;
  • Set the CMake parameters that you need (for me, BUILD_SHARED_LIBS=False and SFML_USE_STATIC_STD_LIBS=True) and click Apply Configuration Changes (Make sure to set the Build Directory to something like "<SFML_Source_Root>..\SFML-Build\<Build_Configuration>" to make the Project Configuration later easier)
  • Click the Hammer in the bottom-left corner to build the current Build Configuration (Do this for both Debug and Release)
  • Go to File->New File Or Project->Non-Qt Project->Plain C++ Application->Choose
  • Click Choose. Name your project. The rest of the Project Setup can be left as the default
  • Open the Project's .pro file and replace the contents with the following (Variables have been used so you only need to replace 2 paths with your paths)
    (click to show/hide)

Replace the contents of main.cpp with the following

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}
 

And compile.

4
General / Re: Issues getting SFML to work with the QT IDE
« on: February 18, 2018, 08:13:08 pm »
Quote
-llibsfml-audio-s
Should be -lsfml-audio-s (same for all other libs).

My generated libs had the "lib" prefix i.e. instead of sfml-system-s-d.a being generated, libsfml-system-s-d.a was generated. It is most likely just a quirk of the QT IDE because the test program (in the spoiler for convenience) ran perfectly fine
(click to show/hide)

5
General / Re: Issues getting SFML to work with the QT IDE
« on: February 18, 2018, 04:55:49 pm »
Then I don't know why the test code (the one at the end of the configuration tutorials on the SFML website) won't compile...

EDIT

I have figured it out... it was the order of stuff that was the issue. I had the libs that depended on other libs after those libs.

For people who stumble upon this thread looking for the solution, I got you fam  ;D

Here is what you add to your <Project_Name>.pro file
//Library Directories Configuration
LIBS += -L<Debug_Binaries_Base_Dir>\lib -L<Release_Binaries_Base_Dir>\lib -L<SFML_Source_Base_Dir>\extlibs\libs-mingw\x86

//Release Library Configuration
CONFIG(release, debug|release): LIBS += -llibsfml-audio-s -llibopenal32 -llibFLAC -llibvorbisenc -llibvorbisfile -llibvorbis -llibogg -llibsfml-graphics-s -llibfreetype -llibjpeg -llibsfml-network-s -lws2_32 -llibsfml-window-s -lopengl32 -lgdi32 -llibsfml-system-s -lwinmm

//Debug Library Configuration
CONFIG(debug, debug|release): LIBS += -llibsfml-audio-s-d -llibopenal32 -llibFLAC -llibvorbisenc -llibvorbisfile -llibvorbis -llibogg -llibsfml-graphics-s-d -llibfreetype -llibjpeg -llibsfml-network-s-d -lws2_32 -llibsfml-window-s-d -lopengl32 -lgdi32 -llibsfml-system-s-d -lwinmm

INCLUDEPATH += <SFML_Source_Base_Dir>\include
DEPENDPATH += <SFML_Source_Base_Dir>\include

//SFML_STATIC preprocessor definition
DEFINES += SFML_STATIC

 

EDIT 2
This is the forum post that I found that solved my issue (for those of you that are curious)

EDIT 3
I had forgotten to add the libraries for the Audio and Network modules. I also have rearranged the libs dependency libs (the ones like Freetype and GDI32) so that they are before the SFML libs that don't need them.

6
General / Re: Issues getting SFML to work with the QT IDE
« on: February 18, 2018, 04:35:47 pm »
Quote
I've just looked into the errors
Which errors?

Quote
Things like "GLCheck.hpp" aren't in the include directory of SFML's Source
It's under "src", not "include".

A fresh Compilation log
(click to show/hide)

And here is a screenshot of one of the missing headers attached  too

7
General / Re: Issues getting SFML to work with the QT IDE
« on: February 18, 2018, 01:43:51 pm »
I've just looked into the errors and there are missing include files from the Source. Things like "GLCheck.hpp" aren't in the include directory of SFML's Source

8
General / Re: Issues getting SFML to work with the QT IDE
« on: February 18, 2018, 12:33:54 pm »
Ah... my bad... I used this tutorial in order to get stuff going with QT. It is designed for Dynamic Linking and so I adapted it for Static Linking but forgot about that Compiler option... Thanks  :-[

9
General / Issues getting SFML to work with the QT IDE
« on: February 18, 2018, 12:22:07 pm »
Hi all, I built SFML 2.4.2 as Static Linking and this is the build output for SFML (I added in the contents of <SFML Source Dir>\extlibs\libs-mingw\x86 to <Build Output>\lib just incase it was an issue with missing dependencies but still got the same errors).

Here is the .pro file contents for the QT project I created to test that SFML was properly set up (but ultimately failed)

And here is the Compiler Output

Now for Screenshots of my SFML Source CMake Config

Debug


Release

10
I have found the issue... it was a problem with the font itself  ::)
The font must have omitted the numbers or something because it worked just fine with a different font

11
I seriously have no idea what is going wrong here

12
This is a really weird issue I am having and have been stuck on for most of today.

What should be rendering is "0 | 0" but the pipe is the only part of the string that is being rendered.



Here is the code:

/*
*       Game.h
*       Written by James Yeoman
*/

#pragma once

#include "Paddle.h"
#include "Ball.h"

#include <SFML/Graphics.hpp>

class Game
{
private:
        sf::RenderWindow window;
        uint16_t WindowWidth;
        uint16_t WindowHeight;

        uint8_t score1;
        uint8_t score2;

        bool isRoundOver;
       
        void createEntities();

        Ball* puck;

        Paddle* paddles[2];

        sf::Font scoreFont;

        sf::Text* scoreSmall;
        sf::Text* scoreBig;

public:
        Game(uint16_t, uint16_t, std::string);
        void startLoop();
};

/*
*       Game.cpp
*       Written by James Yeoman
*/


#include "Game.h"
#include <string>

Game::Game(uint16_t windowWidth, uint16_t windowHeight, std::string title) :
        window(sf::VideoMode(windowWidth, windowHeight), title)
{
        this->WindowWidth = windowWidth;
        this->WindowHeight = windowHeight;

        this->window.setVerticalSyncEnabled(true);

        this->score1 = 0;
        this->score2 = 0;

        this->isRoundOver = false;

        this->scoreFont = sf::Font();
        if (!this->scoreFont.loadFromFile("fonts/scoreFont.ttf"))
        {
        }
       
        this->scoreSmall = new sf::Text("", this->scoreFont, 30U);
        this->scoreSmall->setString(std::to_string(score1) + " | " + std::to_string(score2));
        this->scoreSmall->setOrigin(this->scoreSmall->getLocalBounds().width / 2, this->scoreSmall->getLocalBounds().height / 2);
        this->scoreSmall->setPosition(this->WindowWidth / 2, this->scoreSmall->getGlobalBounds().height);
        this->scoreSmall->setFillColor(sf::Color::White);
        this->scoreSmall->setOutlineColor(sf::Color::White);
        this->scoreSmall->setOutlineThickness(1.0f);

        std::printf(scoreSmall->getString().toAnsiString().data());

        this->scoreBig = new sf::Text("0 | 0", this->scoreFont, 200U);
        this->scoreBig->setOrigin(this->scoreBig->getLocalBounds().width / 2, this->scoreBig->getLocalBounds().height / 2);
        this->scoreBig->setPosition(windowWidth / 2.0f, windowHeight / 2.0f);
        this->scoreBig->setFillColor(sf::Color::White);
}

void Game::createEntities()
{
        this->paddles[0] = new Paddle(sf::Vector2f(20, 100), 1, sf::Vector2f(this->window.getSize()));
        this->paddles[1] = new Paddle(sf::Vector2f(20, 100), 2, sf::Vector2f(this->window.getSize()));
        this->puck = new Ball(sf::Vector2f(20, 20), &(this->window), this->paddles);
}

void Game::startLoop()
{
        sf::Event event;
        while (window.isOpen())
        {
                // Initialises the paddles and the ball
                this->createEntities();

                // Round loop
                while (this->isRoundOver == false)
                {
                        while (this->window.pollEvent(event))
                        {
                                if (event.type == sf::Event::Closed)
                                        this->window.close();
                        }

                        this->window.clear();

                        this->paddles[0]->Update();
                        this->window.draw(this->paddles[0]->getBody());

                        this->paddles[1]->Update();
                        this->window.draw(this->paddles[1]->getBody());

                        this->isRoundOver = this->puck->Update();
                        this->window.draw(this->puck->getBody());

                        this->window.draw(*this->scoreSmall);

                        this->window.display();
                       
                }

                /* Checks who won the round */
                if (this->puck->getBody().getPosition().x > this->WindowWidth / 2)
                        this->score1 += 1;
                else
                        this->score2 += 1;

                this->scoreSmall->setString(std::to_string(this->score1) + " | " + std::to_string(this->score2));
                this->scoreBig->setString(this->scoreSmall->getString());

                /* Positions the score in the middle of the screen */
                this->scoreBig->setPosition(WindowWidth / 2.0f, WindowHeight / 2.0f);

                /* Display the score in the middle of the screen */
                while (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Space) == false)
                {
                        while (this->window.pollEvent(event))
                        {
                                if (event.type == sf::Event::Closed)
                                        this->window.close();
                        }

                        this->window.clear();

                        this->window.draw(this->paddles[0]->getBody());
                        this->window.draw(this->paddles[1]->getBody());

                        this->window.draw(*this->scoreSmall);
                        this->window.draw(*this->scoreBig);

                        this->window.display();
                }
                this->isRoundOver = false;
        }

}
 

13
this->window.create(...).

Just read the docs next time ;)

Since it's in the constructor, you can also use the initialization list.
Game::Game(...) : window(...)
{
   ...
}

Thanks Laurent. I actually didn't know about initialization lists. When I saw your reply, I went straight to google and looked them up  ;D

14
So I was happily coding away and then I realised that I had screwed up somewhere in a constructor (because the build failed)... ok... so I go to the constructor and this happened:


ok... this is ok... I can fix this... (or so I thought)

5 mins later



yeah...

Here is the code

/*
*       Game.cpp
*       Written by James Yeoman
*/


#include "Game.h"

Game::Game(uint16_t windowWidth, uint16_t windowHeight, std::string title)
{
        this->window = sf::RenderWindow(sf::VideoMode(windowWidth, windowHeight), title);
        this->window.setVerticalSyncEnabled(true);
        this->score = 0;
        this->isRoundOver = false;
}

void Game::createEntities()
{
        p1 = Paddle(sf::Vector2f(20, 100), 1);
}

void Game::startLoop()
{
        createEntities();

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }
               
                window.clear();
                p1.Update();
                window.draw(p1.getBody());
                window.display();
        }
}

/*
*       Game.h
*       Written by James Yeoman
*/

#pragma once

#include "Paddle.h"
#include "Ball.h"

#include <SFML/Graphics.hpp>

class Game
{
private:
        sf::RenderWindow window;
        uint16_t WindowWidth;
        uint16_t WindowHeight;

        uint8_t score;

        Paddle p1;
        Paddle p2;

        bool isRoundOver;
       
        void createEntities();

public:
        Game(uint16_t, uint16_t, std::string);
        void startLoop();
};

15
General / Re: Compile error LNK2038 when statically linking
« on: May 21, 2017, 07:24:37 pm »
The LNK error number is generally useful, but much more useful is always the full error as it clearly tells you what the issue is. Plus it's kind of annoying when you first have to ask MSDN what the error code means. ;)

You've set the /MT or /MTd flag for the runtime libs while SFML was built with /MD or /MDd.

Either change your project settings to /MD or /MDd, or build SFML from source and make sure to check SFML_STATIC_STD_LIBS.

Thanks for the reply. Looks like I will be building from source then.  :'(

The website should be updated to state that the precompiled binaries provided for download aren't capable of static linking. It could have saved me a lot of time but...  :-\

Pages: [1] 2