Point Sprite Rotation

Hello again,

I’m currently trying to learn Point Sprites, and having a difficult time understanding them. I’m following a tutorial here. I have a good looking particle engine, but it doesn’t cover rotate. I’ve tried playing with glRotatef, but can’t get the results I want. Here is the render function as it is: (ParticleEmitter.m)

- (void)renderParticles {
	
	glEnable(GL_TEXTURE_2D);
	
	// Enable texturing and bind the texture to be used as the point sprite
	if(texture && [sharedGameState currentlyBoundTexture] != [[texture texture] name]) {
		glBindTexture(GL_TEXTURE_2D, [[texture texture] name]);
		[sharedGameState setCurrentlyBoundTexture:[[texture texture] name]];
	}
	
	// Enable and configure blending
	glEnable(GL_BLEND);
	
	// Change the blend function used if blendAdditive has been set
	if(blendAdditive) {
		glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	} else {
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	}
	
	// Enable and configure point sprites which we are going to use for our particles
	glEnable(GL_POINT_SPRITE_OES);
	glTexEnvi( GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, GL_TRUE );
	
	// Enable vertex arrays and bind to the vertices VBO which has been created
	glEnableClientState(GL_VERTEX_ARRAY);
	glBindBuffer(GL_ARRAY_BUFFER, verticesID);
	
	// Configure the vertex pointer which will use the vertices VBO
	glVertexPointer(2, GL_FLOAT, sizeof(PointSprite), 0);
	
	// Enable the point size array
	glEnableClientState(GL_POINT_SIZE_ARRAY_OES);
	
	// Configure the point size pointer which will use the currently bound VBO.  PointSprite contains
	// both the location of the point as well as its size, so the config below tells the point size
	// pointer where in the currently bound VBO it can find the size for each point
	glPointSizePointerOES(GL_FLOAT,sizeof(PointSprite),(GLvoid*) (sizeof(GL_FLOAT)*2));
	
	// Enable the use of the color array
	glEnableClientState(GL_COLOR_ARRAY);
	
	// Bind to the color VBO which has been created
	glBindBuffer(GL_ARRAY_BUFFER, colorsID);
	
	// Configure the color pointer specifying how many values there are for each color and their type
	glColorPointer(4,GL_FLOAT,0,0);
	
	// Now that all of the VBOs have been used to configure the vertices, pointer size and color
	// use glDrawArrays to draw the points
	glDrawArrays(GL_POINTS, 0, particleIndex);
	
	// Unbind the current VBO
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	// Disable the client states which have been used incase the next draw function does 
	// not need or use them
	glDisableClientState(GL_POINT_SPRITE_OES);
	glDisableClientState(GL_POINT_SIZE_ARRAY_OES);
	glDisableClientState(GL_COLOR_ARRAY);
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_POINT_SPRITE_OES);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}


Do you guys have any wisdom for me on how I could add rotation to each particle?

Thanks,

Craig

I have a good looking particle engine, but it doesn’t cover rotate.

That’s because point sprites don’t rotate. Point sprites are always window-aligned squares.

Thanks for the quick response.

So, would there be a way to load a few textures and apply a 2nd two every other particle? Or do you have a better recommendation to break up the repetitiveness of the particles?

Thanks.

Here’s a hint: point sprites also support multitexturing, so you can use 2 textures and blend by various amounts between them. And/or color them differently.

Or, if you decide to go the shader way, you can “create” point sprites quite easily (still you’ll have to pass 4 vertices, not 1), then you can also rotate those sprites in screen space, can affect the texture coordinates however you like and will also avoid some problems with point sprites (if the center of the point is outside the screen, the point sprite dissapears completly even if you could theoretically still see parts of it ).
Of course, the shader way will require a bit more work, but the results are worth it ;).

So Can you point me out towards some code to get started actually implementing this. I should be working on this in the morning, so literally anything that would break up the tiling of this stream would be of great help.

Thanks

uff…
here http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=22 you have a preety decent tutorial about multitexturing (at least the first part, before the bump mapping theory).

here http://www.opengl.org/wiki/Texture_Combiners you have a nice description about the texture combiners AND the equivalent shader code. Now, depending on whatever effect you’re trying to obtain, you can use these things to get it.
Now read, think, code …