opengl序列帧特效

前些天逛论坛,发现了些png序列帧的图片资源。一时兴起写个程序玩一玩。

 

理论非常简单,循环改变纹理即可。

 

上代码

class SequenceFrame
{
public:
	SequenceFrame()
	{

	}

	void Init(const char* filePath, const char* fileHeadName, int sumFrame);
	void update();
	void drawRect(float left, float right, float bottom, float top,float z);


	GLuint* mTextures;
	int currentFrame; // 当前的帧
	int maxFrame;  // 最大的帧
};
#include "SequenceFrame.h"

GLuint createTexture(const char* fileName)
{
	GLuint texture;
	texture = SOIL_load_OGL_texture(fileName, 0, 0, SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_INVERT_Y);
	return texture;
}

void SequenceFrame::Init(const char* filePath, const char* fileHeadName, int sumFrame)
{
	mTextures = new GLuint[sumFrame];
	//glGenTextures(sumFrame, mTextures);

	maxFrame = sumFrame;
	currentFrame = 0;

	char imgFileName[256];
	for (int i = 0; i < maxFrame; ++i)
	{
		memset(imgFileName, 0, 256);
		sprintf(imgFileName,"%s/%s%d.png", filePath, fileHeadName, i+1);
		mTextures[i] = createTexture(imgFileName);
		printf("%s\n", imgFileName);
	}
}

void SequenceFrame::update()
{
	currentFrame += 1;
	
	if (currentFrame == maxFrame)
		currentFrame = 0;
	//printf("%d   ", currentFrame);
}

void SequenceFrame::drawRect(float left, float right, float bottom, float top,float z)
{
	glBindTexture(GL_TEXTURE_2D, mTextures[currentFrame]);
	glBegin(GL_QUADS);
	glTexCoord2f(0.0f, 0.0f); glVertex3f(left, bottom, z);
	glTexCoord2f(1.0f, 0.0f); glVertex3f(right, bottom, z);
	glTexCoord2f(1.0f, 1.0f); glVertex3f(right, top, z);
	glTexCoord2f(0.0f, 1.0f); glVertex3f(left, top, z);
	glEnd();
}

 

Init参数如下例

test.Init("imageFrame/2", "1406-", 20);

项目资源如图

 画的时候,先draw再update就行了。效果还是挺炫酷的,挺唬人的技术

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值