我正在Display list
为我拥有的所有 GUI 对象创建一个,如下所示:
glNewList(displayList, GL_COMPILE);
obj->draw();
glEndList();
但是当我尝试编译它时,我得到一个错误:
R6025 - pure virtual call
该draw()
方法是纯虚拟的。但我想知道,为什么我不能把虚函数放在里面Display list
?
编辑:
这是 GUIObject 类:
class GUIObject
{
protected:
int m_id;
int m_parentId;
int m_width;
int m_height;
Point m_position;
Point m_drawPosition;
bool m_bEnabled;
bool m_bVisible;
GLuint m_displayListId; // Id in display lists array in TGUIManager
virtual void onDrawStart() = 0;
virtual void onDrawFinish() = 0;
public:
virtual bool draw() = 0;
void setDisplayListId(GLuint id);
GLuint getDisplayListId();
virtual int getWidth() const;
virtual int getHeight() const;
virtual bool pointInObject(const TPoint& point);
GUIObject();
virtual ~GUIObject();
};
GUIObject::GUIObject() :
m_position(Point(0,0)),
m_width(0),
m_height(0),
{
m_drawPosition = m_position;
GUIManager::Instance().addObject(this);
}
GUIObject::~GUIObject()
{
}
这里是Button
类,它派生自Component
which 派生自GUIObject
:
class Button : public Component, public Clickable
{
private:
std::string m_text;
TBackground* m_pBackground;
public:
void setText(std::string text);
void setBackground(Background* pBg);
Background* getBackground() const;
void setBackgroundOnClick(Background* pBg);
Background* getBackgroundOnClick() const;
bool draw();
int getFontSize() const;
std::string getText() const;
Button& operator=(const Button & button);
// From Clickable
bool wasClicked(const Point& clickPos);
Button();
~Button();
};
bool Button::draw()
{
onDrawStart(); // This needs to be called in each object
if(!isClicked() && m_pBackground != nullptr)
m_pBackground->draw(m_drawPosition, m_width, m_height);
else if(m_pBackgroundOnClick != nullptr)
m_pBackgroundOnClick->draw(m_drawPosition, m_width, m_height);
FontManager::Instance().renderLineOfText(font, lineLength, pos, textToRender);
onDrawFinish(); // This needs to be called in each object
return true;
}
Button::Button() :
TComponent(Point(0,0)),
m_pBackground(nullptr),
m_pBackgroundOnClick(nullptr),
m_text("")
{
}
Button::~Button()
{
if(m_pBackground != nullptr)
{
delete m_pBackground;
m_pBackground = nullptr;
}
}
Button& Button::operator=(const Button & button)
{
m_position = Point(button.getPos());
m_pBackground = new Background()
return *this;
}
好的,我想我包含了所有必需的代码部分。
绘图内容是 insideBackground
的draw()
方法。
调用的对象是在构造函数内部的方法obj
中作为参数传递的对象:addObject()
GUIObject
GUIManager::Instance().addObject(this);