HGE教程翻譯(5)

2021-05-24 12:01:30 字數 1713 閱讀 7385

使用曲面變換

在這個教程中我們學習如何使用曲面變形,一種可以建立水面、透鏡、紙張甚至實時的變化。我們使用靜態的紋理,但你可以渲染你的整個遊戲場景到乙個紋理,通過扭曲網格來達到一些很酷的實時特效。

首先包含標頭檔案和變數的宣告。

#include 

#include 

#include 

hge *hge = 0;

htexture tex;

hgedistortionmesh *dis;

接著我們宣告一些常量。這裡定義網格的數值和位置。

const int nrows=16;

const int ncols=16;

const float meshx=144;

const float meshy=44;

framefunc中需要一些變數。一對用於計時,結束符用來計算偏移。

float dt;

static float t=0.0f;

int i, j, col;

現在是關鍵部分。我們計算網格的位移並通過時間流逝來上色。

dt=hge->timer_getdelta();

t+=dt;

for(i=0; i
for(j=1; j

最終我們渲染網格在

renderfunc中:

hge->gfx_beginscene();

hge->gfx_clear(0);

dis->render(meshx, meshy);

hge->gfx_endscene();

winmain中我們載入紋理並初始化網格:

結束時刪除紋理和網格。

delete dis;

hge->texture_free(tex);

HGE教程翻譯(3)

這次我們會學習使用 hge的一些幫助類。首先,包含所有需要的標頭檔案並宣告 hge全域性指標,大多數幫助類都需要它。include include include include hge hge 0 現在宣告 hge物件。hgesprite spr hgesprite spt hgefont fnt...

HGE教程翻譯(4)

渲染紋理 首先我們宣告渲染物件的控制代碼和配合使用的精靈。hgesprite tar htarget target gfxrestorefunc 函式。bool gfxrestorefunc 在renderfunc中我們首先渲染所有的素材到紋理,在 gfx beginscene 中詳細指定渲染物件。...

HGE教程翻譯(7)

成千上萬的野兔 這篇教程示範hge渲染多種混合模式。建立精靈 我們跳過所有的技術細節直接來到動作。首先建立並初始化一對精靈,用於 game objects 和背景。注意背景精靈是如何從小的 64x64 圖塊建立並在底部上色。htexture tex,bgtex hgesprite spr,bgspr...