QOpenGL RCC Errors
-
wrote on 27 Dec 2022, 13:50 last edited by jacubus
Hello, i'm trying to link shaders and .png texture file but i'm getting RCC errors.
For shadersRCC Parse Error: 'C:/Users/Jacob/source/repos/SMGG_2_0/resources/fshader.glsl' Line: 1 Column: 1 [Start tag expected.]
For .png
RCC Parse Error: 'C:/Users/Jacob/source/repos/SMGG_2_0/resources/cube.png' Line: 1 Column: 1 [Encountered incorrectly encoded content.]
CMake
# Resources: set(shaders_resource_files "resources/fshader.glsl" "resources/vshader.glsl" ) qt6_add_resources(SMGG_2_0 "shaders" PREFIX "Shaders" FILES ${shaders_resource_files} ) set(textures_resource_files "resources/cube.png" ) qt6_add_resources(SMGG_2_0 "textures" PREFIX "Textures" FILES ${textures_resource_files} ) set(PROJECT_SOURCES ${shaders_resource_files} ${textures_resource_files} )
Shader files
#ifdef GL_ES // Set default precision to medium precision mediump int; precision mediump float; #endif uniform sampler2D texture; varying vec2 v_texcoord; //! [0] void main() { // Set fragment color from texture gl_FragColor = texture2D(texture, v_texcoord); } //! [0]
#ifdef GL_ES // Set default precision to medium precision mediump int; precision mediump float; #endif uniform mat4 mvp_matrix; attribute vec4 a_position; attribute vec2 a_texcoord; varying vec2 v_texcoord; //! [0] void main() { // Calculate vertex position in screen space gl_Position = mvp_matrix * a_position; // Pass texture coordinate to fragment shader // Value will be automatically interpolated to fragments inside polygon faces v_texcoord = a_texcoord; } //! [0]
-
@jacubus said in QOpenGL RCC Errors:
qt6_add_resources
When you use the target variant you have to create the target (in your case SMGG_2_0 ) before the qt6_add_resources() call.
-
@jacubus said in QOpenGL RCC Errors:
qt6_add_resources
When you use the target variant you have to create the target (in your case SMGG_2_0 ) before the qt6_add_resources() call.
wrote on 27 Dec 2022, 22:08 last edited by@Christian-Ehrlicher
When i moved it to be after .exe i'm getting that it can't be opened.QOpenGLShader: Unable to open file "vshader.glsl" QOpenGLShader: Unable to open file "fshader.glsl" QOpenGLShaderProgram::uniformLocation(mvp_matrix): shader program is not linked QOpenGLShaderProgram::uniformLocation(texture): shader program is not linked
Project tree looks like:
| widget.h | widget.cpp mainfolder -| resources -| | fshader.glsl | vshader.glsl | cube.png
-
@Christian-Ehrlicher
When i moved it to be after .exe i'm getting that it can't be opened.QOpenGLShader: Unable to open file "vshader.glsl" QOpenGLShader: Unable to open file "fshader.glsl" QOpenGLShaderProgram::uniformLocation(mvp_matrix): shader program is not linked QOpenGLShaderProgram::uniformLocation(texture): shader program is not linked
Project tree looks like:
| widget.h | widget.cpp mainfolder -| resources -| | fshader.glsl | vshader.glsl | cube.png
@jacubus said in QOpenGL RCC Errors:
I'm getting that it can't be opened.
but it compiles so it was correct.
Now you should show us how you're loading them in your code.
-
@jacubus said in QOpenGL RCC Errors:
I'm getting that it can't be opened.
but it compiles so it was correct.
Now you should show us how you're loading them in your code.
wrote on 28 Dec 2022, 14:48 last edited by// Compile vertex shader if (!program.addShaderFromSourceFile(QOpenGLShader::Vertex, ":/vshader.glsl")) close(); // Compile fragment shader if (!program.addShaderFromSourceFile(QOpenGLShader::Fragment, ":/fshader.glsl")) close();
-
// Compile vertex shader if (!program.addShaderFromSourceFile(QOpenGLShader::Vertex, ":/vshader.glsl")) close(); // Compile fragment shader if (!program.addShaderFromSourceFile(QOpenGLShader::Fragment, ":/fshader.glsl")) close();
@jacubus said in QOpenGL RCC Errors:
":/vshader.glsl"
qt6_add_resources(SMGG_2_0 "shaders"
PREFIX
"Shaders"
FILES
${shaders_resource_files}
)I mean - how do you expect that the filename is :/vshader.glsl when you add "Shaders" as prefix. Reading the documentation to find out what the arguments are doing seems to be really hard these days...
PREFIX specifies a path prefix under which all files of this resource are accessible from C++ code. This corresponds to the XML attribute prefix of the .qrc file format. If PREFIX is not given, the target property QT_RESOURCE_PREFIX is used.
1/6