-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.cpp
More file actions
112 lines (86 loc) · 2.63 KB
/
Copy pathui.cpp
File metadata and controls
112 lines (86 loc) · 2.63 KB
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
111
112
#define STB_IMAGE_IMPLEMENTATION
#include "game.h"
#include "stb/stb_image.h"
#include <iostream>
Game* Game::_this = nullptr;
void Game::resize_callback(GLFWwindow* window, int width, int height) {
glViewport(0, 0, width, height);
_this->Render();
}
void Game::key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
if (action == GLFW_PRESS) {
_this->pressedKey = key;
}
if (key == GLFW_KEY_ESCAPE) {
glfwSetWindowShouldClose(window, 1);
}
}
static char const* textFileNames[TEXTURE_LAST] = {
"data/background.png",
"data/field.png",
"data/slot.png",
"data/numbers.png",
"data/lightning.png",
"data/D-lightning.png",
"data/dice1.png",
"data/dice2.png",
"data/dice3.png",
"data/dice4.png",
"data/dice5.png",
"data/dice6.png",
};
GLFWwindow* Field::CreateWindow() {
// Create a windowed mode window and its OpenGL context
auto window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Knucklebones", NULL, NULL);
if (window) {
// Make the window's context current
glfwMakeContextCurrent(window);
// tell OpenGL where to render
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
// have minimal textures for the first render
StartupTextures();
}
return window;
}
void TexDic::StartupTextures() {
// generate names
glGenTextures(COUNT_TEX_NAMES, textureNames);
// load what's needed on start
LoadTexture(E_BACKGROUND, textFileNames[E_BACKGROUND]);
LoadTexture(E_FIELD, textFileNames[E_FIELD]);
}
void TexDic::LoadMainBlockTex() {
// load for each
for (int i = E_SLOT; i < TEXTURE_LAST; i++) {
LoadTexture(i, textFileNames[i]);
}
// clean up
glBindTexture(GL_TEXTURE_2D, 0);
}
bool TexDic::LoadTexture(int idxTx, char const* filename) {
int widthImg, heightImg, numColCh;
unsigned char* bytes = stbi_load(filename, &widthImg, &heightImg, &numColCh, 0);
if (!bytes) {
std::cout << "Not found texture file: " << filename << std::endl;
return false;
}
glBindTexture(GL_TEXTURE_2D, textureNames[idxTx]);
// modulation
glTexEnvf(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
// filtration
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// wrapping
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, widthImg, heightImg, 0, GL_RGBA, GL_UNSIGNED_BYTE, bytes);
stbi_image_free(bytes);
return true;
}
void TexDic::EnableTransparancy() {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
}
void TexDic::PrepareShaders() {
}