⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tutorials_tut04.html

📁 2D游戏引擎hge的代码
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- http://hge.relishgames.com -->

<html>

<head>
<meta name="Keywords" content="game engine, 2d, hardware accelerated, hge, engine, relish games, game development">
<meta name="Description" content="Haaf's Game Engine - Hardware accelerated 2D games engine">
<title>Haaf's Game Engine - Hardware accelerated 2D games engine</title>
<link rel=stylesheet type=text/css href=hge.css>
<script language="JavaScript" src="hge.js"></script>
</head>

<body onload="setContents('cnt_tutorials.html');" bgcolor=#ffffff text=#000000 link=#7F0000 vlink=#7F0000 alink=#7F0000 marginwidth=0 marginheight=0 leftmargin=0 topmargin=0>
<table height=100% cellspacing=0 cellpadding=0 border=0><tr>

<td valign=top>
<table width=566 cellspacing=0 cellpadding=20 border=0><tr><td>
<h1 style="margin-top:0px">Tutorial 04 - Rendering to texture</h1>
<p>
<b>I</b>n this tutorial we will learn how to use render targets.
First, we declare the variables to handle the render target and
the sprite that we will associate with it:
</p>
<pre>
hgeSprite*   tar;

HTARGET      target;
</pre>
<p>
When the application loses focus, the render target's texture
handle may change. So, we write the focus gain function
in which we obtain the new render target's texture:
</p>
<pre>
bool FocusGainFunc()
{
  tar->SetTexture(hge->Target_GetTexture(target));
  return false;
}
</pre>
<p>
In the <b>FrameFunc</b> (frame function) we first render
all our stuff onto the texture, specifying our render target
in the <a href="hgefunc_gfxbeginscene.html">Gfx_BeginScene</a> call:
</p>
<pre>
  hge->Gfx_BeginScene(target);
  hge->Gfx_Clear(0);
  par->Render();
  spr->Render(x, y);
  hge->Gfx_EndScene();
</pre>
<p>
Then we render several instances of the texture to the screen:
</p>
<pre>
  hge->Gfx_BeginScene();
  hge->Gfx_Clear(0);
  for(i=0;i<6;i++)
  {
    tar->SetColor(0xFFFFFF | (((5-i)*40+55)<<24));
    tar->RenderEx(i*100.0f, i*50.0f, 1.0f-i*0.1f, i*M_PI/8);
  }
  fnt->printf(5,5,"dt:%.3f\nFPS:%d", dt, hge->Timer_GetFPS());
  hge->Gfx_EndScene();
</pre>
<p>
In the <b>WinMain</b> function we attach our focus gain function:
</p>
<pre>
  hge->System_SetState(HGE_FOCUSGAINFUNC, FocusGainFunc);
</pre>
<p>
Then, after <b>HGE</b> initiation, we create a render target and a sprite 
that we will use to make rendering of the created texture easier:
</p>
<pre>
    target=hge->Target_Create(512,512,false);

    tar=new hgeSprite(
           hge->Target_GetTexture(target),0,0,512,512);
    tar->SetBlendMode(
           BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_NOZWRITE);
</pre>
<p>
During shutdown we delete the sprite that we used to render
the generated texture and the render target itself:
</p>
<pre>
    delete tar;
    hge->Target_Free(target);
</pre>
<p>
The rest of shutdown process is identical to the one demonstrated in
previous tutorials.
<br><br>
The complete source code with detailed comments for this tutorial you may find in the folder
<b>tutorials\tutorial04</b>. The required media files you'll find in the folder <b>tutorials\precompiled</b>.
</p>
<br>
</td></tr></table>
</td>

</tr></table>
</body>

</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -