Problems with Point Sprites

Started by smith, December 04, 2006, 00:29:18

Previous topic - Next topic

smith

I am having problems getting point sprite distance attenuation working.

I am using the following code:

GL11.glEnable(ARBPointSprite.GL_POINT_SPRITE_ARB);
GL11.glTexEnvf(ARBPointSprite.GL_POINT_SPRITE_ARB,ARBPointSprite.GL_COORD_REPLACE_ARB, GL11.GL_TRUE);
GL14.glPointParameterf(GL14.GL_POINT_SIZE_MIN, 0.0f);
GL14.glPointParameterf(GL14.GL_POINT_SIZE_MAX, 500.0f);
GL11.glPointSize(100.0f);
GL14.glPointParameter(GL14.GL_POINT_DISTANCE_ATTENUATION, GLUtils.toBuffer(1.0f,0.0f,0.0f,0.0));
GL11.glBegin(GL11.GL_POINTS);
for(Particle particle : particles){
    particle.draw();
}
GL11.glEnd();

Particle class:

public void draw(){
    GL11.glColor4f(1.0f,1.0f,1.0f,fade);
    GL11.glVertex3f(x,y,z);
}


Except all the particles draw at ~500px which is GL_POINT_SIZE_MAX.
All the docs I have looked at state that the glPointSize() should be
attenuated by the GL_POINT_DISTANCE_ATTENUATION function. However
regardless of what I set this to one of two things happen, either the
particle is drawn at GL_POINT_SIZE_MIN or GL_POINT_SIZE_MAX. I have
never been able to get them to draw at anything in between.
Also glPointSize() seems to have no effect whatsoever.

Am I missing something?

Also as an aside, why does glPointParameter() need a FloatBuffer with
four elements when the parameter only requires three?



Fool Running

Try the values (0.0f, 0f, 0.0001f, 0.0f) for the GL_POINT_DISTANCE_ATTENUATION. Change the 0.0001 to whatever works best for you  :)
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

smith

Thanks for the reply,

I've tried (0.0f, 0f, 0.00001f, 0.0f) and still get the same result. I have played around a lot
with the attenuation function and only ever get MAX_SIZE or MIN_SIZE never anything in between.
There is something else going on apart from the distance attenuation that I am missing.

Why does the glPointSize() not change anything?



Fool Running

Its a long shot, but I seem to remember having a similar problem and I fixed it by using the ARBpointParametersSupport versions of GL_POINT_SIZE_MIN, GL_POINT_SIZE_MAX, and GL_POINT_DISTANCE_ATTENUATION instead of the GL14 versions...
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

smith

Tried the ARBPointParameters versions, still the same result.
Looking through the spec for point sprites I came across this:

derived_size = clamp(size * sqrt(1 / (a + b * d + c * d ^ 2)))

Now if I set the attenuation vector to (1.0, 0.0, 0.0), then derived
size should always be the same size as that set with glPointSize(),
but it always comes out as POINT_SIZE_MAX.

What is going on? Is there some other factor that effects the size
other than glPointSize() and the distance attenuation function?

Fool Running

Well, I'm out of ideas. You are doing (as near as I can tell) the same thing I'm doing in my engine and its working for me ???
This is what I'm doing:
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL13.*;
import static org.lwjgl.opengl.ARBPointSprite.*;
import static org.lwjgl.opengl.ARBPointParameters.*;

    public void setup(){
        // enable point param support
        if(ARBpointParametersSupport){
            glPointParameterARB(GL_POINT_DISTANCE_ATTENUATION_ARB
                             , BufferUtils.setFB4(new float[]{0.0f, 0f, 0.0001f, 0.0f}));
            glPointParameterfARB(GL_POINT_SIZE_MIN_ARB, 1.0f);
            glPointParameterfARB(GL_POINT_SIZE_MAX_ARB, 100.0f);
        }

        // enable point sprite rendering
        if(ARBpointSpriteSupport){
            glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, 1);
        }
    }

    public void render(){
        glPointSize(pointSize);
        glEnable(ARBPointSprite.GL_POINT_SPRITE_ARB);
        
        // Render all the points
    }

Maybe you can see something I'm not seeing ;D
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

smith

I am beginning to suspect it has something to do with my OpenGL drivers
(Quadro FX 1400 running on Ubuntu-edgy with nvidia drivers).
I have been hunting round and saw the Ogre guys were having a similar
problem. They were running up against the max point size limit of 63 pixels,
which is not very big. I really don't understand why point sprites work the
way they do, it seams stupid that you have to use an attenuation function
when you have already specified the projection matrix.

I'm still having a play around but will post if I get it sorted.

Thanks for you help.