帧动画 视频纹理

这篇博客展示了如何使用OpenGL和FFmpeg库来实现帧动画和视频播放。通过FFMPEGVideoReader加载视频文件,提取每一帧并转化为纹理,然后在OpenGL的四边形上进行渲染。OpenGL窗口类SamplerTexture中包含了创建纹理、更新纹理和绘制帧的关键代码,实现了视频帧在四边形上的实时播放效果。

帧动画
动态修改uv 采样大图上面的区域 依次显示形成帧动画

#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  _texture1;
	
	int _texWidth;
	int _texHeight;

	int _imageWidth;
	int _imageHeight;
public:
    SamplerTexture() 
    {
   
   
		
    }

    virtual void    onShutdownGL()
    {
   
   
        glDeleteTextures(1,&_texture1);
    }
    
	 unsigned    createTextureFromImage(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);

		_texWidth = width;
		_texHeight = height;

		_imageWidth = 108;
		_imageHeight = 108;

        unsigned    res =   createTexture(width,height,pixels);
        FreeImage_Unload(dib);
        return      res;
    }

    unsigned    createTexture(int w,int h,const void* data)
    {
   
   
        unsigned    texId;
        glGenTextures(1,&texId);
        glBindTexture(GL_TEXTURE_2D,texId);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
       
        glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,w,h,0,GL_RGBA,GL_UNSIGNED_BYTE,data);

       
        return  texId;
    }
    virtual void    onInitGL()
    {
   
   
		glClearColor(0,0,0,1);
		glEnable(GL_TEXTURE_2D);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(45,double(_width)/double(_height),0.1,100);
		_texture1 = createTextureFromImage("xx.png"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值