I m a newbie to programming and I want to write conditional statements for OpenGL models such that when I click a button it loads a Triangle model in a stl vector container. When I click the same button again, it loads another model say Quad in the container, and for further button clicks it loads more models such as Cube, Toroid and so on.... I m also going to include an Undo button to remove the last loaded model.
请允许我通过撰写这种有条件声明,说明如何将大约4个模型装入每 but点点击的STL矢量集装箱,以及单单载荷。
class Shapes {
public:
Shapes(){}
~Shapes(){}
virtual void draw()
{
std::cout << "Base function called" << std::endl;
}
};
class Models : public Shapes
{
public: Models()
{
}
~Models() {}
virtual void draw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5f, 0.0f, -6.0f);
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f); // Red color
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glColor3f(0.0f, 1.0f, 0.0f); // Green color
glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
glColor3f(0.0f, 0.0f, 1.0f); // Blue color
glVertex3f( 1.0f, -1.0f, 0.0f); // Bottom Right
glEnd(); // End drawing the triangle
}
};
Draw_All_models{
std::vector<Shapes*> myObjects;
myObjects.push_back(new Triangle());
myObjects.push_back(new Quad());
//more models...
void RenderScene()
{
std::vector<Shapes*>::iterator it;
for(it = myObjects.begin() ; it != myObjects.end; ++it) (*it)->draw();
}
}