PDA

View Full Version : How to get point attenuation to work in OpenGL ES?



mobilevisuals
10-19-2009, 12:10 AM
I am producing a mobile screensaver which simulates the stars in galaxies. The stars are point sprites and the stars which are far away should look smaller than those closer to the viewer. That is why I need point attenuation. I have tried to include everything to get point attenuation to work, but the points still have the same size. Why doesn't the point attenuation have any effect? This is my code:

glPointSize( 4 );
GLfloat min=0.1f;
glPointParameterf(GL_POINT_SIZE_MIN, min);
GLfloat max=4f;
glPointParameterf(GL_POINT_SIZE_MAX, max);
//the coordinates for calcluting point atenuation
iPointSizeCoords[0] = 0f;
iPointSizeCoords[1] = 0.5f;
iPointSizeCoords[2] = 0.5f;
glPointParameterf(GL_POINT_DISTANCE_ATTENUATION,*i PointSizeCoords);
glPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE,5.f );

thinks
10-19-2009, 06:13 AM
Not sure exactly what the problem is, but I think this line:

glPointParameterf(GL_POINT_DISTANCE_ATTENUATION,*i PointSizeCoords);

should be:

glPointParameterf(GL_POINT_DISTANCE_ATTENUATION, iPointSizeCoords);

mobilevisuals
10-19-2009, 09:59 AM
I tried your idea,but I got "function call does not match", so it can't be that.

thinks
10-19-2009, 10:04 AM
Sorry, it should be:

glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, iPointSizeCoords);

Notice the extra 'v', which is necessary since you are passing an array.

mobilevisuals
10-20-2009, 12:47 AM
Thanks, it worked without errors. But I still do not see any point attenuation. You can see my current code below. I have tried a lot of values for the attentuation coordinates (iPointSizeCoords) but I never see any results. Do I need to add more code? Or should I remove glPointSize( 4 ) or
glPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE,5.f ) or do I need to enable something more?

glPointSize( 4 );
glPointParameterf(GL_POINT_SIZE_MIN, 0.1f);
glPointParameterf(GL_POINT_SIZE_MAX,4.0f);
iPointSizeCoords[0] = 0.0f;
iPointSizeCoords[1] = 5.0f;
iPointSizeCoords[2] = 5.0f;
glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, iPointSizeCoords);
glPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE,5.f );

mobilevisuals
10-20-2009, 08:04 AM
I got it to work now. The problem is that the S60 3d edition FP1 emulator can not simulate point attenuation. When I run the same program on a mobile device as on the emulator, the point attenuation works on the mobile but not on the emulator. So if you only try it on the emulator, you think that the code is wrong, eventhough it isn't. You can see my working code below:

glPointSize(8);
glPointParameterf(GL_POINT_SIZE_MIN, 0.1f);
glPointParameterf(GL_POINT_SIZE_MAX,8.0f);
//the coordinates for calcluting point atenuation:
iPointSizeCoords[0] = 1.0f;
iPointSizeCoords[1] = 0.055f;
iPointSizeCoords[2] = 0.0f;
glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, iPointSizeCoords);

thinks
10-21-2009, 04:12 AM
Thanks for sharing your solution.