GL_ARB_point_parameters
and GL_ARB_point_sprite extensions.![]()
1:
Introduction.
In Basic particle systems we use quad to render geometry. This is
very expensive for each particle to billboard the face and after send 4 points
and 4 textures coordinate to video cards. The GL_ARB_point_parameters
and GL_ARB_point_sprite give us a fast and easy way for rendering particles.
These extensions allow us to use points rather than quads.
2:
Set up extension.
The first think to do is to check if your video card supports one
of the two extensions. After that step we get de functions pointer.
|
In your
header file |
|
|
0 1 2 3 4 |
bool
m_PointARBEnable; bool
m_PointNVEnable; PFNGLPOINTPARAMETERFARBPROC glPointParameterfARB ; PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB
; void CheckForExtension(void); |
0: A Boolean used later to check if Point ARB is available.
1: A Boolean used later to check if Point NV is available.
2,3: Functions pointer for extensions.
|
In your cpp file |
|
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
void CheckForExtension(void) { char *ext = (char*)glGetString( GL_EXTENSIONS ); ///////////////////////////////////////////////////////////////// //Looking for
GL_ARB_point_parameters extension ///////////////////////////////////////////////////////////////// if( strstr( ext,
"GL_ARB_point_parameters" ) != NULL
) { glPointParameterfARB
= (PFNGLPOINTPARAMETERFEXTPROC)wglGetProcAddress("glPointParameterfARB"); glPointParameterfvARB
= (PFNGLPOINTPARAMETERFVEXTPROC)wglGetProcAddress("glPointParameterfvARB"); if( !glPointParameterfARB || !glPointParameterfvARB
) { LOGFILE<<"One
or more GL_EXT_point_parameters functions were not
found"<<std::endl; m_PointARBEnable=false; } m_PointARBEnable=true; } } |
2:
Use a char* to store the list of extension available on video cards.
6:
Check if we find the string "GL_ARB_point_parameters" in the extension list.
8, 9:
Get the pointer for glPointParameterfARB and glPointParameterfvARB function.
10-16:
Check if success and set Boolean state.
3: New
functions and constants descriptions.
A:
glPointParameterfARB and glPointParameterfvARB.
These
functions are used to set points parameters.
glPointParameterf[v]ARB(Glenum pname,GLfloat param);
The
variable pname can take 4 values. Each
of these values is constant and defined in “glext.h”.
GL_POINT_SIZE_MIN_ARB: The param parameter is used to specify the
minimum point size.
The default value is 0.0
Be careful don’t set minimum size to a value greater
than the maximum size.
GL_POINT_SIZE_MAX_ARB: The param parameter is used to specify the
maximum point size.
The default value is the
largest point size supported by the implementation.
Be careful don’t set minimum size to a value greater
than the maximum size.
GL_POINT_FADE_THRESHOLD_ARB: The param parameter is used to specify the
point size for which smaller
Points fade out instead of
shrinking when multisampling is enabled.
The default value is 1.0f.
GL_POINT_DISTANCE_ATTENUATION_ARB: The param parameter is used to specify the
coefficients used in
the distance attenuation
function for point size.
The default array value is 0,0,0.
B: new constant for Point Parameter.
There is 2 new constant GL_POINT_SPRITE_ARB and GL_COORD_REPLACE_ARB.
We use GL_POINT_SPRITE_ARB and GL_COORD_REPLACE_ARB to center texture on vertex.
glTexEnvf (GL_POINT_SPRITE_ARB,
GL_COORD_REPLACE_ARB, GL_TRUE);
We enable point parameter by calling this function.
glEnable (GL_POINT_SPRITE_ARB);
4:Exemple draw a particle.
VecParticle is an array of particle.
|
0 1 2 3 4 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
void DrawARBPointSprites(Particle*
VecParticle, int Number) { float quadratic[]
= { 0.0f, 0.0f, glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, quadratic ); float maxSize = glGetFloatv( GL_POINT_SIZE_MAX_ARB,
&maxSize ); glPointSize(
maxSize ); glPointParameterfARB(
GL_POINT_SIZE_MAX_ARB, maxSize ); glPointParameterfARB(
GL_POINT_SIZE_MIN_ARB, glTexEnvf(
GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE
); glEnable(
GL_POINT_SPRITE_ARB ); glBegin(
GL_POINTS ); { for(int i=0;i<Number;i++) { glColor4f(VecParticle[i].Color.x,VecParticle[i].Color.y,VecParticle[i].Color.z,1.0f); glVertex3f(VecParticle[i].Position.x,VecParticle[i].Position.y,VecParticle[i].Position.z); } } glEnd(); glDisable(
GL_POINT_SPRITE_ARB ); } |
2-3:
declare and pass value for distance attenuation.
4-8:
Get the maximum point size available and apply it.
9:
Set the minimum point size.
10:
Tell openGL to center texture on vertex.
11:
Enable point rendering.
12-20:
Draw all particles in array.
21:
Disable point sprite.
For
questions or comments see our forum section.
Source:tutorialARB.zip
References:
The
OpenGL Extensions guide. By Eric Lengyel.
Charles rivers Media
ISBN:
1-58450-294-0
OpenGl 1.2 guide
Campus
Press
ISBN:
2-7440-0841-9