HGE基本渲染图元

HGE基本的渲染图元是hgeQuad (Quad is the basic HGE graphic primitive),其中有一个hgeVertex成员结构,它用来描述图元顶点信息。The hgeVertex structure is used to describe vertices of which HGE graphic primitives consist.两个结构信息如下:

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被描述为颜色。创建一组顶点,每个顶点包含了位置坐标,和纹理坐标(纹理坐标一般为0--1),还有颜色等信息。为什么会有屏幕坐标很纹理坐标呢,一个点在屏幕上有坐标,一个矩形区域需要把一张图片映射进来,如果采用纹理方式,就需要为每一个点指定一个二维的坐标,hgeQuad就采用了四个纹理坐标,存在hgeVertex中,这样就可以从一张纹理图中切割一部分来渲染。这四个顶点分别从左上角开始顺时针表示一个RECT

利用hgeQuad显示图片的过程:

1.  用Texture_Load载入外部文件作为纹理。hgeQuad quad;  quad.tex=hge->Texture_Load("particles.png");

2.  设置hgeQuad的纹理坐标,窗口坐标,以及渲染模式。 

      quad.blend=BLEND_ALPHAADD | BLEND_COLORMUL| BLEND_ZWRITE;

3.  每一帧都调用 Gfx_RenderQuad函数,这个函数用hge->System_SetState()设置的。


通过小精灵hgeSprite和HTEXTURE配合也可以进行图形渲染,

hgeSprite方法:

ConstructorsCreate and initalize a hgeSprite object.
OperatorshgeSprite operators.
  
RenderRenders sprite to the screen.
RenderExRenders sprite with scaling and rotation.
RenderStretchRenders stretched sprite.
Render4VRenders sprite into arbitrary quad on the screen.
  
SetTextureSets the texture to use for the sprite.
SetTextureRectSets the texture region to use for the sprite.
SetColorSets tint and alpha for the specified vertex or entire sprite.
SetZSets Z-order for the specified vertex or entire sprite.
SetBlendModeSets the sprite blending mode.
SetHotSpotSets the sprite anchor point.
SetFlipFlips the sprite horizontally and/or vertically.
  
GetTextureReturns the current sprite texture.
GetTextureRectReturns the current texture region used for the sprite.
GetColorReturns color of the specified sprite vertex.
GetZReturns Z-order of the specified sprite vertex.
GetBlendModeReturns the current sprite blending mode.
GetHotSpotReturns the sprite anchor point.
GetFlipReturns the current sprite flipping.
  
GetWidthReturns the sprite width.
GetHeightReturns the sprite height.
GetBoundingBoxReturns the sprite bounding box.
GetBoundingBoxExReturns the scaled and rotated sprite bounding box.

typedef DWORD  HTEXTURE;
也就是说HTEXTURE实际上就是一个纹理的指针

渲染过程很简单,初始化:

HTEXTURE tex1;  hgeSprite *spr;

tex1=hge->Texture_Load("1.jpg"); 

spr=new hgeSprite(tex1,0,0,800,600); //初始化图片精灵,后四个参数分别是,起始位置X,起始位置Y,图片宽,图片高。

在渲染函数中:

hge->Gfx_BeginScene();  //开始渲染
hge->Gfx_Clear(0xFFFFFFFF);   //以某种颜色清屏幕
spr->Render(10,10);     //在指定的位置上显示精灵
spr->SetColor(0xFFFF0000);    //设置hgesprite的渲染颜色是红色,前两位是透明度a,后面一次是r,g,b
hge->Gfx_EndScene();  //结束渲染 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值