帧动画
动态修改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"

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

被折叠的 条评论
为什么被折叠?



