HGE游戏引擎之hgeQuad结构体的使用(用于渲染图片)
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方法:
| Constructors | Create and initalize a hgeSprite object. |
| Operators | hgeSprite operators. |
| Render | Renders sprite to the screen. |
| RenderEx | Renders sprite with scaling and rotation. |
| RenderStretch | Renders stretched sprite. |
| Render4V | Renders sprite into arbitrary quad on the screen. |
| SetTexture | Sets the texture to use for the sprite. |
| SetTextureRect | Sets the texture region to use for the sprite. |
| SetColor | Sets tint and alpha for the specified vertex or entire sprite. |
| SetZ | Sets Z-order for the specified vertex or entire sprite. |
| SetBlendMode | Sets the sprite blending mode. |
| SetHotSpot | Sets the sprite anchor point. |
| SetFlip | Flips the sprite horizontally and/or vertically. |
| GetTexture | Returns the current sprite texture. |
| GetTextureRect | Returns the current texture region used for the sprite. |
| GetColor | Returns color of the specified sprite vertex. |
| GetZ | Returns Z-order of the specified sprite vertex. |
| GetBlendMode | Returns the current sprite blending mode. |
| GetHotSpot | Returns the sprite anchor point. |
| GetFlip | Returns the current sprite flipping. |
| GetWidth | Returns the sprite width. |
| GetHeight | Returns the sprite height. |
| GetBoundingBox | Returns the sprite bounding box. |
| GetBoundingBoxEx | Returns 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(); //结束渲染
HGE游戏引擎之hgeQuad结构体的使用(用于渲染图片)的更多相关文章
- 对HGE游戏引擎的一次封装
HGE游戏引擎是一个开源2D游戏引擎,基于directX. 它的渲染及逻辑是基于帧回调的框架模式, 其提供一些主要的图像操作和输入控制功能. 我在之前写一个2D游戏的时候对它整个框架进行了一次封装,非 ...
- HGE游戏引擎之实战篇,渐变的游戏开场
#include <hge.h> #include "menuitem.h" //#include <hgefont.h> #include <hge ...
- 游戏引擎架构 (Jason Gregory 著)
第一部分 基础 第1章 导论 (已看) 第2章 专业工具 (已看) 第3章 游戏软件工程基础 (已看) 第4章 游戏所需的三维数学 (已看) 第二部分 低阶引擎系统 第5章 游戏支持系统 (已看) 第 ...
- Swift 的类、结构体、枚举等的构造过程Initialization(下)
类的继承和构造过程 类里面的全部存储型属性--包含全部继承自父类的属性--都必须在构造过程中设置初始值. Swift 提供了两种类型的类构造器来确保全部类实例中存储型属性都能获得初始值,它们各自是指定 ...
- Go part 5 结构体,方法与接收器
结构体 结构体定义 结构体的定义只是一种内存布局的描述(相当于是一个模板),只有当结构体实例化时,才会真正分配内存空间 结构体是一种复合的基本类型,通过关键字 type 定义为 自定义 类型后,使结构 ...
- C语言实现链表中结构体嵌套
1.首先,定义两个结构体,一个用于定义链表,一个用于定义数据 // 定义数据相关的结构体 typedef struct Student{ int stu_id; ]; }Stu; // 定义链表相关的 ...
- APUE学习笔记——4.2结构体 struct stat 及其相关函数介绍
以下不少内容来自man手册 结构体struct stat 结构体struct stat用于保存文件相关的所有信息. struct stat的基本成员如下所示 struc ...
- 转载:[转]如何学好3D游戏引擎编程
[转]如何学好3D游戏引擎编程 Albert 本帖被 gamengines 从 游戏引擎(Game Engine) 此文为转载,但是值得一看. 此篇文章献给那些为了游戏编程不怕困难的热血青年,它的 ...
- 第1部分: 游戏引擎介绍, 渲染和构造3D世界
原文作者:Jake Simpson译者: 向海Email:GameWorldChina@myway.com ---------------------------------------------- ...
随机推荐
- ACCESS自动编号重新从1开始
方法一: 删掉自动编号的字段,再建一个同样的自动编号字段. 方法二: 选择工具,再选择数据库实用工具,单击压缩和修复数据库,这样就OK了. 方法三:(提示错误“无效的数据字段类型” 尝试失败) ...
- LightOj1074 - Extended Traffic(SPFA最短路)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1074 题意:有n个城市,每个城市有一个拥堵值a[i],m条单向路u到v,从u到v所需时 ...
- OC initialize和init
Objective-C很有趣的一个地方是,它非常非常像C.实际上,它就是C语言加上一些其他扩展和一个运行时间(runtime). 有了这个在每个Objective-C程序中都会起作用的附加运行时间,给 ...
- 针对大的sql文件删除行操作
今天处理开发已导出的库的一个sql文件.未gzip压缩 ,1.3G 需要删除 17 18 24行的SET行. 想到了两个办法 1 sed 方法 主意 由于 sed 虽然指定行 进行 替换, 也会读完 ...
- UIStoryboard类介绍(如何从Storyboard中加载View Controller)
如何从Storyboard中加载View Controller? 1. 首先了解下UIStoryboard类: @class UIViewController; @interface UIStoryb ...
- hadoop 文件系统API操作
配置参数:-DHADOOP_USER_NAME=hadoop public class HdfsUtils { private static FileSystem fileSystem; @Befor ...
- iTOP-4412 开发板镜像的烧写
镜像就是源代码编译并连接以后生成的可执行文件包,把这些镜像文件烧写到开发板的存储芯片里,开机就可以运行了. 烧写方式有两种,通过TF卡烧写以及使用OTG接口烧写 OTG方式:只能在WIN7 或者XP ...
- hibernate3与ehcache-2.8.3配合使用,在多个SessionFactory实例的情况下出现“Another unnamed CacheManager already exists in the same VM”问题
不想看分析过程的,直接拉到最下面看第4部分 1. 问题背景 由于某些原因,项目中使用了hibernate3与ehcache-2.8.3在配合使用,又由于某些原因,需要使用多个SessionFactor ...
- .NET Framework 4 中的并行编程9---线程安全集合类
原文转载自:http://www.cnblogs.com/xray2005/archive/2011/10/11/2206745.html 在.Net 4中,新增System.Collections. ...
- System.Threading.Timer使用心得
System.Threading.Timer 是一个使用回调方法的计时器,而且由线程池线程服务,简单且对资源要求不高. "只要在使用 Timer,就必须保留对它的引用."对于任何托 ...