游戏的背景图片我们也可以用hgeQuad 来加载
struct hgeQuad
{
hgeVertex v[4];
HTEXTURE tex;
int blend;
};
struct hgeVertex
{
float x, y;
float z;
DWORD col;
float tx, ty;
};
其中,x,y被描述为屏幕坐标,
tx,ty被描述为纹理坐标,
col被描述为颜色。
一个点在屏幕上有坐标,一个矩形区域需要把一张图片映射进来,如果采用纹理方式,就需要为每一个点指定一个二维的坐标。
利用hgeQuad显示图片的过程:
1. 使用quad.tex=hge->Texture_Load("bj.png");来加载纹理
2. 设置hgeQuad的纹理坐标,窗口坐标,以及渲染模式。
3. 使用hge->Gfx_RenderQuad(&quad);来渲染图片
注意:设置纹理坐标以及窗口坐标时,v[0]表示左上角坐标,v[1]表示右上角坐标,v[2]表示右下角坐标,v[3]表示左下角坐标。
quad的tx=的最大范围为0.0-1.0
如果是全屏幕的话算法
就是你要使用用图片左上角的X,Y的坐标除以图片实际左上角的图标,四个角都是
#include "hgefont.h"// 包含hgefont头文件
#include <math.h>
HGE *hge=0;
hgeQuad quad;
bool FrameFunc()
{
quad.v[0].tx=0; quad.v[0].ty=0;//使用x坐标/图片x坐标
quad.v[1].tx=1; quad.v[1].ty=0;
quad.v[2].tx=1; quad.v[2].ty=1;
quad.v[3].tx=0; quad.v[3].ty=1;
return false;
}
bool RenderFunc()
{
// Render graphics
hge->Gfx_BeginScene();
hge->Gfx_RenderQuad(&quad);
hge->Gfx_EndScene();
return false;
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
hge = hgeCreate(HGE_VERSION);
hge->System_SetState(HGE_LOGFILE, "hge_tut06.log");
hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
hge->System_SetState(HGE_RENDERFUNC, RenderFunc);
hge->System_SetState(HGE_TITLE, "HGE Tutorial 06 - Creating menus");
hge->System_SetState(HGE_WINDOWED, true);
hge->System_SetState(HGE_SCREENWIDTH, 800);
hge->System_SetState(HGE_SCREENHEIGHT, 600);
hge->System_SetState(HGE_SCREENBPP, 32);
if(hge->System_Initiate())
{
// Load sound and textures
quad.tex=hge->Texture_Load("mp.jpg");
if(!quad.tex)
{
// If one of the data files is not found, display
// an error message and shutdown.
MessageBox(NULL, "Can't load ", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
hge->System_Shutdown();
hge->Release();
return 0;
}
quad.blend=BLEND_ALPHABLEND | BLEND_COLORMUL | BLEND_NOZWRITE;
for(int i=0;i<4;i++)
{
// Set up z-coordinate of vertices
quad.v[i].z=0.5f;
// Set up color. The format of DWORD col is 0xAARRGGBB
quad.v[i].col=0xFFFFFFFF;
}
quad.v[0].x=0; quad.v[0].y=0;
quad.v[1].x=800; quad.v[1].y=0;
quad.v[2].x=800; quad.v[2].y=600;
quad.v[3].x=0; quad.v[3].y=600;
hge->System_Start();
// Delete created objects and free loaded resources
hge->Texture_Free(quad.tex);
}
// Clean up and shutdown
hge->System_Shutdown();
hge->Release();
return 0;
}