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

Thread: gl_PointCoord anyone?

  1. #1
    Intern Contributor
    Join Date
    Dec 2016
    Posts
    53

    gl_PointCoord anyone?

    Hey all,

    I'm working on a new series, experimenting with Point Sprites.

    I've got this line in my code to enable point sizes in the shader:

    Code :
    glEnable(GL_PROGRAM_POINT_SIZE);

    I've also got this line in the vertex shader:

    Code :
    gl_PointSize = 30.0f;

    And I'm using the gl_PointCoord.x and gl_PointCoord.y in the fragment shader, and I can't get it to do anything.

    I've tried discarding point greater than a certain value.... nothing. Less than a certain value..... nothing.

    Any ideas on making something? Anything? with gl_PointCoord?? I just want to play around, literally anything would be great, even something simple (which is what I thought I was trying).

    Alright, thanks,

    Jeff

  2. #2
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    870
    Do you understand when gl_PointCoord is undefined?

  3. #3
    Intern Contributor
    Join Date
    Dec 2016
    Posts
    53
    Quote Originally Posted by arekkusu View Post
    Do you understand when gl_PointCoord is undefined?
    Maybe that's the part I'm missing. When is it undefined? I haven't seen any documentation on this, and I've googled a bunch.......

    Any help would be appreciated, especially if you have an example of how to work with this built in variable.

    Thanks,

    Jeff

  4. #4
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    870
    Read the documentation, specifically the GLSL specification that defines gl_PointCoord:

    Quote Originally Posted by GLSL 4.50 "Built-in Variables" page 128
    If the current primitive is not a point, or if point sprites are not enabled, then the values read fromgl_PointCoord are undefined.
    Next question: do you understand how to enable point sprites?

  5. #5
    Intern Contributor
    Join Date
    Dec 2016
    Posts
    53
    Point Sprites are enabled by default, there is no setting to enable point sprites:

    My intellisense shows just this:

    GL_POINT_SIZE
    GL_POINT_SIZE_GRANULARITY
    GL_POINT_SIZE_RANGE
    GL_POINT_SPRITE_COORD_ORIGIN

    there is no constant for GL_POINT_SPRITE

    .....

    So, nobody has even a small example of manipulating this built in variable?

    I'm not surprised.... since the example from the book that I'm studying didn't work, maybe the feature is deprecated.

    I hope not,
    Jeff

  6. #6
    Intern Contributor
    Join Date
    Dec 2016
    Posts
    53
    This is the video series that I was going to do, I've done the first video, the rest was going to be tinkering with this built-in variable, but I don't think it's working.....

    and I can't find any sample code on making it work either.... but I will....I must.... for I am a ...... hobby programmer.

    https://www.youtube.com/watch?v=73XoxNQ4WNc&t=3s

    Jeff

  7. #7
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    870
    Quote Originally Posted by OceanJeff40 View Post
    Point Sprites are enabled by default
    That's true in a core profile GL context, or in ES2, ES3, or WebGL.
    But it's not true in a compatibility profile GL context, or in ES1.

    So, what context profile are you using? And do your included headers match your context profile?



    Quote Originally Posted by OceanJeff40 View Post
    I can't find any sample code on making it work either
    It took me three minutes to write and test a complete, minimal, working example using gl_PointCoord:
    Code :
    //
    // gl_PointCoord
    //
    // cc sprite.c -framework OpenGL -framework GLUT -Wno-deprecated-declarations -o sprite && ./sprite
    //
     
    #include <GLUT/glut.h>
    #include <stdlib.h>
     
    GLint prog;
     
    void reshape(int w, int h)
    {
        glViewport(0, 0, w, h);
    }
     
    void display(void)
    {
        glClear(GL_COLOR_BUFFER_BIT);
     
        glBegin(GL_POINTS);
            glVertex2f(0, 0);
        glEnd();
     
        glutSwapBuffers();
        glutPostRedisplay();
    }
     
    void init(void)
    {
        glPointSize(32);    
        glEnable(GL_POINT_SPRITE);
     
        const GLchar *src =
        "#version 120\n"
        "void main() {\n"
        "    gl_FragColor = vec4(gl_PointCoord, 0.0, 1.0);\n"
        "}";    
     
        prog = glCreateProgram();
        GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
        glShaderSource(fs, 1, &src, NULL);
        glCompileShader(fs);    
        glAttachShader(prog, fs);
        glLinkProgram(prog);
        glDeleteShader(fs);    
     
        glUseProgram(prog);
    }
     
    int main(int argc, char *argv[])
    {
        glutInit(&argc, argv);
        glutInitDisplayString("double rgba");
        glutInitWindowSize(480, 320);
        glutCreateWindow("Sprite");
        glutDisplayFunc(display);
        glutReshapeFunc(reshape);
     
        init();
        glutMainLoop();
        return 0;
    }

    This uses GLUT and a compatibility profile context. On OSX (GL2.1, Nvidia, Intel, and Software renderers), it produces a black window with one 32x32 sprite in the center. The sprite shows gl_PointCoord as a black->red gradient from left->right, and black->green gradient from top->bottom.

    The only interesting part of that code is glEnable(GL_POINT_SPRITE). Commenting that line out results in "undefined" behavior; the sprite changes to all-black on Nvidia and software renderers, and is unchanged on Intel.

  8. #8
    Intern Contributor
    Join Date
    Dec 2016
    Posts
    53
    Anybody else have any other examples of using this? I still haven't gotten this to work for me.

    Links to examples would be great too.

    Thanks in advance,

    Jeff

    P.S. Perhaps other profiles? etc.

  9. #9
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,123
    Quote Originally Posted by OceanJeff40 View Post
    Anybody else have any other examples of using this? I still haven't gotten this to work for me.
    It's been 5 years, but I know I've seen this used in an NVidia example, possibly in their GPU Computing SDK.

    I may have an example at home. In the interim, check out the point sprite shaders in the OpenGL Programming Guide (9th edition) examples:

    * https://github.com/openglredbook/exa...s/pointsprites
    * https://github.com/openglredbook/exa...3-pointsprites

Posting Permissions

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