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 6 of 6

Thread: GLSL simple question

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2013
    Posts
    16

    Question GLSL simple question

    Hello

    If I understand well, in the vertex shader, the gl_Position built-in variable should get a clip-space value, that means a value between [-1,-1,-1,1] and [1,1,1,1].

    So if my vertex shader is

    "
    #version 330 core
    main()
    {
    gl_Position=vec4(0,0,0,1);
    }
    "

    and my fragment shader is

    "
    #version 330 core

    out vec4 color;

    main()
    {
    color=vec4(1,0,0,1);
    }
    "

    for anything drawn with "glDrawArrays(...);" juste before swapping the buffers,I should see a red point in the middle of the screen.
    But it doesn't work, someone could explain me where is the mistake?

    Thanks for the help
    Cathy L.

  2. #2
    Intern Contributor Brokenmind's Avatar
    Join Date
    Feb 2014
    Location
    Aachen / Germany
    Posts
    58
    The code itself should be correct, but I just tried it in my program and also don't see the red dot.

    My assumption is that due to some odd rounding errors or the resolution, the point is considered "too small" and thus not drawn. If you try to draw some 2D faces instead, you should see a result...

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2013
    Posts
    16
    Ok I'm gonna try, thanks a lot!
    At least you validate what I said about gl_Position, that was my main interest.

  4. #4
    Intern Contributor Godlike's Avatar
    Join Date
    May 2004
    Location
    Greece
    Posts
    67
    If you are drawing something other than GL_POINTS then I don't think you will see anything. For example a triangle with the same coordinates will not be drawn at all. Try drawing points with the above shaders and if you are already doing that maybe your depth culls them.

  5. #5
    Junior Member Newbie
    Join Date
    Sep 2013
    Posts
    16
    Good, I'll try!
    Thanks a lot

  6. #6
    Junior Member Newbie
    Join Date
    Sep 2013
    Posts
    16
    It works with GL_POINTS, thanks again!

Posting Permissions

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