PDA

View Full Version : Displaying and transforming objects in layers



blessman11
04-03-2011, 12:07 PM
Using the glDisplayfunc();, I want to display and transform individual objects in layers but its misbehaving instead. I know about how open gl executes the matrices at the bottom of the function first during any translations.

However aside from that I don't know how I can apply individual transformations in layers.

//basically when I add the static_object, the transformations for background are tampered with. Any help here?

void Display()
{
Background();
Static_object();
glutSwapBuffers();
Sleep(15);//delay (frame change)
}

Alfonse Reinheart
04-03-2011, 03:28 PM
Any help here?

How can we help if you don't show what you're doing? The problem isn't with these 4 lines of code; the problem is within the functions that these lines of code call.

Kelvin
04-04-2011, 08:13 PM
Perhaps what you're looking for is glPushMatrix/glPopMatrix. These allow you to isolate transformations that apply only to an single object from tranforms that apply to the whole layer.

e.g.


// generic transforms for world setup
glPushMatrix() // save pre-layer1 transforms
// transform the layer1 (e.g. translation for all objects in layer 1)
glPushMatrix() // save pre-object A
// transform object A in layer 1 (e.g. rotation this object only)
// draw object A
glPopMatrix() // back to layer 1 transforms
glPushMatrix()
// transform object B within layer 1
glPopMatrix() // back to layer 1
glPopMatrix() // back to world
glPushMatrix() // save world
// transforms common to all layer 2 objects
glPushMatrix()
// transform object C within layer 2
// draw object C
glPopMatrix() // back to layer 2
glPopMatrix() // back to world


If you don't have the glPushMatrix/glPopMatrix functions in the version of OpenGL you are targeting, you will have to manage this yourself.

NOTE: The "layers" above are purely conceptual. In reality you are always drawing objects -- you don't actually "draw layers". But you can apply common transformations to all objects that you consider to be in the same layer.