M//Hax
12-14-2010, 07:24 AM
I was able to apply a 2D texture on point sprites, but it didnt really make it look like a 3D sphere. I've looked over alot of google pages and i didnt find anything about using glsl for making a point sprite appear like a sphere. Anyone know where i could find some infos on how to do this using a .vert and .frag program? Here the code where i'm drawing the point sprites :
void InitPointSprites()
{
setShaders();
g_floorLightMapTexture = LoadTexture("Content/Textures/floor_light_map.tga");
// clear buffer
// save the initial ModelView matrix before modifying ModelView matrix
// tramsform camera
if(vboUsed) // draw cube using VBO
{
glEnable( GL_DEPTH_TEST );
glDepthMask( GL_FALSE );
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_COLOR, GL_ONE);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboId);
// enable vertex arrays
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
// before draw, specify vertex and index arrays with their offsets
glNormalPointer(GL_FLOAT, 0, (void*)sizeof(vertices));
glColorPointer(3, GL_FLOAT, 0, (void*)(sizeof(vertices)+sizeof(normals)));
glVertexPointer(3, GL_FLOAT, 0, 0);
float quadratic[] = {1.0f, 0.0f, 0.01f};
glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATIO N_ARB, quadratic );
// Query for the max point size supported by the hardware
float maxSize = 0.0f;
glGetFloatv(GL_POINT_SIZE_MAX_ARB, &maxSize );
if(maxSize > 100.0f)
maxSize = 100.0f;
glPointSize(maxSize);
// The alpha of a point is calculated to allow the fading of points
// instead of shrinking them past a defined threshold size. The threshold
// is defined by GL_POINT_FADE_THRESHOLD_SIZE_ARB and is not clamped to
// the minimum and maximum point sizes.
glPointParameterfARB(GL_POINT_FADE_THRESHOLD_SIZE_ ARB, 60.0f);
glPointParameterfARB(GL_POINT_SIZE_MIN_ARB, 1.0f);
glPointParameterfARB(GL_POINT_SIZE_MAX_ARB, maxSize);
//glEnable(GL_TEXTURE_2D);
//glBindTexture(GL_TEXTURE_2D, g_floorLightMapTexture);
glEnable(GL_POINT_SPRITE_ARB);
glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
glDrawArrays(GL_POINTS, 0, numPoints);
glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_FALSE);
glDisable(GL_POINT_SPRITE_ARB);
//glBindTexture(GL_TEXTURE_2D, 0);
//glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_VERTEX_ARRAY); // disable vertex arrays
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glDisable(GL_BLEND);
glDisable( GL_DEPTH_TEST );
glDepthMask( GL_TRUE );
}
ShadersOff();
}
void InitPointSprites()
{
setShaders();
g_floorLightMapTexture = LoadTexture("Content/Textures/floor_light_map.tga");
// clear buffer
// save the initial ModelView matrix before modifying ModelView matrix
// tramsform camera
if(vboUsed) // draw cube using VBO
{
glEnable( GL_DEPTH_TEST );
glDepthMask( GL_FALSE );
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_COLOR, GL_ONE);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboId);
// enable vertex arrays
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
// before draw, specify vertex and index arrays with their offsets
glNormalPointer(GL_FLOAT, 0, (void*)sizeof(vertices));
glColorPointer(3, GL_FLOAT, 0, (void*)(sizeof(vertices)+sizeof(normals)));
glVertexPointer(3, GL_FLOAT, 0, 0);
float quadratic[] = {1.0f, 0.0f, 0.01f};
glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATIO N_ARB, quadratic );
// Query for the max point size supported by the hardware
float maxSize = 0.0f;
glGetFloatv(GL_POINT_SIZE_MAX_ARB, &maxSize );
if(maxSize > 100.0f)
maxSize = 100.0f;
glPointSize(maxSize);
// The alpha of a point is calculated to allow the fading of points
// instead of shrinking them past a defined threshold size. The threshold
// is defined by GL_POINT_FADE_THRESHOLD_SIZE_ARB and is not clamped to
// the minimum and maximum point sizes.
glPointParameterfARB(GL_POINT_FADE_THRESHOLD_SIZE_ ARB, 60.0f);
glPointParameterfARB(GL_POINT_SIZE_MIN_ARB, 1.0f);
glPointParameterfARB(GL_POINT_SIZE_MAX_ARB, maxSize);
//glEnable(GL_TEXTURE_2D);
//glBindTexture(GL_TEXTURE_2D, g_floorLightMapTexture);
glEnable(GL_POINT_SPRITE_ARB);
glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
glDrawArrays(GL_POINTS, 0, numPoints);
glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_FALSE);
glDisable(GL_POINT_SPRITE_ARB);
//glBindTexture(GL_TEXTURE_2D, 0);
//glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_VERTEX_ARRAY); // disable vertex arrays
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glDisable(GL_BLEND);
glDisable( GL_DEPTH_TEST );
glDepthMask( GL_TRUE );
}
ShadersOff();
}