Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 43 additions & 11 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1875,16 +1875,30 @@ void render_item(Attrib *attrib) {
glUniform3f(attrib->camera, 0, 0, 5);
glUniform1i(attrib->sampler, 0);
glUniform1f(attrib->timer, time_of_day());
int w = hotbar_items[g->item_index];
if (is_plant(w)) {
GLuint buffer = gen_plant_buffer(0, 0, 0, 0.5, w);
draw_plant(attrib, buffer);
del_buffer(buffer);
}
else {
GLuint buffer = gen_cube_buffer(0, 0, 0, 0.5, w);
draw_cube(attrib, buffer);
del_buffer(buffer);

for (int i = 0; i < 9; ++i) {
if (g->item_index + i >= hotbar_item_count) {
break;
}

glUniformMatrix4fv(attrib->matrix, 1, GL_FALSE, matrix);

int w = hotbar_items[g->item_index + i];
if (is_plant(w)) {
GLuint buffer = gen_plant_buffer(0, 0, 0, 0.5, w);
draw_plant(attrib, buffer);
del_buffer(buffer);
} else {
GLuint buffer = gen_cube_buffer(0, 0, 0, 0.5, w);
draw_cube(attrib, buffer);
del_buffer(buffer);
}

if (!i) {
set_matrix_item(matrix, g->width, g->height, g->scale);
}

matrix[13] += 0.2126;
}
}

Expand All @@ -1904,6 +1918,23 @@ void render_text(
del_buffer(buffer);
}

void render_item_count(Attrib *attrib, float ts) {
float ty = 15.0f;
for (int i = 0; i < 9; ++i) {
if (g->item_index + i >= hotbar_item_count) {
break;
}

char buf[4] = {0};
//snprintf(buf, sizeof(buf), "%d", 16); // TODO: finite inventory
float tx = g->width - 20.0f;
render_text(attrib, ALIGN_CENTER, tx, ty, ts, buf);

float ratio_to_hardcoded = (g->height / 768.0f);
ty += 81.705 * ratio_to_hardcoded;
}
}

void add_message(const char *text) {
printf("%s\n", text);
snprintf(
Expand Down Expand Up @@ -3397,6 +3428,7 @@ void render_scene() {
// RENDER 3-D SCENE //
render_sky(&sky_attrib, player, sky_buffer);
int face_count;
float ts = 12 * g->scale;
if (g->initialized) {
glClear(GL_DEPTH_BUFFER_BIT);
face_count = render_chunks(&block_attrib, player);
Expand All @@ -3418,14 +3450,14 @@ void render_scene() {
}
if (SHOW_ITEM && g->show_ui) {
render_item(&block_attrib);
render_item_count(&text_attrib, ts);
}
} else {
face_count = 0;
}

// RENDER TEXT //
char text_buffer[1024];
float ts = 12 * g->scale;
float tx = ts / 2;
float ty = g->height - ts;
if (g->show_info_text && g->show_ui && g->initialized) {
Expand Down
6 changes: 3 additions & 3 deletions src/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void set_matrix_item(float *matrix, int width, int height, int scale) {
float a[16];
float b[16];
float aspect = (float)width / height;
float size = 64 * scale;
float size = 32 * scale;
float box = height / size / 2;
float xoffset = 1 - size / width * 2;
float yoffset = 1 - size / height * 2;
Expand All @@ -250,9 +250,9 @@ void set_matrix_item(float *matrix, int width, int height, int scale) {
mat_multiply(a, b, a);
mat_rotate(b, 1, 0, 0, -PI / 10);
mat_multiply(a, b, a);
mat_ortho(b, -box * aspect, box * aspect, -box, box, -1, 1);
mat_ortho(b, -box * aspect, box * aspect, -box, box, -1, 2);
mat_multiply(a, b, a);
mat_translate(b, -xoffset, -yoffset, 0);
mat_translate(b, xoffset, -yoffset, 1.0f);
mat_multiply(a, b, a);
mat_identity(matrix);
mat_multiply(matrix, a, matrix);
Expand Down