Multi Layer drawing and erasing them individually

Started by
2 comments, last by srikanth 22 years, 5 months ago
I am developing an real time application in which i want to have different individual layers on which i want to draw objects and erase them with out effecting the other layers. all the layers should be one over the other individually. how can i do it please help me out. srikanth
srikanth
Advertisement
I did something like that with my 2D RPG engine. You have 2 options :

-use drawing-order sorting :
Disable depth testing.
Draw a layer of objects, and then another. Remove an object from the first layer and then redraw the second layer. OpenGL will draw the second layer over the first one since it was drawn after it.

Good points : pretty fast, very easy
Bad points : multiple rendering passes

-use Z-Buffer sorting
Enable depth testing, and create a function like so :


void glDrawLayer(char layer, float depth)
{

if(layer==1)
{
glBegin(GL_WHATEVER_IT_IS_YOU_WANNA_DRAW_IN_LAYER_1)
glVertex3f(0.0, 0.0, depth);
glVertex3f(0.0, 1.0, depth);
glEnd();
}

if(layer=2)
{
glBegin(GL_WHATEVER_IT_IS_YOU_WANNA_DRAW_IN_LAYER_2)
glVertex3f(0.0, 0.0, depth);
glVertex3f(0.0, 1.0, depth);
glEnd();
}

}

At that point just call glDrawLayer(the layer you want, the depth you want)
Thanx for the reply, but i dont want to redraw the different layers, i want to only erase one layer without effecting the other. bcos i have to maintain 7 layers to do this. so erasing all of them will be a problem. can u suggest for an better idea.


srikanth
srikanth
The Z-buffering technique (see above)will automatically sort your layers, so deleting one will not affect the others.

This topic is closed to new replies.

Advertisement