Jump to content

  • Log In with Google      Sign In   
  • Create Account


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 VanKurt   Members   -  Reputation: 133

Like
0Likes
Like

Posted 12 July 2006 - 09:16 PM

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[i].isUsed  )
			{

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

	glDisable( GL_POINT_SPRITE_ARB );
	glDisable(GL_TEXTURE_2D);
}



Sponsor:

#2 VanKurt   Members   -  Reputation: 133

Like
0Likes
Like

Posted 13 July 2006 - 05:30 AM

No one? Come on guys! :-)

#3 Ezbez   Crossbones+   -  Reputation: 1164

Like
0Likes
Like

Posted 13 July 2006 - 07:00 AM

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.

#4 VanKurt   Members   -  Reputation: 133

Like
0Likes
Like

Posted 13 July 2006 - 10:20 AM

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????

#5 Morpheus011   Members   -  Reputation: 309

Like
0Likes
Like

Posted 13 July 2006 - 10:22 AM

That didn't change a thing because that's not how you change the size of points in ogl. glPointSize() is what you need.

#6 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

0Likes

Posted 13 July 2006 - 09:12 PM

Quote:
Original post by 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.


These are point sprites, not regular points. glPointSize won't do anything.


#7 Ezbez   Crossbones+   -  Reputation: 1164

Like
0Likes
Like

Posted 13 July 2006 - 10:40 PM

Hm... Try fiddling around with GL_POINT_DISTANCE_ATTENUATION settings. Lowering A might help.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS