How does the default GLSL shaders look like? for version 330

后端 未结 1 1183
礼貌的吻别
礼貌的吻别 2021-02-01 17:20

What do the default vertex, fragment and geometry GLSL shaders look like for version #330?

I\'ll be using #version 330 GLSL Version 3.30 NVIDIA via Cg compi

相关标签:
1条回答
  • 2021-02-01 17:59

    There are no "default" shaders with OpenGL. It looks like what you want a very simple example of a shader that transforms vertices to clip space and gives them a color, so here you go:

    Vertex shader:

    #version 330
    
    layout(location = 0)in vec4 vert;
    
    uniform mat4 projection;
    uniform mat4 view;
    uniform mat4 model;
    
    void main()
    {
        gl_Position = projection * view * model * vert;
    }
    

    Fragment shader:

    #version 330
    
    out vec4 fragColor;
    
    void main()
    {
        fragColor = vec4(1.0, 0.0, 0.0, 1.0);
    }
    

    The core OpenGL 3.3 profile drops support for a lot of old fixed-function things like the matrix stack. You are expected to handle your own matrices and send them to your shaders. There is no ftransform, and gl_Position is pretty much the only valid gl_* variable.

    While glBindAttribLocation is not deprecated, the preferred method of defining the location of vertex attributes is through "layout(location = x)" in GLSL.

    In the vertex shader, "attribute" is now "in" and "varying" is now "out". In the fragment shader, "varying" is now "in" and "gl_FragColor" is defined by an "out" variable. I believe that gl_FragColor is still valid, but now it's possible to use an out variable to define the color.

    This tutorial is very good and teaches core OpenGL and GLSL 3.30, I would recommend you use it to help you learn more about GLSL. Also remember that the GLSL Reference Pages is your friend.

    0 讨论(0)
提交回复
热议问题