🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Sprites

Started by
1 comment, last by David20321 24 years ago
Yes I know I''ve been polluting this message forum thing with all these questions about sprites but i have to clarify my real problem. My problem is that with Depth-testing on if I draw a sprite in front of another one then the black part of the sprite in front still covers the sprite in back. It looks very ugly. I fixed it by making it draw the farthest sprite first and then the nearer ones but still if you rotate the camera the sprites rotate against the camera and occasionally half of one sprite gets stuck in the other one and the part of the sprite that clips through the other one covers up part of the sprite behind it.
Advertisement
I think you''re using rasterization functions, right?
Try using textured polygons (with GL_REPLACE, not GL_BLEND, or you won''t have transparence) as your sprites. z-buffering will then probably do everything right.

Eric Laberge
----------------------------------------"Inash neteia haeg joa kavari quilm..." SD4
I''m pretty sure I''m using textured polygons and I''m using GL_BlEND. It works except that sometimes the sprites clip through each other. Here is my sprite routine thing if anybody wants to help. The stuff with olddistance is trying to draw the sprites in order from farthest sprite to nearest. The spritetypes stuff tells how to draw the different sprites. Spritetype 2 is the sun and spritetype 6 is a ground-hugging shockwave thing. If anybody can help it will be appreciated A LOT!

glDisable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);

for (num=0; num<51; num++)
{
Olddistance=-20000;
for (num2=0; num2<51; num2++)
{
if ((Square(Spritex[num2]-CamPosx)+Square(Spritez[num2]-CamPosz))+Square(Spritey[num2]-CamPosy)>Olddistance&&Spritedrawn[num2]==0//num==0&&Spritetype[num2]!=0){
Olddistance=(Square(Spritex[num2]-CamPosx)+Square(Spritez[num2]-CamPosz))+Square(Spritey[num2]-CamPosy);
target=num2;
}
}
Spritedrawn[target]=1;
if (Spritetype[target]!=0){
if (Spritetype[target]==1){glColor4f(255,0,0,Spritebrightness[target]/255);size=1;}
if (Spritetype[target]==2){glColor4f(255,255,0,Spritebrightness[target]/255);size=10;}
if (Spritetype[target]==3){glColor4f(255,0,100,Spritebrightness[target]/255);size=3;}
if (Spritetype[target]==4){glColor4f(100,100,100,Spritebrightness[target]/255);size=3;}
if (Spritetype[target]==5){glColor4f(255,255,0,Spritebrightness[target]/255);size=3;}
if (Spritetype[target]==6){glColor4f(255,255,0,Spritebrightness[target]/255);size=Spritesize[target];}
glLoadIdentity();
glRotatef(CameraAngle,0.0f,1.0f,0.0f);
if (Spritetype[target]!=2){
Transx=Spritex[target]-CamPosx;
Transy=Spritey[target]-CamPosy;
Transz=Spritez[target]-CamPosz;
glTranslatef(Transx,Transy,Transz);
}
if (Spritetype[target]==2){
Transx=Spritex[target];
Transy=Spritey[target]-10;
Transz=Spritez[target];
glTranslatef(Transx,Transy,Transz);
}
if (Spritetype[target]!=6){glRotatef(-CameraAngle,0.0f,1.0f,0.0f);}
if (Spritetype[target]==6){glRotatef(90,1.0f,0.0f,0.0f);}
glRotatef(Spriteangle[target],0.0f,0.0f,1.0f);
glBindTexture(GL_TEXTURE_2D, texture[3]);
if (Spritetype[target]==4//Spritetype[target]==5){glBindTexture(GL_TEXTURE_2D, texture[5]);}

if (Spritetype[target]==6){glBindTexture(GL_TEXTURE_2D, texture[4]);}
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-.3f*size,-.3f*size, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( .3f*size,-.3f*size, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( .3f*size, .3f*size, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-.3f*size, .3f*size, 0.0f);
glEnd(); }
}
glDisable(GL_BLEND);
glEnable(GL_LIGHTING);

This topic is closed to new replies.

Advertisement