-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathn_rendering.cpp
138 lines (117 loc) · 4.74 KB
/
n_rendering.cpp
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* Created by MajesticWaffle on 2/10/22.
* Copyright (c) 2022 Thicc Industries. All rights reserved.
* This software is under the: Thicc-Industries-Do-What-You-Want-I-Dont-Care License.
*/
#include "nails.h"
void rendering_draw_chunks(){
glColor1c(COLOR_BLACK);
glBegin(GL_QUADS);{
glVertex2i(300, 0);
glVertex2i(480, 0);
glVertex2i(480, 360);
glVertex2i(300, 360);
}
glEnd();
glColor1c(COLOR_WHITE);
}
void rendering_draw_frames(){
glBegin(GL_QUADS);{
glVertex2i(0, 10);
glVertex2i(300, 10);
glVertex2i(300, 14);
glVertex2i(0, 14);
glVertex2i(0, 14);
glVertex2i(4, 14);
glVertex2i(4, 360);
glVertex2i(0, 360);
glVertex2i(0, 356);
glVertex2i(300, 356);
glVertex2i(300, 360);
glVertex2i(0, 360);
glVertex2i(296, 14);
glVertex2i(300, 14);
glVertex2i(300, 360);
glVertex2i(296, 360);
}
glEnd();
glColor1c(COLOR_WHITE);
glBegin(GL_QUADS);{
glVertex2i(310, 10);
glVertex2i(462, 10);
glVertex2i(462, 274);
glVertex2i(310, 274);
}
glColor1c(COLOR_BLACK);
glBegin(GL_QUADS);{
glVertex2i(314, 14);
glVertex2i(458, 14);
glVertex2i(458, 270);
glVertex2i(314, 270);
}
glEnd();
glColor1c(COLOR_WHITE);
}
void rendering_draw_tiles(uint selected_tile){
selected_tile--;
uint tile_count = g_map -> tile_count;
uint tile_size = g_map -> tilemap -> tile_size;
double tile_dx = g_map -> tilemap -> atlas_uvs.x;
double tile_dy = g_map -> tilemap -> atlas_uvs.y;
//TODO: Please figure this out
Texture* fuck = texture_generate(g_map -> tilemap -> image, TEXTURE_MULTIPLE, 16);
int x = 314;
int y = 14;
uint tiles_x = 9;
glEnable(GL_TEXTURE_2D);
texture_bind(fuck, 0);
double uv_x1, uv_y1, uv_x2, uv_y2;
for(uint i = 1; i < tile_count; ++i){
//Two different textures means chunk must be animated.
int anim_frame = 0;
if(g_map -> tile_properties[i].options & TILE_ANIMATED){
int anim_tick = g_time -> tick % TIME_TPS;
int anim_rate_d = TIME_TPS / 4;
anim_frame += anim_tick / anim_rate_d;
}
uv_x1 = tile_dx * ((g_map -> tile_properties[i].atlas_index + anim_frame * (fuck -> width / fuck -> tile_size)) % (fuck -> width / fuck -> tile_size));
uv_x2 = uv_x1 + tile_dx;
uv_y1 = tile_dy * ((g_map -> tile_properties[i].atlas_index + anim_frame * (fuck -> width / fuck -> tile_size)) / (fuck -> width / fuck -> tile_size));
uv_y2 = uv_y1 + tile_dx;
//Swap for flips
if(g_map -> tile_properties[i].options & TILE_TEX_FLIP_X){
uv_x2 += uv_x1;
uv_x1 = uv_x2 - uv_x1;
uv_x2 -= uv_x1;
}
if(g_map -> tile_properties[i].options & TILE_TEX_FLIP_Y){
uv_y2 += uv_y1;
uv_y1 = uv_y2 - uv_y1;
uv_y2 -= uv_y1;
}
glBegin(GL_QUADS);{
glTexCoord2d(uv_x1, uv_y1); glVertex2i(x + (((i - 1) % tiles_x) * tile_size), y + (((i - 1) / tiles_x) * tile_size));
glTexCoord2d(uv_x2, uv_y1); glVertex2i(x + (((i - 1) % tiles_x) * tile_size) + tile_size, y + (((i - 1) / tiles_x) * tile_size));
glTexCoord2d(uv_x2, uv_y2); glVertex2i(x + (((i - 1) % tiles_x) * tile_size) + tile_size, y + (((i - 1) / tiles_x) * tile_size) + tile_size);
glTexCoord2d(uv_x1, uv_y2); glVertex2i(x + (((i - 1) % tiles_x) * tile_size), y + (((i - 1) / tiles_x) * tile_size) + tile_size);
}
glEnd();
}
glDisable(GL_TEXTURE_2D);
texture_destroy(fuck);
glColor1c(COLOR_RED);
glLineWidth(2);
glBegin(GL_LINES);
{
glVertex2i(x + (selected_tile % tiles_x) * tile_size, y + (selected_tile / tiles_x) * tile_size);
glVertex2i(x + (selected_tile % tiles_x) * tile_size + tile_size, y + (selected_tile / tiles_x) * tile_size);
glVertex2i(x + (selected_tile % tiles_x) * tile_size + tile_size, y + (selected_tile / tiles_x) * tile_size);
glVertex2i(x + (selected_tile % tiles_x) * tile_size + tile_size, y + (selected_tile / tiles_x) * tile_size + tile_size);
glVertex2i(x + (selected_tile % tiles_x) * tile_size + tile_size, y + (selected_tile / tiles_x) * tile_size + tile_size);
glVertex2i(x + (selected_tile % tiles_x) * tile_size, y + (selected_tile / tiles_x) * tile_size + tile_size);
glVertex2i(x + (selected_tile % tiles_x) * tile_size, y + (selected_tile / tiles_x) * tile_size + tile_size);
glVertex2i(x + (selected_tile % tiles_x) * tile_size, y + (selected_tile / tiles_x) * tile_size);
}
glEnd();
glColor1c(COLOR_WHITE);
}