Tuesday, September 29, 2009

Displaying a point sprite in OpenGL

After looking at a bunch of examples on how to use point sprites in OpenGL and seeing some with blatant errors and leaving out key things like setting the point size, I've decided to cut and paste my point sprite code snippet from PointSprite::draw()

// Get the max point size
glGetFloatv(GL_POINT_SIZE_MAX_ARB, &_maxSize );

// Get the minimum point size. Not necessary for this example, but interesting to know
glGetFloatv(GL_POINT_SIZE_MIN_ARB, &_minSize );

// Enable point sprites

// I've also seen the following used to enable point sprites:
// but I only needed the first one. Maybe it's because I'm using GLEW

// Replace the texture coordinates across the point sprite

// Set the point size.

// I saw some examples doing the following:
// glPointParameteri(GL_POINT_SIZE, _maxSize);
// But this didn't do anything for me. glPointSize was
// the only thing that actually set the point size

// Set a color. You'll want to use a nice texture map that you blend
// using a shader, but this is a simple example to get you started
glColor3f(1.0, 1.0, 1.0);

// Begin points. In real life, you'd use a vertex array.

// A point
glVertex3f(0.0, 0.0, -1.0);

// Done.

1 comment:

  1. Jeff,
    Did you get textures to work with points using vertex/fragment programs? I could do them in fixed functions, but for some reason cannot seem to get the texture coordinates to be generated correctly in the shaders.

    - Remon (from class of CS513)