Compare commits

...

2 Commits

Author SHA1 Message Date
Alexandre 5a2f68c741 index error swept away 2h 2025-02-20 14:45:09 +01:00
Alexandre 90e0fd244d working (?) textures 2025-02-20 12:25:43 +01:00
31 changed files with 8149 additions and 74 deletions

View File

@ -17,6 +17,9 @@
"entities.h": "c", "entities.h": "c",
"menus.h": "c", "menus.h": "c",
"structure.h": "c", "structure.h": "c",
"limits.h": "c" "limits.h": "c",
"png.h": "c",
"stdlib.h": "c",
"stb_image.h": "c"
} }
} }

View File

@ -1,6 +1,6 @@
CC = gcc CC = gcc
FLAGS = -Wall -Wextra -g FLAGS = -Wall -Wextra -g
LFLAGS = -lm src/glad.c -ldl -lglfw -lcglm LFLAGS = -lm src/glad.c -ldl -lglfw -lcglm -lpng -lSOIL
all: bin/back all: bin/back

BIN
bin/back

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
res/container.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 KiB

BIN
res/question_block.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

BIN
res/white.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

@ -9,7 +9,6 @@
#include <time.h> #include <time.h>
#include "hash.h" #include "hash.h"
#include "structure.h"
#include "base.h" #include "base.h"
int ln_baseN(int n, int b) { int ln_baseN(int n, int b) {

View File

@ -9,7 +9,6 @@
#include <time.h> #include <time.h>
#include "hash.h" #include "hash.h"
#include "structure.h"
#include "base.h" #include "base.h"
#include "move.h" #include "move.h"
#include "entities.h" #include "entities.h"

View File

@ -12,7 +12,6 @@
#include <cglm/cglm.h> #include <cglm/cglm.h>
#include "hash.h" #include "hash.h"
#include "structure.h"
#include "base.h" #include "base.h"
#include "move.h" #include "move.h"
#include "menus.h" #include "menus.h"
@ -27,12 +26,13 @@ int MAX_SIZE = 8192 ;
int* drawOrder ; int* drawOrder ;
GLint loc_scale; int loc_scale;
GLint loc_model; int loc_model;
GLint loc_view; int loc_view;
GLint loc_proj; int loc_proj;
GLint loc_frag; int loc_frag;
int loc_tex;
void init_draworder() { void init_draworder() {
drawOrder = malloc(sizeof(int)*6) ; drawOrder = malloc(sizeof(int)*6) ;
@ -79,51 +79,51 @@ double right = 1.0 ;
mat4 model, view, projection; mat4 model, view, projection;
mat4 scale; mat4 scale;
float vertices[108]; float vertices[180];
// -x ; +x ; -y ; +y ; -z ; +z // // -x ; +x ; -y ; +y ; -z ; +z //
void init_vertices() { void init_vertices() {
vertices[0] = -0.5f; vertices[1] = -0.5f; vertices[2] = -0.5f; vertices[0] = -0.5f; vertices[1] = -0.5f; vertices[2] = -0.5f; vertices[3] = 0.0; vertices[4] = 1.0;
vertices[3] = -0.5f; vertices[4] = 0.5f; vertices[5] = -0.5f; vertices[5] = -0.5f; vertices[6] = 0.5f; vertices[7] = -0.5f; vertices[8] = 0.0; vertices[9] = 0.0;
vertices[6] = -0.5f; vertices[7] = 0.5f; vertices[8] = 0.5f; vertices[10] = -0.5f; vertices[11] = 0.5f; vertices[12] = 0.5f; vertices[13] = 1.0; vertices[14] = 0.0;
vertices[9] = -0.5f; vertices[10] = -0.5f; vertices[11] = -0.5f; vertices[15] = -0.5f; vertices[16] = -0.5f; vertices[17] = -0.5f; vertices[18] = 0.0; vertices[19] = 1.0;
vertices[12] = -0.5f; vertices[13] = 0.5f; vertices[14] = 0.5f; vertices[20] = -0.5f; vertices[21] = 0.5f; vertices[22] = 0.5f; vertices[23] = 1.0; vertices[24] = 0.0;
vertices[15] = -0.5f; vertices[16] = -0.5f; vertices[17] = 0.5f; vertices[25] = -0.5f; vertices[26] = -0.5f; vertices[27] = 0.5f; vertices[28] = 1.0; vertices[29] = 1.0;
vertices[18] = 0.5f; vertices[19] = -0.5f; vertices[20] = -0.5f; vertices[30] = 0.5f; vertices[31] = -0.5f; vertices[32] = -0.5f; vertices[33] = 1.0; vertices[34] = 1.0;
vertices[21] = 0.5f; vertices[22] = 0.5f; vertices[23] = 0.5f; vertices[35] = 0.5f; vertices[36] = 0.5f; vertices[37] = 0.5f; vertices[38] = 0.0; vertices[39] = 0.0;
vertices[24] = 0.5f; vertices[25] = 0.5f; vertices[26] = -0.5f; vertices[40] = 0.5f; vertices[41] = 0.5f; vertices[42] = -0.5f; vertices[43] = 1.0; vertices[44] = 0.0;
vertices[27] = 0.5f; vertices[28] = -0.5f; vertices[29] = -0.5f; vertices[45] = 0.5f; vertices[46] = -0.5f; vertices[47] = -0.5f; vertices[48] = 1.0; vertices[49] = 1.0;
vertices[30] = 0.5f; vertices[31] = -0.5f; vertices[32] = 0.5f; vertices[50] = 0.5f; vertices[51] = -0.5f; vertices[52] = 0.5f; vertices[53] = 0.0; vertices[54] = 1.0;
vertices[33] = 0.5f; vertices[34] = 0.5f; vertices[35] = 0.5f; vertices[55] = 0.5f; vertices[56] = 0.5f; vertices[57] = 0.5f; vertices[58] = 0.0; vertices[59] = 0.0;
vertices[36] = -0.5f; vertices[37] = -0.5f; vertices[38] = -0.5f; vertices[60] = -0.5f; vertices[61] = -0.5f; vertices[62] = -0.5f; vertices[63] = 0.0; vertices[64] = 1.0;
vertices[39] = 0.5f; vertices[40] = -0.5f; vertices[41] = 0.5f; vertices[65] = 0.5f; vertices[66] = -0.5f; vertices[67] = 0.5f; vertices[68] = 1.0; vertices[69] = 0.0;
vertices[42] = 0.5f; vertices[43] = -0.5f; vertices[44] = -0.5f; vertices[70] = 0.5f; vertices[71] = -0.5f; vertices[72] = -0.5f; vertices[73] = 0.0; vertices[74] = 0.0;
vertices[45] = -0.5f; vertices[46] = -0.5f; vertices[47] = -0.5f; vertices[75] = -0.5f; vertices[76] = -0.5f; vertices[77] = -0.5f; vertices[78] = 0.0; vertices[79] = 1.0;
vertices[48] = -0.5f; vertices[49] = -0.5f; vertices[50] = 0.5f; vertices[80] = -0.5f; vertices[81] = -0.5f; vertices[82] = 0.5f; vertices[83] = 1.0; vertices[84] = 1.0;
vertices[51] = 0.5f; vertices[52] = -0.5f; vertices[53] = 0.5f; vertices[85] = 0.5f; vertices[86] = -0.5f; vertices[87] = 0.5f; vertices[88] = 1.0; vertices[89] = 0.0;
vertices[54] = -0.5f; vertices[55] = 0.5f; vertices[56] = -0.5f; vertices[90] = -0.5f; vertices[91] = 0.5f; vertices[92] = -0.5f; vertices[93] = 1.0; vertices[94] = 1.0;
vertices[57] = 0.5f; vertices[58] = 0.5f; vertices[59] = -0.5f; vertices[95] = 0.5f; vertices[96] = 0.5f; vertices[97] = -0.5f; vertices[98] = 1.0; vertices[99] = 0.0;
vertices[60] = 0.5f; vertices[61] = 0.5f; vertices[62] = 0.5f; vertices[100] = 0.5f; vertices[101] = 0.5f; vertices[102] = 0.5f; vertices[103] = 0.0; vertices[104] = 0.0;
vertices[63] = -0.5f; vertices[64] = 0.5f; vertices[65] = -0.5f; vertices[105] = -0.5f; vertices[106] = 0.5f; vertices[107] = -0.5f; vertices[108] = 1.0; vertices[109] = 1.0;
vertices[66] = 0.5f; vertices[67] = 0.5f; vertices[68] = 0.5f; vertices[110] = 0.5f; vertices[111] = 0.5f; vertices[112] = 0.5f; vertices[113] = 0.0; vertices[114] = 0.0;
vertices[69] = -0.5f; vertices[70] = 0.5f; vertices[71] = 0.5f; vertices[115] = -0.5f; vertices[116] = 0.5f; vertices[117] = 0.5f; vertices[118] = 0.0; vertices[119] = 1.0;
vertices[72] = -0.5f; vertices[73] = -0.5f; vertices[74] = -0.5f; vertices[120] = -0.5f; vertices[121] = -0.5f; vertices[122] = -0.5f; vertices[123] = 1.0; vertices[124] = 1.0;
vertices[75] = 0.5f; vertices[76] = -0.5f; vertices[77] = -0.5f; vertices[125] = 0.5f; vertices[126] = -0.5f; vertices[127] = -0.5f; vertices[128] = 0.0; vertices[129] = 1.0;
vertices[78] = 0.5f; vertices[79] = 0.5f; vertices[80] = -0.5f; vertices[130] = 0.5f; vertices[131] = 0.5f; vertices[132] = -0.5f; vertices[133] = 0.0; vertices[134] = 0.0;
vertices[81] = -0.5f; vertices[82] = -0.5f; vertices[83] = -0.5f; vertices[135] = -0.5f; vertices[136] = -0.5f; vertices[137] = -0.5f; vertices[138] = 1.0; vertices[139] = 1.0;
vertices[84] = 0.5f; vertices[85] = 0.5f; vertices[86] = -0.5f; vertices[140] = 0.5f; vertices[141] = 0.5f; vertices[142] = -0.5f; vertices[143] = 0.0; vertices[144] = 0.0;
vertices[87] = -0.5f; vertices[88] = 0.5f; vertices[89] = -0.5f; vertices[145] = -0.5f; vertices[146] = 0.5f; vertices[147] = -0.5f; vertices[148] = 1.0; vertices[149] = 0.0;
vertices[90] = -0.5f; vertices[91] = -0.5f; vertices[92] = 0.5f; vertices[150] = -0.5f; vertices[151] = -0.5f; vertices[152] = 0.5f; vertices[153] = 0.0; vertices[154] = 1.0;
vertices[93] = 0.5f; vertices[94] = 0.5f; vertices[95] = 0.5f; vertices[155] = 0.5f; vertices[156] = 0.5f; vertices[157] = 0.5f; vertices[158] = 1.0; vertices[159] = 0.0;
vertices[96] = 0.5f; vertices[97] = -0.5f; vertices[98] = 0.5f; vertices[160] = 0.5f; vertices[161] = -0.5f; vertices[162] = 0.5f; vertices[163] = 1.0; vertices[164] = 1.0;
vertices[99] = -0.5f; vertices[100] = -0.5f; vertices[101] = 0.5f; vertices[165] = -0.5f; vertices[166] = -0.5f; vertices[167] = 0.5f; vertices[168] = 0.0; vertices[169] = 1.0;
vertices[102] = -0.5f; vertices[103] = 0.5f; vertices[104] = 0.5f; vertices[170] = -0.5f; vertices[171] = 0.5f; vertices[172] = 0.5f; vertices[173] = 0.0; vertices[174] = 0.0;
vertices[105] = 0.5f; vertices[106] = 0.5f; vertices[107] = 0.5f; vertices[175] = 0.5f; vertices[176] = 0.5f; vertices[177] = 0.5f; vertices[178] = 1.0; vertices[179] = 0.0;
} }
void gl_renderCube(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO, cube_0* c, double offx, double offy, double offz) { void gl_renderCube(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO, cube_0* c, double offx, double offy, double offz) {
@ -144,6 +144,7 @@ void gl_renderCube(unsigned int shaderProgram, unsigned int fragmentShader, unsi
glUniform4f(loc_frag, c->red/255.0f, c->green/255.0f, c->blue/255.0f, 1.0f); glUniform4f(loc_frag, c->red/255.0f, c->green/255.0f, c->blue/255.0f, 1.0f);
glDrawArrays(GL_TRIANGLES, 0, 36); glDrawArrays(GL_TRIANGLES, 0, 36);
//glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
triCount += 12; triCount += 12;
} }
@ -162,6 +163,8 @@ bool is_visible(cube_0* cb, double offx, double offy, double offz) {
void gl_renderAll(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO, room* rtd, double offx, double offy, double offz) { void gl_renderAll(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO, room* rtd, double offx, double offy, double offz) {
if(rtd != NULL) { if(rtd != NULL) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textures[0]);
for(int k = 0; k < rtd->map_size; k++) { for(int k = 0; k < rtd->map_size; k++) {
if(is_visible(rtd->map[k], offx, offy, offz)) { if(is_visible(rtd->map[k], offx, offy, offz)) {
gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, rtd->map[k], offx, offy, offz); gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, rtd->map[k], offx, offy, offz);
@ -174,6 +177,8 @@ void gl_renderAll(unsigned int shaderProgram, unsigned int fragmentShader, unsig
} }
for(int k = 0; k < rtd->ent_len; k++) { for(int k = 0; k < rtd->ent_len; k++) {
if(is_visible(rtd->ents[k]->pos, offx, offy, offz)) { if(is_visible(rtd->ents[k]->pos, offx, offy, offz)) {
//printf("%d\n", rtd->ents[k]->tex);
glBindTexture(GL_TEXTURE_2D, textures[rtd->ents[k]->tex]);
gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, rtd->ents[k]->pos, offx, offy, offz); gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, rtd->ents[k]->pos, offx, offy, offz);
} }
} }
@ -226,13 +231,3 @@ void gl_drawData(unsigned int shaderProg) {
gl_printf(shaderProg, -0.95f, 0.8f, 0.04f, 0.004f, 255, 255, 0, "coins %d", coins); gl_printf(shaderProg, -0.95f, 0.8f, 0.04f, 0.004f, 255, 255, 0, "coins %d", coins);
//gl_drawInteger(shaderProg, player_hp, -0.95f, 0.9f, 0.05f, 255-player_hp/4, player_hp/4, 0, 0.005f, 1); //gl_drawInteger(shaderProg, player_hp, -0.95f, 0.9f, 0.05f, 255-player_hp/4, player_hp/4, 0, 0.005f, 1);
} }
void read_ppm(char* filename) {
FILE* ptr = fopen(filename, "r");
char c = fgetc(ptr);
while(c != EOF) {
printf("%c\n", c);
}
printf("\n");
fclose(ptr);
}

View File

@ -10,6 +10,4 @@ void init_vertices();
void gl_drawData(unsigned int shaderProg); void gl_drawData(unsigned int shaderProg);
void read_ppm(char* filename);
#endif #endif

View File

@ -7,11 +7,14 @@
#include <termios.h> #include <termios.h>
#include <limits.h> #include <limits.h>
#include <time.h> #include <time.h>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <cglm/cglm.h>
#include "hash.h" #include "hash.h"
#include "structure.h"
#include "base.h" #include "base.h"
#include "display.h" #include "display.h"
#include "menus.h"
#include "proj.h" #include "proj.h"
#include "entities.h" #include "entities.h"

View File

@ -10,7 +10,6 @@
#include <string.h> #include <string.h>
#include "hash.h" #include "hash.h"
#include "structure.h"
#include "base.h" #include "base.h"
#include "entities.h" #include "entities.h"
#include "generation.h" #include "generation.h"
@ -42,48 +41,56 @@ void init_ent_generator(int n) {
} }
hashtbl_entities[0].id = 0; hashtbl_entities[0].id = 0;
hashtbl_entities[0].tex = 0;
hashtbl_entities[0].name = "Coin"; // 0 = default hashtbl_entities[0].name = "Coin"; // 0 = default
hashtbl_entities[0].updatePos = &speen; hashtbl_entities[0].updatePos = &speen;
hashtbl_entities[0].onHit = &money; hashtbl_entities[0].onHit = &money;
hashtbl_entities[0].onDeath = NULL; hashtbl_entities[0].onDeath = NULL;
hashtbl_entities[1].id = 1; hashtbl_entities[1].id = 1;
hashtbl_entities[1].tex = 0;
hashtbl_entities[1].name = "ExplosiveStill"; hashtbl_entities[1].name = "ExplosiveStill";
hashtbl_entities[1].updatePos = &speen2; hashtbl_entities[1].updatePos = &speen2;
hashtbl_entities[1].onHit = &explodeOnHit; hashtbl_entities[1].onHit = &explodeOnHit;
hashtbl_entities[1].onDeath = NULL; hashtbl_entities[1].onDeath = NULL;
hashtbl_entities[2].id = 2; hashtbl_entities[2].id = 2;
hashtbl_entities[2].tex = 0;
hashtbl_entities[2].name = "ExplosiveSeek"; hashtbl_entities[2].name = "ExplosiveSeek";
hashtbl_entities[2].updatePos = &go_to_player; hashtbl_entities[2].updatePos = &go_to_player;
hashtbl_entities[2].onHit = &explodeOnHit; hashtbl_entities[2].onHit = &explodeOnHit;
hashtbl_entities[2].onDeath = NULL; hashtbl_entities[2].onDeath = NULL;
hashtbl_entities[3].id = 3; hashtbl_entities[3].id = 3;
hashtbl_entities[3].tex = 0;
hashtbl_entities[3].name = "ExplosiveShoot"; hashtbl_entities[3].name = "ExplosiveShoot";
hashtbl_entities[3].updatePos = &speen3; hashtbl_entities[3].updatePos = &speen3;
hashtbl_entities[3].onHit = &explodeOnHit; hashtbl_entities[3].onHit = &explodeOnHit;
hashtbl_entities[3].onDeath = NULL; hashtbl_entities[3].onDeath = NULL;
hashtbl_entities[4].id = 4; hashtbl_entities[4].id = 4;
hashtbl_entities[4].tex = 0;
hashtbl_entities[4].name = "SinePlatform"; hashtbl_entities[4].name = "SinePlatform";
hashtbl_entities[4].updatePos = &moving_xyz; hashtbl_entities[4].updatePos = &moving_xyz;
hashtbl_entities[4].onHit = &translatePlayer; hashtbl_entities[4].onHit = &translatePlayer;
hashtbl_entities[4].onDeath = NULL; hashtbl_entities[4].onDeath = NULL;
hashtbl_entities[5].id = 5; hashtbl_entities[5].id = 5;
hashtbl_entities[5].tex = 0;
hashtbl_entities[5].name = "LinePlatform"; hashtbl_entities[5].name = "LinePlatform";
hashtbl_entities[5].updatePos = &moving_xyz_line; hashtbl_entities[5].updatePos = &moving_xyz_line;
hashtbl_entities[5].onHit = &translatePlayerLine; hashtbl_entities[5].onHit = &translatePlayerLine;
hashtbl_entities[5].onDeath = NULL; hashtbl_entities[5].onDeath = NULL;
hashtbl_entities[6].id = 6; hashtbl_entities[6].id = 6;
hashtbl_entities[6].tex = 1;
hashtbl_entities[6].name = "TextBox"; hashtbl_entities[6].name = "TextBox";
hashtbl_entities[6].updatePos = NULL; hashtbl_entities[6].updatePos = NULL;
hashtbl_entities[6].onHit = &pop_text; hashtbl_entities[6].onHit = &pop_text;
hashtbl_entities[6].onDeath = NULL; hashtbl_entities[6].onDeath = NULL;
hashtbl_entities[7].id = 7; hashtbl_entities[7].id = 7;
hashtbl_entities[7].tex = 0;
hashtbl_entities[7].name = "WarpBox"; hashtbl_entities[7].name = "WarpBox";
hashtbl_entities[7].updatePos = NULL; hashtbl_entities[7].updatePos = NULL;
hashtbl_entities[7].onHit = &pop_and_tp; hashtbl_entities[7].onHit = &pop_and_tp;
@ -132,6 +139,8 @@ void copy_room(room* src, room* dest, int chx, int chy) {
for(int k = 0; k < src->ent_len; k++) { for(int k = 0; k < src->ent_len; k++) {
dest->ents[k] = malloc(sizeof(entity)); dest->ents[k] = malloc(sizeof(entity));
dest->ents[k]->damage = src->ents[k]->damage; dest->ents[k]->damage = src->ents[k]->damage;
dest->ents[k]->tex = src->ents[k]->tex;
//printf("!! %d !!\n", dest->ents [k]->tex);
dest->ents[k]->hitpoints = malloc(sizeof(int)); dest->ents[k]->hitpoints = malloc(sizeof(int));
dest->ents[k]->metai1 = src->ents[k]->metai1; dest->ents[k]->metai1 = src->ents[k]->metai1;
dest->ents[k]->metai2 = src->ents[k]->metai2; dest->ents[k]->metai2 = src->ents[k]->metai2;
@ -200,6 +209,7 @@ void build_starting_chunk(int chx, int chy) {
for(int k = 0; k < 32; k++) { for(int k = 0; k < 32; k++) {
new->ents[k] = malloc(sizeof(entity)); new->ents[k] = malloc(sizeof(entity));
new->ents[k]->hitpoints = malloc(sizeof(int)); new->ents[k]->hitpoints = malloc(sizeof(int));
new->ents[k]->tex = 0;
new->ents[k]->pos = malloc(sizeof(cube_0)); new->ents[k]->pos = malloc(sizeof(cube_0));
}; };
new->ent_len = 1; new->ent_len = 1;
@ -347,6 +357,7 @@ void parse_one_room(int id, char* filename) {
pool[id].area->ents[k] = malloc(sizeof(entity)); pool[id].area->ents[k] = malloc(sizeof(entity));
pool[id].area->ents[k]->hitpoints = malloc(sizeof(int)); pool[id].area->ents[k]->hitpoints = malloc(sizeof(int));
pool[id].area->ents[k]->pos = malloc(sizeof(cube_0)); pool[id].area->ents[k]->pos = malloc(sizeof(cube_0));
pool[id].area->ents[k]->tex = 0;
} }
pool[id].area->ent_len = nent; pool[id].area->ent_len = nent;
pool[id].area->ent_memlen = nmemlen; pool[id].area->ent_memlen = nmemlen;
@ -416,8 +427,10 @@ void parse_one_room(int id, char* filename) {
if(entry == NULL) { if(entry == NULL) {
entry = get_entry(0); entry = get_entry(0);
} }
//printf(">>><>>>>><> %d\n", entry->tex);
fill_cube_0(pool[id].area->ents[k]->pos, cx, cy, cz, cw, ch, cd, chz, cvt, red, green, blue); fill_cube_0(pool[id].area->ents[k]->pos, cx, cy, cz, cw, ch, cd, chz, cvt, red, green, blue);
pool[id].area->ents[k]->damage = dmg; pool[id].area->ents[k]->damage = dmg;
pool[id].area->ents[k]->tex = entry->tex;
*(pool[id].area->ents[k]->hitpoints) = hp; *(pool[id].area->ents[k]->hitpoints) = hp;
pool[id].area->ents[k]->updatePos = entry->updatePos; pool[id].area->ents[k]->updatePos = entry->updatePos;
pool[id].area->ents[k]->onHit = entry->onHit ; pool[id].area->ents[k]->onHit = entry->onHit ;
@ -635,14 +648,17 @@ void generate_nearby_chunks(int render_dist) {
void free_pool() { void free_pool() {
for(int k0 = 0; k0 < pool_size; k0++) { for(int k0 = 0; k0 < pool_size; k0++) {
printf("%d/%d\n", 1+k0, pool_size); printf("%d/%d\n", 1+k0, pool_size); fflush(stdout);
for(int k = 0; k < pool[k0].area->map_size; k++) { for(int k = 0; k < pool[k0].area->map_size; k++) {
printf("%d-%d\n", k, pool[k0].area->map_size);
free(pool[k0].area->map[k]); free(pool[k0].area->map[k]);
} }
printf("...\n"); fflush(stdout);
for(int k = 0; k < pool[k0].area->tps_size; k++) { for(int k = 0; k < pool[k0].area->tps_size; k++) {
free(pool[k0].area->tps[k]->hitbox); free(pool[k0].area->tps[k]->hitbox);
free(pool[k0].area->tps[k]); free(pool[k0].area->tps[k]);
} }
printf("...\n"); fflush(stdout);
for(int k = 0; k < pool[k0].area->ent_memlen; k++) { for(int k = 0; k < pool[k0].area->ent_memlen; k++) {
if(pool[k0].area->ents[k]->metai3 == -727) { // 6 and 7 // if(pool[k0].area->ents[k]->metai3 == -727) { // 6 and 7 //
//free(pool[k0].area->ents[k]->metach1); //free(pool[k0].area->ents[k]->metach1);
@ -655,6 +671,7 @@ void free_pool() {
free(pool[k0].area->ents[k]->pos); free(pool[k0].area->ents[k]->pos);
free(pool[k0].area->ents[k]); free(pool[k0].area->ents[k]);
} }
printf("...\n"); fflush(stdout);
free(pool[k0].area->ents); free(pool[k0].area->ents);
free(pool[k0].area->tps); free(pool[k0].area->tps);
free(pool[k0].area->map); free(pool[k0].area->map);

View File

@ -33,6 +33,8 @@ typedef struct fct_entry {
double metad9; double metad9;
char* metach1; char* metach1;
char* metach2; char* metach2;
int tex;
} fct_entry ; } fct_entry ;
extern int build_text_box(char* msg, int red, int green, int blue); extern int build_text_box(char* msg, int red, int green, int blue);

View File

@ -8,7 +8,6 @@
#include <limits.h> #include <limits.h>
#include <time.h> #include <time.h>
#include "structure.h"
#include "hash.h" #include "hash.h"
// ------------------------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------------------------- //

View File

@ -4,6 +4,7 @@
#ifndef HASH_H #ifndef HASH_H
#define HASH_H #define HASH_H
#include "structure.h" #include "structure.h"
#include <stdbool.h> #include <stdbool.h>

View File

@ -10,8 +10,12 @@
#include <glad/glad.h> #include <glad/glad.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#ifndef STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#endif
#include "hash.h" #include "hash.h"
#include "structure.h"
#include "base.h" #include "base.h"
#include "move.h" #include "move.h"
#include "menus.h" #include "menus.h"
@ -33,6 +37,8 @@ double jPress = false;
double gPress = false; double gPress = false;
double rPress = false; double rPress = false;
unsigned int textures[16];
void reset_everything(GLFWwindow *window, int count, char* folder) { void reset_everything(GLFWwindow *window, int count, char* folder) {
/*hashtbl_free(visited); /*hashtbl_free(visited);
free_proj(); free_proj();
@ -105,6 +111,8 @@ void reset_everything(GLFWwindow *window, int count, char* folder) {
interface_set(-1); interface_set(-1);
generate_nearby_chunks(1); generate_nearby_chunks(1);
printf("-------------------------------- Done 5 --------------------------------\n");
} }
void processInput(GLFWwindow *window, float dtime) { void processInput(GLFWwindow *window, float dtime) {
@ -248,26 +256,32 @@ void processInput(GLFWwindow *window, float dtime) {
//printf("-----\n"); //printf("-----\n");
switchRoom = false; switchRoom = false;
reset_everything(window, newRoomCount, newRoomName); reset_everything(window, newRoomCount, newRoomName);
free(newRoomName); //free(newRoomName);
} }
} }
const char *vertexShaderSource = "#version 330 core\n" const char *vertexShaderSource = "#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n" "layout (location = 0) in vec3 aPos;\n"
"layout (location = 1) in vec2 aTex;\n"
"uniform mat4 scale;\n" "uniform mat4 scale;\n"
"uniform mat4 model;\n" "uniform mat4 model;\n"
"uniform mat4 view;\n" "uniform mat4 view;\n"
"uniform mat4 projection;\n" "uniform mat4 projection;\n"
"out vec2 texCoord;\n"
"void main() {\n" "void main() {\n"
" gl_Position = projection * view * model * scale * vec4(aPos, 1.0);\n" " gl_Position = projection * view * model * scale * vec4(aPos, 1.0);\n"
" texCoord = aTex;\n"
"}\0"; "}\0";
// Fragment Shader Source // Fragment Shader Source
const char *fragmentShaderSource = "#version 330 core\n" const char *fragmentShaderSource = "#version 330 core\n"
"uniform vec4 u_color;\n" "uniform vec4 u_color;\n"
"out vec4 FragColor;\n" "out vec4 FragColor;\n"
"in vec2 texCoord;\n"
"uniform sampler2D tex0;\n"
"void main() {\n" "void main() {\n"
" FragColor = u_color;\n" // " FragColor = u_color;\n"
" FragColor = texture(tex0, texCoord) * u_color;\n"
"}\0"; "}\0";
const char *vertexShaderSourceR = "#version 330 core\n" const char *vertexShaderSourceR = "#version 330 core\n"
@ -285,6 +299,34 @@ const char *fragmentShaderSourceR = "#version 330 core\n"
" FragColor = u_color2;\n" " FragColor = u_color2;\n"
"}\0"; "}\0";
typedef enum file_extension {PNG, JPG, JPEG} file_extension;
void generate_texture(int id, char* filename, file_extension ext) {
int widthImg, heightImg, numColCh;
//unsigned char* bytes = stbi_load("res/container.jpg", &widthImg, &heightImg, &numColCh, 0);
unsigned char* bytes = stbi_load(filename, &widthImg, &heightImg, &numColCh, 0);
if(bytes == 0) {fprintf(stderr, "ERROR : cannot load texture\n"); exit(1);}
glGenTextures(1, &textures[id]);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textures[id]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
if(ext == JPG || ext == JPEG) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, widthImg, heightImg, 0, GL_RGB, GL_UNSIGNED_BYTE, bytes);
glGenerateMipmap(GL_TEXTURE_2D);
} else if(ext == PNG) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, widthImg, heightImg, 0, GL_RGBA, GL_UNSIGNED_BYTE, bytes);
glGenerateMipmap(GL_TEXTURE_2D);
}
stbi_image_free(bytes);
glBindTexture(GL_TEXTURE_2D, 0);
}
int main_alt() { int main_alt() {
// glfw: initialize and configure // glfw: initialize and configure
// ------------------------------ // ------------------------------
@ -380,9 +422,22 @@ int main_alt() {
glBindBuffer(GL_ARRAY_BUFFER, VBO); glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); // position attribute
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
// texture coord attribute
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3*sizeof(float)));
glEnableVertexAttribArray(1);
printf("-----------------------------------------------------------------------------------------------\n"); fflush(stdout);
//generate_texture(0, "res/container.jpg", "jpg");
generate_texture(0, "res/white.png", PNG);
generate_texture(1, "res/question_block.png", PNG);
printf("-----------------------------------------------------------------------------------------------\n"); fflush(stdout);
// ---------------------------------------------------------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------------------------------------------------------- //
// ---------------------------------------------------------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------------------------------------------------------- //
@ -460,6 +515,10 @@ int main_alt() {
clock_t finish = clock(); clock_t finish = clock();
clock_t origin = clock(); clock_t origin = clock();
loc_tex = glGetUniformLocation(shaderProgram, "tex0");
glUseProgram(shaderProgram);
glUniform1i(loc_tex, 0);
while(!glfwWindowShouldClose(window) && player_hp > 0) { while(!glfwWindowShouldClose(window) && player_hp > 0) {
// input // input
// ----- // -----
@ -471,8 +530,9 @@ int main_alt() {
generate_nearby_chunks(1); generate_nearby_chunks(1);
fflush(stdout); fflush(stdout);
// draw the map
glUseProgram(shaderProgram); glUseProgram(shaderProgram);
// draw the map
glBindVertexArray(VAO); glBindVertexArray(VAO);
gl_initRender(shaderProgram, shaderProgram, VAO, VBO); gl_initRender(shaderProgram, shaderProgram, VAO, VBO);
@ -528,6 +588,8 @@ int main_alt() {
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
glDeleteVertexArrays(1, &VAO); glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO); glDeleteBuffers(1, &VBO);
glDeleteTextures(1, &textures[0]);
glDeleteTextures(1, &textures[1]);
glDeleteProgram(shaderProgram); glDeleteProgram(shaderProgram);
// glfw: terminate, clearing all previously allocated GLFW resources. // glfw: terminate, clearing all previously allocated GLFW resources.
@ -544,6 +606,6 @@ int main(int argc, char** argv) {
newRoomCount = 7; newRoomCount = 7;
switchRoom = false; switchRoom = false;
newRoomName = "templates/"; newRoomName = "templates/";
//read_ppm("res/smb-2.ppm"); //read_png_file("res/question_block.png");
return main_alt(); return main_alt();
} }

View File

@ -14,7 +14,6 @@
#include <cglm/cglm.h> #include <cglm/cglm.h>
#include "hash.h" #include "hash.h"
#include "structure.h"
#include "base.h" #include "base.h"
#include "entities.h" #include "entities.h"
#include "menus.h" #include "menus.h"

View File

@ -9,7 +9,6 @@
#include <time.h> #include <time.h>
#include "hash.h" #include "hash.h"
#include "structure.h"
#include "base.h" #include "base.h"
#include "entities.h" #include "entities.h"
#include "proj.h" #include "proj.h"

View File

@ -8,7 +8,6 @@
#include <limits.h> #include <limits.h>
#include <time.h> #include <time.h>
#include "structure.h"
#include "hash.h" #include "hash.h"
#include "base.h" #include "base.h"
#include "move.h" #include "move.h"

7988
src/stb_image.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -59,6 +59,8 @@ typedef struct entity {
char* metach1; char* metach1;
char* metach2; char* metach2;
int tex;
int damage; int damage;
int* hitpoints; int* hitpoints;
} entity; } entity;
@ -148,7 +150,7 @@ extern double creative_speed;
extern double min_dist; extern double min_dist;
// ---------------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------------- //
extern float vertices[108]; extern float vertices[180];
extern float rectDefault[18]; extern float rectDefault[18];
extern int triCount; extern int triCount;
@ -170,4 +172,14 @@ extern char* newRoomName;
extern int newRoomCount; extern int newRoomCount;
extern bool switchRoom; extern bool switchRoom;
extern int loc_scale;
extern int loc_model;
extern int loc_view;
extern int loc_proj;
extern int loc_frag;
extern int loc_tex;
extern unsigned int textures[16];
#endif #endif

View File

@ -11,7 +11,7 @@ Teleporters :
[-5.0, 1.0, 9.0, 10.0, 2.0, 1.0, 0.0, 0.0, 0, 0, 255; 0, 1] [-5.0, 1.0, 9.0, 10.0, 2.0, 1.0, 0.0, 0.0, 0, 0, 255; 0, 1]
Entities : Entities :
[-1.0, 1.0, -1.0, 2.0, 2.0, 2.0, 0.0, 0.0, 0, 0, 0, 1, 0, 6, hey look a text box, 200, 200, 200] [-1.0, 1.0, -1.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 255, 1, 0, 6, hey look a text box, 200, 200, 200]
Weight : Weight :
50 50