-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
09-surface-batch-rendering.inl
45 lines (37 loc) · 1.11 KB
/
09-surface-batch-rendering.inl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#define SCENE_GAME 1
struct sSceneGame : public ZL_Scene
{
ZL_Surface srfBlock;
sSceneGame() : ZL_Scene(SCENE_GAME) { }
void InitGlobal()
{
srfBlock = ZL_Surface("Data/PATTERN.png");
}
//Clear screen and draw the surface many times with batch rendering enabled
void Draw()
{
ZL_Display::ClearFill(ZL_Color::Black);
srfBlock.BatchRenderBegin(true);
for (scalar x = 10, maxX = ZLFROMW(34), maxY = ZLFROMH(34); x < maxX; x += s(24))
for (scalar y = 10; y < maxY; y += s(24))
srfBlock.Draw(x, y, ZL_Color::LUM(RAND_FACTOR));
srfBlock.BatchRenderEnd();
}
} SceneGame;
struct sMain : public ZL_Application
{
//we set fps limit to 0 to have unlocked frame rate
sMain() : ZL_Application(0) {}
ZL_Font fntMain;
void Load(int argc, char *argv[])
{
ZL_Display::Init("Surface Batch Rendering", 854, 480);
fntMain = ZL_Font("Data/fntMain.png");
ZL_SceneManager::Init(SCENE_GAME);
}
//display fps
void AfterFrame()
{
fntMain.Draw(ZLFROMW(30), ZLFROMH(30), (const char*)ZL_String::format("%d FPS", FPS), ZL_Color::White, ZL_Origin::CenterRight);
}
} Main;