0
$\begingroup$

I'm a newbie with OpenGl and I'm stuck in following the tutorial. I found this tutorial with these shaders

// Shader sources
const GLchar* vertexSource = R"glsl(
    #version 150 core
    in vec2 position;
    in vec3 color;
    in vec2 texcoord;
    out vec3 Color;
    out vec2 Texcoord;
    void main()
    {
        Color = color;
        Texcoord = texcoord;
        gl_Position = vec4(position, 0.0, 1.0);
    }
)glsl";
const GLchar* fragmentSource = R"glsl(
    #version 150 core
    in vec3 Color;
    in vec2 Texcoord;
    out vec4 outColor;
    uniform sampler2D tex0;
    void main()
    {
        outColor = texture(tex0, Texcoord) * vec4(Color, 1.0);
    }
)glsl";

I noticed that the proposed shaders couldn't compile in my computer, since my GLsl version is 1.30, but changing the version declaration into

#version 130 core

the ouput of this instruction is glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);

0:2(10): error: illegal text following version number

I wuould like to understand what is wrong in this shader (in version 1.30) or at least where to find enough information to "repair" this situation. Thanks

#UPDATE 1 I managed to have compiling shaders with no errors, but still the program does not work.

// Shader sources
//in --> attribute
//out --> varying
const GLchar* vertexSource = R"glsl(
    #version 130
    attribute vec2 position;
    attribute vec3 color;
    attribute vec2 texcoord;
    varying vec3 Color;
    varying vec2 Texcoord;
    void main()
    {
        Color = color;
        Texcoord = texcoord;
        gl_Position = vec4(position, 0.0, 1.0);
    }
)glsl";

//in --> varying
//out --> (delete)
const GLchar* fragmentSource = R"glsl(
    #version 130
    varying vec3 Color;
    varying vec2 Texcoord;
    uniform sampler2D tex0;
    void main()
    {
       gl_FragColor = texture2D(tex0, Texcoord) * vec4(Color, 1.0);
    }
)glsl";

I used some functions like this to confirm that shaders are successfully compiled and linked

int success; char infoLog[512];
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success); 
//can also use GL_LINK_STATUS flag
if(!success)
{
    glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
    std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl;
    std::cout <<  glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
    std::cout <<  success << std::endl;
};
$\endgroup$
  • 3
    $\begingroup$ I'm guessing a bit, so you will have to try around. However, you probably don't need the core annotation, i'm not even sure it exists for version 130. I couldn't find anything on the fly that would confirm this though. Some older versions don't support texture for access of textures, so you may need a texture2D here. All that being said, are your sure your glsl version is 130? That is extremely old. What kind of graphics card are you using? $\endgroup$ – Tare Jan 8 at 12:57
  • $\begingroup$ @Tare thank you. I will try your suggestion. I am sure about glsl version, confirmed both from line code glGetString(GL_SHADING_LANGUAGE_VERSION) and from terminal (glxinfo |grep version). Not sure about the graphics card, because the core runs under a virtual machine. $\endgroup$ – marcoresk Jan 8 at 13:16
4
$\begingroup$

There is no such thing as a core profile in GLSL 1.30. The concept of API profiles was introduced with OpenGL 3.2 which happened after GLSL 1.30 was released. The syntax for the version specification in GLSL 1.30 is

#version <number>

Apart from that, I highly recommend that you check to confirm that GLSL 1.30 really is the maximum version you're supposed to be able to use on your system. It seems not unlikely that you just don't have a proper OpenGL driver installed. Even software implementations like MESA support more recent versions than that these days…

$\endgroup$
  • $\begingroup$ Thanks, the provided syntax has been very useful. I checked about version, under the virtual machine the version number of GLSL is 1.30 and 99% i will not allowed to update the drivers, even if it is possible. (yes, I am forced to work under this virtual machine) $\endgroup$ – marcoresk Jan 9 at 13:57
  • $\begingroup$ Well, if this is a virtual machine which you can't change and are forced to use, then I guess 1.30 is, unfortunately, indeed what you're stuck with… $\endgroup$ – Michael Kenzel Jan 9 at 14:06

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.