diff --git a/.vscode/settings.json b/.vscode/settings.json index 3cc1f82..e4a00e7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -19,6 +19,7 @@ "structure.h": "c", "limits.h": "c", "png.h": "c", - "stdlib.h": "c" + "stdlib.h": "c", + "stb_image.h": "c" } } \ No newline at end of file diff --git a/bin/back b/bin/back index 87779af..2dacfd5 100755 Binary files a/bin/back and b/bin/back differ diff --git a/obj/base.o b/obj/base.o index 72ae6b1..0629df3 100644 Binary files a/obj/base.o and b/obj/base.o differ diff --git a/obj/bullets.o b/obj/bullets.o index b75594c..7c60029 100644 Binary files a/obj/bullets.o and b/obj/bullets.o differ diff --git a/obj/display.o b/obj/display.o index 6501623..59366c3 100644 Binary files a/obj/display.o and b/obj/display.o differ diff --git a/obj/entities.o b/obj/entities.o index fa9bf4e..eef36d8 100644 Binary files a/obj/entities.o and b/obj/entities.o differ diff --git a/obj/generation.o b/obj/generation.o index 448406f..ef6f895 100644 Binary files a/obj/generation.o and b/obj/generation.o differ diff --git a/obj/hash.o b/obj/hash.o index 7b75558..83f1c58 100644 Binary files a/obj/hash.o and b/obj/hash.o differ diff --git a/obj/main.o b/obj/main.o index 5c59786..c8d1ce8 100644 Binary files a/obj/main.o and b/obj/main.o differ diff --git a/obj/menus.o b/obj/menus.o index e17db29..5968bec 100644 Binary files a/obj/menus.o and b/obj/menus.o differ diff --git a/obj/move.o b/obj/move.o index 04b76b5..ef943b7 100644 Binary files a/obj/move.o and b/obj/move.o differ diff --git a/obj/proj.o b/obj/proj.o index ddfebdc..24e47ec 100644 Binary files a/obj/proj.o and b/obj/proj.o differ diff --git a/res/white.png b/res/white.png new file mode 100644 index 0000000..009abfc Binary files /dev/null and b/res/white.png differ diff --git a/src/base.c b/src/base.c index 58bdfe1..e6ba0ac 100644 --- a/src/base.c +++ b/src/base.c @@ -7,10 +7,8 @@ #include #include #include -#include #include "hash.h" -#include "structure.h" #include "base.h" int ln_baseN(int n, int b) { diff --git a/src/bullets.c b/src/bullets.c index d7dfbba..140b270 100644 --- a/src/bullets.c +++ b/src/bullets.c @@ -7,10 +7,8 @@ #include #include #include -#include #include "hash.h" -#include "structure.h" #include "base.h" #include "move.h" #include "entities.h" diff --git a/src/display.c b/src/display.c index c85f291..98bac14 100644 --- a/src/display.c +++ b/src/display.c @@ -10,10 +10,8 @@ #include #include #include -#include #include "hash.h" -#include "structure.h" #include "base.h" #include "move.h" #include "menus.h" @@ -28,13 +26,13 @@ int MAX_SIZE = 8192 ; int* drawOrder ; -GLint loc_scale; -GLint loc_model; -GLint loc_view; -GLint loc_proj; +int loc_scale; +int loc_model; +int loc_view; +int loc_proj; -GLint loc_frag; -GLint loc_tex; +int loc_frag; +int loc_tex; void init_draworder() { drawOrder = malloc(sizeof(int)*6) ; @@ -85,47 +83,47 @@ float vertices[180]; // -x ; +x ; -y ; +y ; -z ; +z // void init_vertices() { - vertices[0] = -0.5f; vertices[1] = -0.5f; vertices[2] = -0.5f; vertices[3] = 0.0; vertices[4] = 0.0; - vertices[5] = -0.5f; vertices[6] = 0.5f; vertices[7] = -0.5f; vertices[8] = 0.0; vertices[9] = 1.0; - vertices[10] = -0.5f; vertices[11] = 0.5f; vertices[12] = 0.5f; vertices[13] = 1.0; vertices[14] = 1.0; - vertices[15] = -0.5f; vertices[16] = -0.5f; vertices[17] = -0.5f; vertices[18] = 0.0; vertices[19] = 0.0; + vertices[0] = -0.5f; vertices[1] = -0.5f; vertices[2] = -0.5f; vertices[3] = 0.0; vertices[4] = 1.0; + vertices[5] = -0.5f; vertices[6] = 0.5f; vertices[7] = -0.5f; vertices[8] = 0.0; vertices[9] = 0.0; + vertices[10] = -0.5f; vertices[11] = 0.5f; vertices[12] = 0.5f; vertices[13] = 1.0; vertices[14] = 0.0; + vertices[15] = -0.5f; vertices[16] = -0.5f; vertices[17] = -0.5f; vertices[18] = 0.0; vertices[19] = 1.0; vertices[20] = -0.5f; vertices[21] = 0.5f; vertices[22] = 0.5f; vertices[23] = 1.0; vertices[24] = 0.0; vertices[25] = -0.5f; vertices[26] = -0.5f; vertices[27] = 0.5f; vertices[28] = 1.0; vertices[29] = 1.0; - vertices[30] = 0.5f; vertices[31] = -0.5f; vertices[32] = -0.5f; vertices[33] = 0.0; vertices[34] = 0.0; - vertices[35] = 0.5f; vertices[36] = 0.5f; vertices[37] = 0.5f; vertices[38] = 0.0; vertices[39] = 1.0; - vertices[40] = 0.5f; vertices[41] = 0.5f; vertices[42] = -0.5f; vertices[43] = 1.0; vertices[44] = 1.0; - vertices[45] = 0.5f; vertices[46] = -0.5f; vertices[47] = -0.5f; vertices[48] = 0.0; vertices[49] = 0.0; - vertices[50] = 0.5f; vertices[51] = -0.5f; vertices[52] = 0.5f; vertices[53] = 1.0; vertices[54] = 0.0; - vertices[55] = 0.5f; vertices[56] = 0.5f; vertices[57] = 0.5f; vertices[58] = 1.0; vertices[59] = 1.0; + vertices[30] = 0.5f; vertices[31] = -0.5f; vertices[32] = -0.5f; vertices[33] = 1.0; vertices[34] = 1.0; + vertices[35] = 0.5f; vertices[36] = 0.5f; vertices[37] = 0.5f; vertices[38] = 0.0; vertices[39] = 0.0; + vertices[40] = 0.5f; vertices[41] = 0.5f; vertices[42] = -0.5f; vertices[43] = 1.0; vertices[44] = 0.0; + vertices[45] = 0.5f; vertices[46] = -0.5f; vertices[47] = -0.5f; vertices[48] = 1.0; vertices[49] = 1.0; + vertices[50] = 0.5f; vertices[51] = -0.5f; vertices[52] = 0.5f; vertices[53] = 0.0; vertices[54] = 1.0; + vertices[55] = 0.5f; vertices[56] = 0.5f; vertices[57] = 0.5f; vertices[58] = 0.0; vertices[59] = 0.0; - vertices[60] = -0.5f; vertices[61] = -0.5f; vertices[62] = -0.5f; vertices[63] = 0.0; vertices[64] = 0.0; - vertices[65] = 0.5f; vertices[66] = -0.5f; vertices[67] = 0.5f; vertices[68] = 0.0; vertices[69] = 1.0; - vertices[70] = 0.5f; vertices[71] = -0.5f; vertices[72] = -0.5f; vertices[73] = 1.0; vertices[74] = 1.0; - vertices[75] = -0.5f; vertices[76] = -0.5f; vertices[77] = -0.5f; vertices[78] = 0.0; vertices[79] = 0.0; - vertices[80] = -0.5f; vertices[81] = -0.5f; vertices[82] = 0.5f; vertices[83] = 1.0; vertices[84] = 0.0; - vertices[85] = 0.5f; vertices[86] = -0.5f; vertices[87] = 0.5f; vertices[88] = 1.0; vertices[89] = 1.0; + vertices[60] = -0.5f; vertices[61] = -0.5f; vertices[62] = -0.5f; vertices[63] = 0.0; vertices[64] = 1.0; + vertices[65] = 0.5f; vertices[66] = -0.5f; vertices[67] = 0.5f; vertices[68] = 1.0; vertices[69] = 0.0; + vertices[70] = 0.5f; vertices[71] = -0.5f; vertices[72] = -0.5f; vertices[73] = 0.0; vertices[74] = 0.0; + vertices[75] = -0.5f; vertices[76] = -0.5f; vertices[77] = -0.5f; vertices[78] = 0.0; vertices[79] = 1.0; + vertices[80] = -0.5f; vertices[81] = -0.5f; vertices[82] = 0.5f; vertices[83] = 1.0; vertices[84] = 1.0; + vertices[85] = 0.5f; vertices[86] = -0.5f; vertices[87] = 0.5f; vertices[88] = 1.0; vertices[89] = 0.0; - vertices[90] = -0.5f; vertices[91] = 0.5f; vertices[92] = -0.5f; vertices[93] = 0.0; vertices[94] = 0.0; - vertices[95] = 0.5f; vertices[96] = 0.5f; vertices[97] = -0.5f; vertices[98] = 0.0; vertices[99] = 1.0; - vertices[100] = 0.5f; vertices[101] = 0.5f; vertices[102] = 0.5f; vertices[103] = 1.0; vertices[104] = 1.0; - vertices[105] = -0.5f; vertices[106] = 0.5f; vertices[107] = -0.5f; vertices[108] = 0.0; vertices[109] = 0.0; - vertices[110] = 0.5f; vertices[111] = 0.5f; vertices[112] = 0.5f; vertices[113] = 1.0; vertices[114] = 0.0; - vertices[115] = -0.5f; vertices[116] = 0.5f; vertices[117] = 0.5f; vertices[118] = 1.0; vertices[119] = 1.0; + vertices[90] = -0.5f; vertices[91] = 0.5f; vertices[92] = -0.5f; vertices[93] = 1.0; vertices[94] = 1.0; + vertices[95] = 0.5f; vertices[96] = 0.5f; vertices[97] = -0.5f; vertices[98] = 1.0; vertices[99] = 0.0; + vertices[100] = 0.5f; vertices[101] = 0.5f; vertices[102] = 0.5f; vertices[103] = 0.0; vertices[104] = 0.0; + vertices[105] = -0.5f; vertices[106] = 0.5f; vertices[107] = -0.5f; vertices[108] = 1.0; vertices[109] = 1.0; + vertices[110] = 0.5f; vertices[111] = 0.5f; vertices[112] = 0.5f; vertices[113] = 0.0; vertices[114] = 0.0; + vertices[115] = -0.5f; vertices[116] = 0.5f; vertices[117] = 0.5f; vertices[118] = 0.0; vertices[119] = 1.0; - vertices[120] = -0.5f; vertices[121] = -0.5f; vertices[122] = -0.5f; vertices[123] = 0.0; vertices[124] = 0.0; + vertices[120] = -0.5f; vertices[121] = -0.5f; vertices[122] = -0.5f; vertices[123] = 1.0; vertices[124] = 1.0; vertices[125] = 0.5f; vertices[126] = -0.5f; vertices[127] = -0.5f; vertices[128] = 0.0; vertices[129] = 1.0; - vertices[130] = 0.5f; vertices[131] = 0.5f; vertices[132] = -0.5f; vertices[133] = 1.0; vertices[134] = 1.0; - vertices[135] = -0.5f; vertices[136] = -0.5f; vertices[137] = -0.5f; vertices[138] = 0.0; vertices[139] = 0.0; - vertices[140] = 0.5f; vertices[141] = 0.5f; vertices[142] = -0.5f; vertices[143] = 1.0; vertices[144] = 0.0; - vertices[145] = -0.5f; vertices[146] = 0.5f; vertices[147] = -0.5f; vertices[148] = 1.0; vertices[149] = 1.0; + vertices[130] = 0.5f; vertices[131] = 0.5f; vertices[132] = -0.5f; vertices[133] = 0.0; vertices[134] = 0.0; + vertices[135] = -0.5f; vertices[136] = -0.5f; vertices[137] = -0.5f; vertices[138] = 1.0; vertices[139] = 1.0; + vertices[140] = 0.5f; vertices[141] = 0.5f; vertices[142] = -0.5f; vertices[143] = 0.0; vertices[144] = 0.0; + vertices[145] = -0.5f; vertices[146] = 0.5f; vertices[147] = -0.5f; vertices[148] = 1.0; vertices[149] = 0.0; - vertices[150] = -0.5f; vertices[151] = -0.5f; vertices[152] = 0.5f; vertices[153] = 0.0; vertices[154] = 0.0; - vertices[155] = 0.5f; vertices[156] = 0.5f; vertices[157] = 0.5f; vertices[158] = 0.0; vertices[159] = 1.0; + vertices[150] = -0.5f; vertices[151] = -0.5f; vertices[152] = 0.5f; vertices[153] = 0.0; vertices[154] = 1.0; + vertices[155] = 0.5f; vertices[156] = 0.5f; vertices[157] = 0.5f; vertices[158] = 1.0; vertices[159] = 0.0; vertices[160] = 0.5f; vertices[161] = -0.5f; vertices[162] = 0.5f; vertices[163] = 1.0; vertices[164] = 1.0; - vertices[165] = -0.5f; vertices[166] = -0.5f; vertices[167] = 0.5f; vertices[168] = 0.0; vertices[169] = 0.0; - vertices[170] = -0.5f; vertices[171] = 0.5f; vertices[172] = 0.5f; vertices[173] = 1.0; vertices[174] = 0.0; - vertices[175] = 0.5f; vertices[176] = 0.5f; vertices[177] = 0.5f; vertices[178] = 1.0; vertices[179] = 1.0; + vertices[165] = -0.5f; vertices[166] = -0.5f; vertices[167] = 0.5f; vertices[168] = 0.0; vertices[169] = 1.0; + vertices[170] = -0.5f; vertices[171] = 0.5f; vertices[172] = 0.5f; vertices[173] = 0.0; vertices[174] = 0.0; + 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) { @@ -165,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) { if(rtd != NULL) { + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, textures[0]); for(int k = 0; k < rtd->map_size; k++) { if(is_visible(rtd->map[k], offx, offy, offz)) { gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, rtd->map[k], offx, offy, offz); @@ -177,6 +177,8 @@ void gl_renderAll(unsigned int shaderProgram, unsigned int fragmentShader, unsig } for(int k = 0; k < rtd->ent_len; k++) { 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); } } diff --git a/src/entities.c b/src/entities.c index c0c5340..895b259 100644 --- a/src/entities.c +++ b/src/entities.c @@ -7,12 +7,14 @@ #include #include #include -#include +#include +#include +#include #include "hash.h" -#include "structure.h" #include "base.h" #include "display.h" +#include "menus.h" #include "proj.h" #include "entities.h" diff --git a/src/generation.c b/src/generation.c index 06891bf..857c6bc 100644 --- a/src/generation.c +++ b/src/generation.c @@ -8,10 +8,8 @@ #include #include #include -#include #include "hash.h" -#include "structure.h" #include "base.h" #include "entities.h" #include "generation.h" @@ -43,48 +41,56 @@ void init_ent_generator(int n) { } hashtbl_entities[0].id = 0; + hashtbl_entities[0].tex = 0; hashtbl_entities[0].name = "Coin"; // 0 = default hashtbl_entities[0].updatePos = &speen; hashtbl_entities[0].onHit = &money; hashtbl_entities[0].onDeath = NULL; hashtbl_entities[1].id = 1; + hashtbl_entities[1].tex = 0; hashtbl_entities[1].name = "ExplosiveStill"; hashtbl_entities[1].updatePos = &speen2; hashtbl_entities[1].onHit = &explodeOnHit; hashtbl_entities[1].onDeath = NULL; hashtbl_entities[2].id = 2; + hashtbl_entities[2].tex = 0; hashtbl_entities[2].name = "ExplosiveSeek"; hashtbl_entities[2].updatePos = &go_to_player; hashtbl_entities[2].onHit = &explodeOnHit; hashtbl_entities[2].onDeath = NULL; hashtbl_entities[3].id = 3; + hashtbl_entities[3].tex = 0; hashtbl_entities[3].name = "ExplosiveShoot"; hashtbl_entities[3].updatePos = &speen3; hashtbl_entities[3].onHit = &explodeOnHit; hashtbl_entities[3].onDeath = NULL; hashtbl_entities[4].id = 4; + hashtbl_entities[4].tex = 0; hashtbl_entities[4].name = "SinePlatform"; hashtbl_entities[4].updatePos = &moving_xyz; hashtbl_entities[4].onHit = &translatePlayer; hashtbl_entities[4].onDeath = NULL; hashtbl_entities[5].id = 5; + hashtbl_entities[5].tex = 0; hashtbl_entities[5].name = "LinePlatform"; hashtbl_entities[5].updatePos = &moving_xyz_line; hashtbl_entities[5].onHit = &translatePlayerLine; hashtbl_entities[5].onDeath = NULL; hashtbl_entities[6].id = 6; + hashtbl_entities[6].tex = 1; hashtbl_entities[6].name = "TextBox"; hashtbl_entities[6].updatePos = NULL; hashtbl_entities[6].onHit = &pop_text; hashtbl_entities[6].onDeath = NULL; hashtbl_entities[7].id = 7; + hashtbl_entities[7].tex = 0; hashtbl_entities[7].name = "WarpBox"; hashtbl_entities[7].updatePos = NULL; hashtbl_entities[7].onHit = &pop_and_tp; @@ -133,6 +139,8 @@ void copy_room(room* src, room* dest, int chx, int chy) { for(int k = 0; k < src->ent_len; k++) { dest->ents[k] = malloc(sizeof(entity)); 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]->metai1 = src->ents[k]->metai1; dest->ents[k]->metai2 = src->ents[k]->metai2; @@ -201,6 +209,7 @@ void build_starting_chunk(int chx, int chy) { for(int k = 0; k < 32; k++) { new->ents[k] = malloc(sizeof(entity)); new->ents[k]->hitpoints = malloc(sizeof(int)); + new->ents[k]->tex = 0; new->ents[k]->pos = malloc(sizeof(cube_0)); }; new->ent_len = 1; @@ -348,6 +357,7 @@ void parse_one_room(int id, char* filename) { pool[id].area->ents[k] = malloc(sizeof(entity)); pool[id].area->ents[k]->hitpoints = malloc(sizeof(int)); 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_memlen = nmemlen; @@ -417,8 +427,10 @@ void parse_one_room(int id, char* filename) { if(entry == NULL) { 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); 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]->updatePos = entry->updatePos; pool[id].area->ents[k]->onHit = entry->onHit ; @@ -636,14 +648,17 @@ void generate_nearby_chunks(int render_dist) { void free_pool() { 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++) { + printf("%d-%d\n", k, pool[k0].area->map_size); free(pool[k0].area->map[k]); } + printf("...\n"); fflush(stdout); for(int k = 0; k < pool[k0].area->tps_size; k++) { free(pool[k0].area->tps[k]->hitbox); free(pool[k0].area->tps[k]); } + printf("...\n"); fflush(stdout); for(int k = 0; k < pool[k0].area->ent_memlen; k++) { if(pool[k0].area->ents[k]->metai3 == -727) { // 6 and 7 // //free(pool[k0].area->ents[k]->metach1); @@ -656,6 +671,7 @@ void free_pool() { free(pool[k0].area->ents[k]->pos); free(pool[k0].area->ents[k]); } + printf("...\n"); fflush(stdout); free(pool[k0].area->ents); free(pool[k0].area->tps); free(pool[k0].area->map); diff --git a/src/generation.h b/src/generation.h index 9c2f621..2a2a4b5 100644 --- a/src/generation.h +++ b/src/generation.h @@ -33,6 +33,8 @@ typedef struct fct_entry { double metad9; char* metach1; char* metach2; + + int tex; } fct_entry ; extern int build_text_box(char* msg, int red, int green, int blue); diff --git a/src/hash.c b/src/hash.c index 76ed0fe..c1f479b 100644 --- a/src/hash.c +++ b/src/hash.c @@ -7,9 +7,7 @@ #include #include #include -#include -#include "structure.h" #include "hash.h" // ------------------------------------------------------------------------------------------------------- // diff --git a/src/hash.h b/src/hash.h index c939aea..8ec6658 100644 --- a/src/hash.h +++ b/src/hash.h @@ -4,6 +4,7 @@ #ifndef HASH_H #define HASH_H + #include "structure.h" #include diff --git a/src/main.c b/src/main.c index 0ed5b47..bbe2219 100644 --- a/src/main.c +++ b/src/main.c @@ -9,13 +9,13 @@ #include #include #include -#include +#ifndef STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" +#endif #include "hash.h" -#include "structure.h" #include "base.h" #include "move.h" #include "menus.h" @@ -37,6 +37,8 @@ double jPress = false; double gPress = false; double rPress = false; +unsigned int textures[16]; + void reset_everything(GLFWwindow *window, int count, char* folder) { /*hashtbl_free(visited); free_proj(); @@ -109,6 +111,8 @@ void reset_everything(GLFWwindow *window, int count, char* folder) { interface_set(-1); generate_nearby_chunks(1); + + printf("-------------------------------- Done 5 --------------------------------\n"); } void processInput(GLFWwindow *window, float dtime) { @@ -252,7 +256,7 @@ void processInput(GLFWwindow *window, float dtime) { //printf("-----\n"); switchRoom = false; reset_everything(window, newRoomCount, newRoomName); - free(newRoomName); + //free(newRoomName); } } @@ -277,7 +281,7 @@ const char *fragmentShaderSource = "#version 330 core\n" "uniform sampler2D tex0;\n" "void main() {\n" // " FragColor = u_color;\n" - " FragColor = texture(tex0, texCoord);\n" + " FragColor = texture(tex0, texCoord) * u_color;\n" "}\0"; const char *vertexShaderSourceR = "#version 330 core\n" @@ -295,6 +299,34 @@ const char *fragmentShaderSourceR = "#version 330 core\n" " FragColor = u_color2;\n" "}\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() { // glfw: initialize and configure // ------------------------------ @@ -398,29 +430,13 @@ int main_alt() { glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3*sizeof(float))); glEnableVertexAttribArray(1); - printf("-------------------------------------------------------\n"); fflush(stdout); + printf("-----------------------------------------------------------------------------------------------\n"); fflush(stdout); - int widthImg, heightImg, numColCh; - unsigned char* bytes = stbi_load("res/container.jpg", &widthImg, &heightImg, &numColCh, 0); - if(bytes == 0) {fprintf(stderr, "ERROR : cannot load texture\n"); exit(1);} - GLuint texture; - glGenTextures(1, &texture); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, texture); + //generate_texture(0, "res/container.jpg", "jpg"); + generate_texture(0, "res/white.png", PNG); + generate_texture(1, "res/question_block.png", PNG); - 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); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, widthImg, heightImg, 0, GL_RGB, GL_UNSIGNED_BYTE, bytes); - glGenerateMipmap(GL_TEXTURE_2D); - - stbi_image_free(bytes); - glBindTexture(GL_TEXTURE_2D, 0); - - printf("------------------------------------------------------- %d %d\n", widthImg, heightImg); fflush(stdout); + printf("-----------------------------------------------------------------------------------------------\n"); fflush(stdout); // ---------------------------------------------------------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------------------------------------------------------- // @@ -517,7 +533,6 @@ int main_alt() { glUseProgram(shaderProgram); // draw the map - glBindTexture(GL_TEXTURE_2D, texture); glBindVertexArray(VAO); gl_initRender(shaderProgram, shaderProgram, VAO, VBO); @@ -573,7 +588,8 @@ int main_alt() { // ------------------------------------------------------------------------ glDeleteVertexArrays(1, &VAO); glDeleteBuffers(1, &VBO); - glDeleteTextures(1, &texture); + glDeleteTextures(1, &textures[0]); + glDeleteTextures(1, &textures[1]); glDeleteProgram(shaderProgram); // glfw: terminate, clearing all previously allocated GLFW resources. diff --git a/src/menus.c b/src/menus.c index ce0d294..0db7edf 100644 --- a/src/menus.c +++ b/src/menus.c @@ -12,10 +12,8 @@ #include "../include/glad/glad.h" #include #include -#include #include "hash.h" -#include "structure.h" #include "base.h" #include "entities.h" #include "menus.h" diff --git a/src/move.c b/src/move.c index e0ba5ed..8744187 100644 --- a/src/move.c +++ b/src/move.c @@ -7,10 +7,8 @@ #include #include #include -#include #include "hash.h" -#include "structure.h" #include "base.h" #include "entities.h" #include "proj.h" diff --git a/src/proj.c b/src/proj.c index 8421487..ce0627e 100644 --- a/src/proj.c +++ b/src/proj.c @@ -7,9 +7,7 @@ #include #include #include -#include -#include "structure.h" #include "hash.h" #include "base.h" #include "move.h" diff --git a/src/structure.h b/src/structure.h index 68d2543..5d49437 100644 --- a/src/structure.h +++ b/src/structure.h @@ -59,6 +59,8 @@ typedef struct entity { char* metach1; char* metach2; + int tex; + int damage; int* hitpoints; } entity; @@ -170,12 +172,14 @@ extern char* newRoomName; extern int newRoomCount; extern bool switchRoom; -extern GLint loc_scale; -extern GLint loc_model; -extern GLint loc_view; -extern GLint loc_proj; +extern int loc_scale; +extern int loc_model; +extern int loc_view; +extern int loc_proj; -extern GLint loc_frag; -extern GLint loc_tex; +extern int loc_frag; +extern int loc_tex; + +extern unsigned int textures[16]; #endif \ No newline at end of file diff --git a/templates/room_3 b/templates/room_3 index 722e64f..32cce61 100644 --- a/templates/room_3 +++ b/templates/room_3 @@ -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] 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 : 50