|
在没有背景图片的情况下,显示一组动画很流畅,可加入一张背景图后,显示非常不流畅,以下是源代码。
#include<hgl/hgl.h>
#include<hgl/OpenGL.H>
#include<hgl/Texture2D.H>
#include<hgl/hgp.h>
#include<hgl/InputState.h>
using namespace hgl;
class TestObject:public FlowObject
{
Texture2D *tex; //一个贴图指针
HGP* back; //背景
bool display_back; //是否显示背景图片
public:
void KeyDownProc(uint32 key)
{
if(key==' ') display_back=!display_back;
}
TestObject()
{
display_back=false;
tex=CreateTexture2D(L"Anim5.TEX",GL_RGBA2);
back=new HGP(L"back.hgp");
To2DMode(800,600);
glEnable(GL_TEXTURE_2D);
glClearColor(0.2,0.5,0.2,1);
OnKeyDown = KeyDownProc;
}
~TestObject()
{
delete tex;
delete back;
}
void Draw()
{
if(display_back)
back->Draw(0,0);
else
ClearScreen();
tex->Draw((640-256)/2,(480-256)/2);
}
};
void GameMain(char *)
{
SystemInitInfo iis;
iis.info.ProjectName=L"按空格键进行测试";
iis.info.ProjectCode=L"Application";
iis.graphics.FPS=400;
iis.graphics.Width=800;
iis.graphics.Height=600;
iis.graphics.fs.Width=800;
iis.graphics.fs.Height=600;
if(!Application->Init(&iis)) return;
Application->flow.SetStart(new TestObject);
Application->Run();
}
|
|