标签:object 基类 idg model public function include 一个 div
创建一个基类为widget的工程
把文件夹glut64放到代码目录下,文件夹包含以下文件
freeglut.dll
freeglut.lib
glut.h
freeglut.h
freeglut_ext.h
freeglut_std.h
在工程文件*.pro中增加以下几行
win32: LIBS += -L$$PWD/glut64/ -lfreeglut
INCLUDEPATH += $$PWD/glut64
DEPENDPATH += $$PWD/glut64
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
class Widget : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
};
#endif // WIDGET_H
widget.cpp
#include "widget.h"
#include "glut64\freeglut.h"
Widget::Widget(QWidget *parent)
: QOpenGLWidget(parent)
{
}
Widget::~Widget()
{
}
void Widget::initializeGL()
{
initializeOpenGLFunctions();
glClearColor(0.0, 0.0, 0.0,1.0);
}
void Widget::resizeGL(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-10,10,-10,10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void Widget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLineWidth(5.0);
glColor3d(0.0,1.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2d(-8.0, -8.0);
glVertex2d(8.0, -8.0);
glVertex2d(0.0, 8.0);
glEnd();
}
标签:object 基类 idg model public function include 一个 div
原文地址:https://www.cnblogs.com/xieqianli/p/11399959.html