参考:http://www.qiliang.net/old/nehe_qt/index.html
不同面纹理贴图在放在begin与end之间,类似下面,否则不生效.
glBindTexture( GL_TEXTURE_2D, texture[0] );
glBegin(GL_QUADS);
glTexCoord2f( 0.0, 0.0 ); glVertex3f( -1.0, -1.0, 1.0 );
glTexCoord2f( 1.0, 0.0 ); glVertex3f( 1.0, -1.0, 1.0 );
glTexCoord2f( 1.0, 1.0 ); glVertex3f( 1.0, 1.0, 1.0 );
glTexCoord2f( 0.0, 1.0 ); glVertex3f( -1.0, 1.0, 1.0 );
glEnd();
/nehewidget.h:
#ifndef NEHEWIDGET_H
#define NEHEWIDGET_H
#include <QtOpenGL> // Header File For OpenGL Module
class NeHeWidget : public QGLWidget
{
Q_OBJECT // Declaration For Q_OBJECT
public:
NeHeWidget( QWidget* parent = 0 ); // Declaration For NeHeWidget
~NeHeWidget();
protected:
void initializeGL(); // All Setup For OpenGL Goes Here
void paintGL(); // Here's Where We Do All The Drawing
void resizeGL( int width, int height ); // Resize And Initialize The GL Window
void keyPressEvent( QKeyEvent *e ); // Declaration For Key Press Event
void loadGLTextures();
protected:
bool fullscreen; // Declaration For Full Screen Switch
GLfloat rTri;
GLfloat rQuad;
GLfloat xRot, yRot, zRot;
GLfloat zoom;
GLfloat xSpeed, ySpeed;
GLuint texture[3];
GLuint filter;
bool light;
};
#endif//NEHEWIDGET_H
/nehewidget.cpp:
#include "nehewidget.h"
/*!
* Declaration For NeHeWidget
*/
GLfloat lightAmbient[4] = { 0.5, 0.5, 0.5, 1.0 };
GLfloat lightDiffuse[4] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat lightPosition[4] = { 0.0, 0.0, 2.0, 1.0 };
NeHeWidget::NeHeWidget( QWidget* parent )
: QGLWidget( parent ), fullscreen(false)
{
setGeometry( 0, 0, 640, 480 );
xRot = yRot = zRot = 0.0;
//setCaption( "NeHe's OpenGL Framework" );
rTri = 0.0;
rQuad = 0.0;
zoom = -5.0;
xSpeed = ySpeed = 0.0;
filter = 0;