aboutsummaryrefslogtreecommitdiff
path: root/test/06TextureFont/main.cpp
blob: 1512ad612ca01771c0d6ee1763112ff0a85debf7 (plain)
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
#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;
Shader* shader = nullptr;
TextureFont* font = nullptr;
Text text = Text(
Encode::UTF8,	
u8R"(
this is a test
you know what i mean
texture font test ^_^
)"
);

float dt;
void onLoad()
{
	const char* font_shader = R"(
#VERTEX_SHADER

Vertex vert(Vertex v)
{
    return v;
}

#END_VERTEX_SHADER

#FRAGMENT_SHADER

Color frag(Color col, Texture tex, Vertex v)
{
	return col * texel(tex, v.uv);
}

#END_FRAGMENT_SHADER
)";
	shader = Shader::createShader(font_shader);
	Filesystem* fs = Filesystem::get();
	fs->mount("../Debug");
	Buffer buffer;
	fs->read("font2.png", &buffer);
	Bitmap* bitmap = Bitmap::createBitmap(buffer.data, buffer.size);
	const char* charset = u8R"( !"#$£€%&'()*+,-./0123456789;:<=>?`'^@abcdefghijklmnopqrstuvwxyz|~[\]_)";
	font = TextureFont::createTextureFont(bitmap, Text(Encode::UTF8, charset, strlen(charset)), Color(255, 0, 0, 255), 16);
}

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()
{
	gl.setClearColor(255, 255, 255, 255);
	glClear(GL_COLOR_BUFFER_BIT);
	glColor4f(1, 1, 1, 1);
	shader->use();
	font->print(text, 10, 10, 16);
	shader->unuse();
}

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;
}