欢迎进入第八课。到现在为止,您应该很好的理解OpenGL了。您已经学会了设置一个OpenGL窗口的每个细节。学会在旋转的物体上贴图并打上光线以及混色(透明)处理。
这一课应该算是第一课中级教程。您将学到如下的知识:在3D场景中移动位图,并去除位图上的黑色象素(使用混色)。接着为黑白纹理上色,最后您将学会创建丰富的色彩,并把上过不同色彩的纹理相互混合,得到简单的动画效果。
lesson8.h
#ifndef LESSON8_H
#define LESSON8_H
#include <QWindow>
#include <QOpenGLFunctions_1_1>
#include <QKeyEvent>
typedef struct // 为星星创建一个结构
{
int r, g, b; // 星星的颜色
GLfloat dist; // 星星距离中心的距离
GLfloat angle; // 当前星星所处的角度,自转角度
}stars; // 结构命名为stars
const int starCount = 50; // 星星的个数
class QPainter;
class QOpenGLContext;
class QOpenGLPaintDevice;
class Lesson8 : public QWindow, QOpenGLFunctions_1_1
{
Q_OBJECT
public:
explicit Lesson8(QWindow *parent = 0);
~Lesson8();
virtual void render(QPainter *);
virtual void render();
virtual void initialize();
public slots:
void renderNow();
protected:
void expose