Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Problem with fragment shader code

  1. #1
    Newbie Newbie
    Join Date
    Mar 2014
    Posts
    2

    Question Problem with fragment shader code

    Hi - I'm learning to use OpenGL and am following an online tutorial. However, the code for the shaders that they supply to begin with were written for version 1.5 and I am running version 1.2
    I have spent a good couple of hours trying to figure out what is wrong by looking on the internet and modifying the code appropriately to account for the differences between the two versions. However I am currently stuck with the vertex shader (I think the fragment shader is OK) and I keep getting the
    Code :
    ERROR: 0:3: '' : syntax error #version
    which apparently means something is still wrong with the code. Any help would be appreciated and I'm sure it's really simple but I'm just not able to fix it.....

    Fragment shader
    Code :
     
    #version 120 core
     
    out vec4 gl_FragColor;
     
    void main()
    {
        gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
    }

    Vertex Shader
    Code :
    #version 120 core
     
    in vec2 in_Vertex;
     
    void main()
    {
        gl_Position = vec4(in_Vertex, 0.0, 1.0);
    }

    (Compiling with Mac OSX 10.9.2 Xcode)

  2. #2
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    782
    To fix those shaders for #120, they should look like this:
    Code :
    #version 120
    attribute vec2 in_Vertex;
    void main()
    {
        gl_Position = vec4(in_Vertex, 0.0, 1.0);
    }
     
     
    #version 120
    void main()
    {
        gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
    }

    Because:
    1) the "core" profile qualifier didn't exist in #120. It was introduced in #150 (and defaults to "core", so you never need to use it on OSX.)
    2) vertex "in"puts are "attribute"s in #120. Vertex "out"puts and fragment "in"puts are "varying"s.
    3) gl_FragColor is pre-declared in #120, and you can't re-declare it. In #150 core, you can't use gl_FragColor, you must declare your own "out"put.


    Quote Originally Posted by alexbcg View Post
    I have spent a good couple of hours trying to figure out what is wrong
    It should only take a couple of hours to read the definitive GLSL references and then all of these differences should be clear.


    (Compiling with Mac OSX 10.9.2 Xcode)
    On OSX you could use the #150 shaders as-is, if you create a Core Profile context.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •