• Advertisement

Archived

This topic is now archived and is closed to further replies.

Sprites

This topic is 6214 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How could I display sprites on OGL? Sprites as in: quads with a 3D location but always face the camera... I guess you''d have to somehow undo the rotation by the camera-martix in the modelview- but im not sure how... Anybody got ideas?

Share this post


Link to post
Share on other sites
Advertisement
It strongly depends on how you implement your rotations, but if you use them like NeHe does, the following code should work :

// Undo rotations and translations in opposite order in wich they were done
glTranslatef(Position.x,Position.y,Position.z);
glRotatef((float)( A1),0.0f,1.0f,0.0f);
glRotatef((float)(-A2),1.0f,0.0f,0.0f);
glRotatef((float)(-A3),0.0f,0.0f,1.0f);

// Draw Quad
glBegin(GL_QUADS);
glTexCoord2f(1.0f,0.0f);
glVertex3f(Size,-Size,0);

glTexCoord2f(0.0f,0.0f);
glVertex3f(Size,Size,0);

glTexCoord2f(0.0f,1.0f);
glVertex3f(-Size,Size,0);

glTexCoord2f(1.0f,1.0f);
glVertex3f(-Size,-Size,0);
glEnd();

// Redo Translations and rotations in the correct order
glRotatef((float)( A3),0.0f,0.0f,1.0f);
glRotatef((float)( A2),1.0f,0.0f,0.0f);
glRotatef((float)(-A1),0.0f,1.0f,0.0f);
glTranslatef(-Position.x,-Position.y,-Position.z);

This only displays a squar sprite, but you could easily draw rectangular ones with 2 Size variables. You should also watch you transparency/blend functions to avoid displaying it as a rectangle, other than that, this code should work perfectly (as it does in my engine

Edited by - Flous on February 18, 2001 4:03:52 PM

Share this post


Link to post
Share on other sites

  • Advertisement