derekdreery
derekdreery

Reputation: 3922

Including GLSL files in project pane in a QTCreator CMake project

I am working through the OpenGL tutorial here: OpenGL-Tutorial.org, and want to use QTCreator and CMake to build the examples.

Opening the root CMakeLists.txt file opens the project, which then builds/runs correctly (after following instructions on the website), but the fragment and vertex files do not show up in the projects pane. I have tried renaming them to .frag, .vert and .glsl with no effect. If I drag these files from a folder they open in the edit pane with correct syntax highlighting.

How do I get these files to show up in the projects pane?


I am on Ubuntu 20.04 and have tried QTCreator from packages and the newest source on sourceforge.

Upvotes: 2

Views: 3816

Answers (3)

vicrion
vicrion

Reputation: 1733

Another way to include shader files in your Qt project using Cmake is through the CMake command qt5_add_resources. One of the Qt's examples does the same when using qmake. For my application I found it to be more practical to include the shader files as resources.

So, for this, you would have to prepare a resource file, for example, Shaders.qrc, and add there all the shader files you want to use, e.g.:

<RCC>
    <qresource prefix="/">
        <file>Stroke.frag</file>
        <file>Stroke.geom</file>
        <file>Stroke.vert</file>
    </qresource>
</RCC>

Then in the CMakeLists.txt, add the resource file:

qt5_add_resources(SHADER_RSC_ADDED 
    Shaders/Shaders.qrc
)

And add it to the executable (or library):

add_executable(${PROJECT_NAME}
    ${PROJECT_SRCS}
    ${SHADER_RSC_ADDED}
)

After re-build, the project tree will look like below:

Added shaders as qrc file

Upvotes: 2

Jarod
Jarod

Reputation: 1712

file(GLOB RES_FILES *.frag *.vert *.glsl)

add_executable(exe_name ${RES_FILES} ${C/CPP FILES})

Upvotes: 4

Mortennobel
Mortennobel

Reputation: 3481

You can add the shader files as other files in the .pro file.

OTHER_FILES += \
    simple.frag \
    simple.vert

Also you should consider using the QT resource management for your shader files. I have recently created a simple OpenGL 3.2 example project in Qt, which also shows how to use the Qt for resource management of shader files. The project is available here: https://github.com/mortennobel/QtOpenGL3.2Core

Warning: the project is only tested on Windows and OS/X.

Upvotes: 0

Related Questions