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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
#include "basic.h"
using namespace F2C;
int wndWidth = 640;
int wndHeight = 480;
std::string title = "Fantasy2C Simple";
bool fullscreen = false;
double framerate = 60.0f;
F2C::uint wndBits = 32;
bool MaxFramerateON = true;
int main(){
InApp.InitInput(); //init Input
WinApp.setWindowHint(F2C::WindowProperty::NoResize,true); //set Option:Window No Resize = true
WinApp.getInstance()->CreateGLWindow(title.c_str(),wndWidth,wndHeight,wndBits,fullscreen); //create Window
WinApp.setWindowPosition(160,120);
WinApp.InitGL();
LogError::ClearLog();
if(WinApp.getSupportedShader()){
WinApp.InitGLShader();
loadFragmentShader("grayscale.frag");
}
Background sprTerrain;
FontSprite sprText;
FontSprite sprInfo;
Sprite sprLogo;
TTFFont font;
F2CLoadBitmapintoSprite(sprTerrain,"Terrain.bmp");
F2CLoadBitmapintoSprite(sprInfo,"Font.png");
F2CLoadFontFile(font,"Arial.ttf");
sprText.setBitmap(&font.getBitmap());
sprTerrain.x = wndWidth/2-sprTerrain.getTexWidth()/2;
sprTerrain.y = wndHeight/2-sprTerrain.getTexHeight()/2;
sprTerrain.vColor[0].set(0,255,0);
sprTerrain.vColor[1].set(0,255,0);
sprTerrain.vColor[2].set(0,0,255);
sprTerrain.vColor[3].set(0,0,255);
std::string text = "Hallo Welt!";
Rect textSize = getStringSize(sprText,text);
int x = wndWidth/2-textSize.width/2;
int y = wndHeight/2-textSize.height/2;
sprText.addText(x,y,textSize.width,textSize.height,text.c_str());
sprText.vColor[0].set(255,0,0);
sprText.vColor[1].set(255,0,0);
sprText.vColor[2].set(255,255,0);
sprText.vColor[3].set(255,255,0);
double last_fps = 0.0f;
double rest_time = 0.0f;
double start_rest_time = 0.0f;
bool quit = false;
bool useESC = true;
while(!quit){
quit = stdUpdateHandle(MaxFramerateON,framerate,useESC,last_fps,rest_time,start_rest_time);
InKeyApp.update();
if(InKeyApp.getTriggerKey(KeyboardEvent::F1)){
MaxFramerateON = !(MaxFramerateON);
}
if(InApp.getPressKey(KeyboardEvent::Up)){
sprTerrain.src_rect.y -= 1;
}
if(InApp.getPressKey(KeyboardEvent::Down)){
sprTerrain.src_rect.y += 1;
}
if(InApp.getPressKey(KeyboardEvent::Left)){
sprTerrain.src_rect.x -= 1;
}
if(InApp.getPressKey(KeyboardEvent::Right)){
sprTerrain.src_rect.x += 1;
}
WinApp.ClearGLScene(); //clear Screen
sprTerrain.render();
sprText.render();
sprInfo.render();
WinApp.UpdateGLScreen(); //Update Screen
if(WinApp.getFPS() != last_fps){
char buffer[128];
if(MaxFramerateON){
sprintf(buffer,"%s \n%5.2f / %5.2f FPS \nPress F1: MaxFramerate ON/OFF",
title.c_str(),WinApp.getFPS(),framerate);
}else{
sprintf(buffer,"%s \n%5.2f FPS \nPress F1: MaxFramerate ON/OFF",
title.c_str(),WinApp.getFPS());
}
std::string str (buffer,128);
Rect infoSize = getStringSize(sprInfo,str.c_str());
sprInfo.clearTexts();
sprInfo.addText(0,0,infoSize.width,infoSize.height,str.c_str());
last_fps = WinApp.getFPS();
}
}
WinApp.ShutdownGLWindow(); //Shutdown Window
return 0;
}
|