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

Author Topic: Custom SFML Wizard for QtCreator  (Read 5194 times)

0 Members and 1 Guest are viewing this topic.

docwild

  • Newbie
  • *
  • Posts: 10
    • View Profile
Custom SFML Wizard for QtCreator
« on: July 31, 2014, 04:29:21 pm »
Something I find useful is adding a SFML custom wizard to qtcreator, it takes the drudgery out of setting up  a new project so I thought I may as well share it.

First you need to locate your qtcreator config folder, which on linux (for me) is at $HOME/.config/QtProject/qtcreator/templates

It will vary depending on distro/OS so check this out:
http://qt-project.org/doc/qtcreator-3.1/creator-project-wizards.html
You may have to create the templates folder, and inside that the wizards folder and then inside that a folder called SFML. So the path now becomes: $HOME/.config/QtProject/qtcreator/templates/wizards/SFML

I'm using CMake so you will need to create a generic CMakeLists.txt inside your newly created SFML folder. Mine looks like this but you should adjust it to your system:

project(%ProjectName%)
cmake_minimum_required(VERSION 2.8)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -Wall -O0")
set(CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules/"  "/usr/share/SFML/cmake/Modules/")


set(SOURCE
   ${SOURCE}
   ${CMAKE_CURRENT_SOURCE_DIR}/main.%CppSourceSuffix%


)
set(HEADERS
   ${HEADERS}


)

find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
  include_directories(${SFML_INCLUDE_DIR})
endif()


add_executable(${PROJECT_NAME} ${SOURCE})
target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES})

The %ProjectName% variable will be replaced with the name of the project you give in the new project wizard. The variable %CppSourceSuffix% will be replaced with whatever you have qtcreator set to use as C++ file name suffixes. So if you use something other than cpp you will want to change the filename of main.cpp you will create next and adjust the "file source" attribute in the XML file you will create later, or you can get rid of the %CppSourceSuffix% and just hard code the name.

Now you will need a main.cpp file (adjust it to your needs):

#include <SFML/Graphics.hpp>


int main()
{
    const int SWIDTH = 1024;
    const int SHEIGHT = 768;
    sf::RenderWindow win(sf::VideoMode(SWIDTH,SHEIGHT),"%ProjectName:c%",sf::Style::Close);
    while(win.isOpen())
    {
        sf::Event e;
        while (win.pollEvent(e))
        {
            if(e.type == sf::Event::Closed)
            {

                win.close();
            }            
        }
        win.clear();
        //drawing
        win.display();
    }
    return 0;
}

 

Again it has the %ProjectName:c% variable with a ':c', which means it will use your project name with the first letter capitalised as your window title.

Now create a file called wizard.xml
<wizard version="1" kind="project" firstpage="10" id="S.Plain C++ (SFML/CMake)" category="I.Projects"
       platformIndependent="true" featuresRequired="CMake.CMakeSupport">
    <icon>sfml.png</icon>
    <description>Creates a SFML C++ project using CMake.</description>
    <displayname>Plain SFML C++ Project (CMake Build)</displayname>;
    <displaycategory>Non-Qt Project</displaycategory>
    <files>
        <file source="main.cpp" target="main.%CppSourceSuffix%" openeditor="true"/>
        <file source="CMakeLists.txt" openproject="true"/>
    </files>
</wizard>

This xml file describes the generic wizard, where to place it in the "Create New" dialog and the picture to use. I knocked up a quick 32x32 sfml logo in GIMP which I've attached (hope you don't mind Laurent), this also goes in the SFML folder.

That's it. Restart QtCreator, go to New Project/Non-Qt Project and "Plain SFML Project" should be under the usual CMake options. Hope it's useful.
« Last Edit: July 31, 2014, 05:26:10 pm by docwild »

Strelok

  • Full Member
  • ***
  • Posts: 139
    • View Profile
    • GitHub
Re: Custom SFML Wizard for QtCreator
« Reply #1 on: July 31, 2014, 04:52:23 pm »
How about changing
project(%ProjectName%)
to
project(%ProjectName% CXX)

and

set(CMAKE_MODULE_PATH "/usr/share/cmake-3.0/Modules/" "/usr/share/SFML/cmake/Modules/")
to
set(CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules/" "/usr/share/SFML/cmake/Modules/")

docwild

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Custom SFML Wizard for QtCreator
« Reply #2 on: July 31, 2014, 05:26:48 pm »
That works too. You learn soemthing new every day, I've updated the original post.

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Re: Custom SFML Wizard for QtCreator
« Reply #3 on: July 31, 2014, 06:49:31 pm »
Nice, thanks !

maidis

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • SFML Geliştirme
Re: Custom SFML Wizard for QtCreator
« Reply #4 on: September 10, 2018, 09:52:38 am »
This page has been in my bookmarks for a very long time. I created qtcreator-template-sfml project using the information in this page and the Adding New Custom Wizards document.

With this template, a simple SFML example can be created that uses one of the CMake, QMake, Qbs build systems. I just tested it on Fedora. For now, it's likely that it will not work on other Linux distributions, other operating systems, and other processor architectures without some changes being made.

So any contribution to the project is welcomed :)

Similar projects:

SFMLGameTemplate
sfml-project
base-sfml

 

anything