纹理矩阵 多张纹理叠加 云雾效果 环境纹理

纹理矩阵

使用纹理矩阵实现之前的广告牌效果
取消之前cpu的顶点uv赋值

直接使用纹理矩阵操作

glMatrixMode(GL_TEXTURE);
		
glTranslatef(0,0.001f,0);
#include <windows.h>
#include <tchar.h>
#include <math.h>

#include "FreeImage.h"


#include "CELLMath.hpp"

#include "OpenGLWindow.h"
#include <gl/GLU.h>
#include <vector>
using namespace CELL;

struct Vertex
{
    
    float x, y, z;
    float u, v;
};
class   SamplerTexture :public OpenGLWindow
{
   
    GLuint  _texture;
	float  _textureV;
public:
    SamplerTexture() 
    {
   
		_textureV=0;
    }

    virtual void    onShutdownGL()
    {
   
        glDeleteTextures(1,&_texture);
    }
    
	virtual FIBITMAP*readImage(const char* fileName)
    {
   
        FREE_IMAGE_FORMAT fifmt = FreeImage_GetFileType(fileName, 0);
        if (fifmt == FIF_UNKNOWN)
        {
   
            return  0;
        }
        FIBITMAP    *dib = FreeImage_Load(fifmt, fileName,0);

        FREE_IMAGE_COLOR_TYPE type    =   FreeImage_GetColorType(dib);

        FIBITMAP*   temp    =   dib;
        dib =   FreeImage_ConvertTo32Bits(dib);
        FreeImage_Unload(temp);

        BYTE*   pixels =   (BYTE*)FreeImage_GetBits(dib);
        int     width   =   FreeImage_GetWidth(dib);
        int     height  =   FreeImage_GetHeight(dib);

        for (int i = 0 ;i < width * height * 4 ; i+=4 )
        {
   
            BYTE temp       =   pixels[i];
            pixels[i]       =   pixels[i + 2];
            pixels[i + 2]   =   temp;
        }
        return      dib;
    }

    virtual void    onInitGL()
    {
   
		FIBITMAP* arrayImage[1];
		arrayImage[0] = readImage( "1.png" );
       

        glGenTextures(1,&_texture);
        glBindTexture(GL_TEXTURE_2D,_texture);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

		 BYTE*   pixels =   (BYTE*)FreeImage_GetBits(arrayImage[0]);
         int     width   =   FreeImage_GetWidth(arrayImage[0]);
         int     height  =   FreeImage_GetHeight(arrayImage[0]);
         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,GL_RGBA, GL_UNSIGNED_BYTE, pixels);
         FreeImage_Unload(arrayImage[0]);
    }
    virtual void    render()
    {
   
		#define M_PI (3.14159265358979323846)
        //! 指定以下的操作针对投影矩阵
        glMatrixMode(GL_PROJECTION);
        //! 将投影举证清空成单位矩阵
        glLoadIdentity();

        gluPerspective(60,double(_width)/double(_height),0.1,1000);

		 _textureV   +=  0.001f;
        Vertex cubeVertices[] =
        {
   
            {
     -1.0f,-0.125f, 1.0f    ,0,  0 },
            {
     1.0f,-0.125f, 1.0f     ,1,  0 },
            {
     1.0f, 0.125f, 1.0f     ,1,  0.25f },
            {
    -1.0f, 0.125f, 1.0f     ,0,  0.25f },
        };
		glMatrixMode(GL_TEXTURE);
		
		glTranslatef(0,0.001f,0);
   
        glMatrixMode(GL_MODELVIEW
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值