Qt_OpenGL:雾程序小测
//.h
#ifndef FOGTEST_H
#define FOGTEST_H
#include <QWidget>
#include <QtOpenGL>
class FogTest : public QGLWidget
{
Q_OBJECT
public:
FogTest(QWidget *parent = 0);
~FogTest();
protected:
void initializeGL();
void paintGL();
void resizeGL(int , int );
void keyPressEvent(QKeyEvent*);
private:
void init(void);
void renderSphere(GLfloat x, GLfloat y, GLfloat z);
void display();
private:
GLint fogMode;
};
#endif // FOGTEST_H
//.cpp
#include "fogtest.h"
#include <iostream>
#include <cmath>
#include <glut.h>
using std::cout;
FogTest::FogTest(QWidget *parent)
: QGLWidget(parent)
{
}
void FogTest::init(){
GLfloat position[] = { 0.5, 0.5, 3.0, 0.0 };
glEnable(GL_DEPTH_TEST);
glLightfv(GL_LIGHT0, GL_POSITION, position);
glEnable(GL_LIGHTING);