opengl 不同面贴不同的纹理

参考: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;

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值