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: How to change the fragcoords relative location. (from the window)

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2014
    Posts
    22

    How to change the fragcoords relative location. (from the window)

    Hi!

    I want to change the origin lower left to the origin upper left corner like it's explained in the documentation :
    https://www.opengl.org/sdk/docs/man/...ragCoord.xhtml

    But I have an error when I try to compiler the shader :

    Code :
    "#version 330 core \n"
                "layout(origin_upper_left) in vec4 gl_FragCoord;"
                "layout(pixel_center_integer);"
                "layout(location = 0) in vec3 vertex_position;"
                "layout(location = 1) in vec4 vertex_color;"
                "layout(location = 2) in vec2 vertex_texCoords0;"
                "layout(location = 3) in vec3 vertex_normal;"
                "uniform mat4 mvp;"
                "out vec2 texCoords;"
                "out vec4 color;"
                "void main () {"
                    "gl_Position = mvp * vec4(vertex_position.xyz, 1);"
                    "texCoords = vertex_texCoords0;"
                    "color = vertex_color;"
                "}";

    It tells me that there is an unespected ; at then end of line 2.

    How can I change gl_FragCoord to upper_left_corner ?

    PS : (whithout this two lines : )
    "layout(origin_upper_left) in vec4 gl_FragCoord;"
    "layout(pixel_center_integer);"
    it compiles without any problems.

  2. #2
    Junior Member Newbie
    Join Date
    Jul 2014
    Posts
    22
    I've found the solution, we have just to separate the layout qualifiers by a , :
    Code :
     "#version 330 core \n"
                "layout(origin_upper_left, pixel_center_integer) in vec4 gl_FragCoord;"
                "uniform sampler2D texture;"
                "uniform sampler2D normalMap;"
                "uniform vec3 resolution;"
                "in vec2 texCoords;"
                "in vec4 color;"
                "out vec4 fragColor;"
                "void main() {"
                    "vec2 position = (gl_FragCoord.xy / resolution.xy);"
                    "vec4 oldNormal = texture2D(normalMap, position);"
                    "vec4 newNormal = texture2D(texture, texCoords);"
                    "if ((newNormal.x == 0 && newNormal.y == 0 && newNormal.z == 0) && (oldNormal.x != 0 || oldNormal.y != 0 || oldNormal.z != 0)) {"
                        "fragColor = oldNormal;"
                    "} else {"
                        "fragColor = newNormal;"
                    "}"
                "}";

Posting Permissions

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