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
|
#include <iostream>
#include "jin.h"
using namespace jin::core;
using namespace jin::graphics;
using namespace jin::input;
using namespace jin::audio;
using namespace jin::filesystem;
Font* font = nullptr;
Canvas* canvas;
FontData* data = nullptr;
JSLProgram* shader = nullptr;
float dt;
void onLoad()
{
const char* program = R"(
uniform float dt;
Color effect(Color col, Texture tex, vec2 uv, vec2 screen)
{
float a = Texel(tex, uv).a;
return Color(col.rgb, a/5);
}
)";
shader = JSLProgram::createJSLProgram(program);
Filesystem* fs = Filesystem::get();
fs->mount("../Debug");
Buffer buffer;
fs->read("simhei.ttf", &buffer);
data = FontData::createFontData((const unsigned char*)buffer.data, buffer.size);
font = Font::createFont(data, 14);
//canvas = Canvas::createCanvas(100, 100);
}
void onEvent(jin::input::Event* e)
{
static Game* game = Game::get();
if (e->type == EventType::QUIT)
game->stop();
}
void onUpdate(int ms)
{
dt += ms / (float)1000;
}
void onDraw()
{
glColor4f(32 / 255.f, 32 / 255.f, 32 / 255.f, 1);
rect(FILL, 0, 0, 500, 500);
glColor4f(1, 1, 1, 1);
shader->use();
shader->sendFloat("dt", dt);
//Canvas::bind(canvas);
if (font != nullptr)
{
glColor4f(1, 1, 1, 1);
font->print(u8"Hello,你好\n啊 world!", 10, 10);
//font->print(u8"Привет мир!", 10, 10 + 15 * 1);
//font->print(u8"こんにちは世界!", 10, 10 + 15 * 2);
//font->print(u8"你好世界!", 10, 10 + 15*3);
glColor4f(1, 1, 1, 1);
}
shader->unuse();
//Canvas::unbind();
//canvas->draw(0, 0, 2, 2, 0);
}
int main(int argc, char* argv[])
{
Game* game = Game::get();
Game::Setting setting;
setting.loader = onLoad;
setting.eventHandler = onEvent;
setting.updater = onUpdate;
setting.drawer = onDraw;
game->init(&setting);
Window* wnd = Window::get();
Window::Setting wndSetting;
wndSetting.width = 600;
wndSetting.height = 512;
wndSetting.title = "Jin v0.1.1";
wndSetting.fps = 60;
wndSetting.vsync = false;
wndSetting.fullscreen = false;
wndSetting.resizable = false;
wnd->init(&wndSetting);
game->run();
game->quit();
wnd->quit();
return 0;
}
|