Skip to main content
GameDev.net gamedev.net
🔒 Locked

Changing a point-sprite's size (image included)

Started by VanKurt Jul 13, 2006 at 3:16 AM 5 replies 9.6k views
Original Post
VanKurt
VanKurt
Hi there! The situation I'm currently trying to implement a particle system using point sprites. The tutorial I' using as a reference is this one: CodeSampler P.S.Tut. On the image below you can see the comparison between the tutorial's sample and my application (As you can see the sprites in the sample app appear to be much bigger than mine): Comparison between particles The problem So what I want to do now is to change my particle's sizes. Sadly the "glPointSize(x)" function won't change a thing [sad]. To be honest I didn't quite understand what all the point-sprite-code is about. So I weren't able to figure out what the problem is... Could you help me a little? Thank's so much!!! The code Just for reference, here's my code: Point sprite initialization:

void initPointSprites( void )
{
	// Create point sprite extensions
	char *ext = (char*)glGetString( GL_EXTENSIONS );
	if( strstr( ext, "GL_ARB_point_parameters" ) == NULL )
	{
		MessageBoxA(NULL,"GL_ARB_point_parameters extension was not found", "ERROR",MB_OK|MB_ICONEXCLAMATION);
		return;
	}
	else
	{
		glPointParameterfARB  = (PFNGLPOINTPARAMETERFARBPROC)wglGetProcAddress("glPointParameterfARB");
		glPointParameterfvARB = (PFNGLPOINTPARAMETERFVARBPROC)wglGetProcAddress("glPointParameterfvARB");

		if( !glPointParameterfARB || !glPointParameterfvARB )
		{
			MessageBoxA(NULL,"One or more GL_ARB_point_parameters functions were not found", "ERROR",MB_OK|MB_ICONEXCLAMATION);
			return;
		}
	}

	// Create texture
	AUX_RGBImageRec *pTextureImage = auxDIBImageLoad( L"default.bmp" );
	if( pTextureImage != NULL )
	{
		glGenTextures( 1, &g_textureID );
		glBindTexture( GL_TEXTURE_2D, g_textureID );
		glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR );
		glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR );

		glTexImage2D( GL_TEXTURE_2D, 0, 3, pTextureImage->sizeX, pTextureImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, pTextureImage->data );
	}

	if( pTextureImage )
	{
		if( pTextureImage->data )
			free( pTextureImage->data );

		free( pTextureImage );
	}

	MessageBoxA(NULL,"Point sprites successfully initialized!", "Info",MB_OK);
}

Point sprite rendering:

void CParticleEmitter::render( void )
{
	// Setup OpenGL
	glEnable(GL_TEXTURE_2D);
	bindMyTexture();
	glEnable( GL_BLEND );
	glBlendFunc( GL_SRC_ALPHA, GL_ONE );
	
	// Do some strange stuff I don't quite understand
	float quadratic[] =  { 0.01f, 0.0f, 0.01f };
	glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, quadratic );
	float maxSize = 0.0f;
	glGetFloatv( GL_POINT_SIZE_MAX_ARB, &maxSize );
	if( maxSize > 100.0f ) maxSize = 100.0f;
	glPointSize( maxSize );
	
	// Do even more strange stuff I don't quite understand
	glPointParameterfARB( GL_POINT_FADE_THRESHOLD_SIZE_ARB, 60.0f );
	glPointParameterfARB( GL_POINT_SIZE_MIN_ARB, 5.0f );
	glPointParameterfARB( GL_POINT_SIZE_MAX_ARB, maxSize );
	glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );
	glEnable( GL_POINT_SPRITE_ARB );

	// Render particles
	glBegin( GL_POINTS );
	{
		for( int i=0; i<maxParticleCount; i++ )
		{
			if( mParticles.isUsed  )
			{

				glColor4f(	mParticles.curColor.x,
							mParticles.curColor.y,
							mParticles.curColor.z,
							mParticles.curAlpha );
				glVertex3f( mParticles.curPos.x, mParticles.curPos.y, mParticles.curPos.z );
			}
		}//end for
	}
	glEnd();

	glDisable( GL_POINT_SPRITE_ARB );
	glDisable(GL_TEXTURE_2D);
}

VanKurt
VanKurt
No one? Come on guys! :-)
Ezbez
Ezbez
Well, glPointSize() won't change anything because you have a call to glPointParameter().

	// Do even more strange stuff I don't quite understand	glPointParameterfARB( GL_POINT_FADE_THRESHOLD_SIZE_ARB, 60.0f );	glPointParameterfARB( GL_POINT_SIZE_MIN_ARB, 5.0f );	glPointParameterfARB( GL_POINT_SIZE_MAX_ARB, maxSize );	glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );	glEnable( GL_POINT_SPRITE_ARB );


You *need* to research this stuff in order to understand what your doing here. I'll try to explain it a bit, but to be honest, I've never used this before, so this is all comming out of the book "Beginning OpenGL Game Program" (which is an excellent read, and explains this pretty nicely). The extension that you are using simply makes point's sizes affected by distance from the camera (like any other object).

The first parameter to glPointParameterARB() defines what is being changed. GL_POINT_FADE_THRESHOLD_SIZE_ARB determines how small a point can get before OpenGL makes it transparent (not sure if it will actually be transparent without enabling blending first). GL_POINT_SIZE_MIN determines the minimum size that a point can be, you can figure out GL_POINT_SIZE_MAX, then.

GL_POINT_DISTANCE_ATTENUATION is a little more interesting. It determines the formula used to calculate the size of points. It is, 1/(a + b*d + c *d^2), where a b and c are the values in the parameters you pass it (in this case, 'quadratic').

So, to change the point size, you need to change GL_POINT_SIZE_MAX and MIN. Looks like you've already got a global or something which is used for MAX.

Hope that helps.
VanKurt
VanKurt
Thank's for your explainations. But the point's sizes can't be changed using "glPointParameterfARB( GL_POINT_SIZE_MAX_ARB, maxSize );"
I already tried to pass any value between 1 and 1000 into maxSize without any effect :-(

I also played with all possible combinations in

float quadratic[] = { 1.0f, 0.0f, 0.01f };
glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, quadratic );

but that didn't change a thing, too.... am I missing something here????
Morpheus011
Morpheus011
That didn't change a thing because that's not how you change the size of points in ogl. glPointSize() is what you need.
Ezbez
Ezbez
Hm... Try fiddling around with GL_POINT_DISTANCE_ATTENUATION settings. Lowering A might help.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.