diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-05-13 17:14:08 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-05-13 17:14:08 +0200 |
| commit | 46f56c104218f675daf2feb1366f53f4d84a1886 (patch) | |
| tree | 6b3a324e160bc601ff724d59dca5ed7d9f6a2766 /src/main.c | |
| parent | 0267b512527b85af6cd815bb9215bd659b75931e (diff) | |
| download | scop-46f56c104218f675daf2feb1366f53f4d84a1886.tar.gz scop-46f56c104218f675daf2feb1366f53f4d84a1886.tar.bz2 scop-46f56c104218f675daf2feb1366f53f4d84a1886.zip | |
Very ugly and not working texture
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 92 |
1 files changed, 64 insertions, 28 deletions
@@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/05/09 10:20:09 by charles #+# #+# */ -/* Updated: 2020/05/13 13:04:45 by charles ### ########.fr */ +/* Updated: 2020/05/13 17:11:37 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,11 +17,40 @@ ** - texture ** - parse vt ** - parse coord index of f -** - parse mtl file -** - color -** - transition with texture +** - transition color/texture */ +void handle_event(GLFWwindow *window, t_gl_state *state) +{ + if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) + glfwSetWindowShouldClose(window, true); + else if (glfwGetKey(window, GLFW_KEY_P) == GLFW_PRESS) + { + if (state->polygon_mode_last_time + 0.1 > glfwGetTime()) + return ; + if (state->polygon_mode == GL_FILL) + state->polygon_mode = GL_LINE; + else if (state->polygon_mode == GL_LINE) + state->polygon_mode = GL_POINT; + else if (state->polygon_mode == GL_POINT) + state->polygon_mode = GL_FILL; + GL_CALL(glPolygonMode(GL_FRONT_AND_BACK, state->polygon_mode)); + state->polygon_mode_last_time = glfwGetTime(); + } + else if (glfwGetKey(window, GLFW_KEY_EQUAL) == GLFW_PRESS) + { + state->fov -= M_PI / 100.0f; + if (state->fov <= M_PI_4 / 2) + state->fov = M_PI_4 / 2; + } + else if (glfwGetKey(window, GLFW_KEY_MINUS) == GLFW_PRESS) + { + state->fov += M_PI / 100.0f; + if (state->fov >= M_PI - M_PI_4 / 2) + state->fov = M_PI - M_PI_4 / 2; + } +} + void debugmat(t_ftmmat4 *mat) { for (int i = 0; i < 4; i++) @@ -57,11 +86,14 @@ int main(int argc, char **argv) return (1); } + unsigned int texture = texture_new("res/brick.bmp"); + float *coords = texture_coord_create(object.vertices, object.vertices_len); + t_ftmmat4 center_trans; center_mat4_init_translate(¢er_trans, object.vertices, object.vertices_len); /* debugmat(¢er_trans); */ - if (!color_merge_vertices(&object)) + if (!color_merge_vertices(&object, coords)) { ft_putstr("Error: couldn't create colors"); return (1); @@ -76,18 +108,20 @@ int main(int argc, char **argv) /* } */ /* printf("yo %lu\n", object.indices_len); */ - /* for (size_t i = 0; i < object.vertices_len * 8; i++) */ - /* { */ - /* printf("% f, ", object.vertices[i++]); */ - /* printf("% f, ", object.vertices[i++]); */ - /* printf("% f, ", object.vertices[i++]); */ - /* printf("% f\tcolor: ", object.vertices[i++]); */ - /* printf("% f, ", object.vertices[i++]); */ - /* printf("% f, ", object.vertices[i++]); */ - /* printf("% f, ", object.vertices[i++]); */ - /* printf("% f\n", object.vertices[i]); */ - /* } */ - /* printf("yo %lu\n", object.vertices_len); */ + for (size_t i = 0; i < object.vertices_len * 10; i++) + { + printf("% f, ", object.vertices[i++]); + printf("% f, ", object.vertices[i++]); + printf("% f, ", object.vertices[i++]); + printf("% f\tcolor: ", object.vertices[i++]); + printf("% f, ", object.vertices[i++]); + printf("% f, ", object.vertices[i++]); + printf("% f, ", object.vertices[i++]); + printf("% f\ttex: ", object.vertices[i]); + printf("% f", object.vertices[i++]); + printf("% f\n", object.vertices[i]); + } + printf("yo %lu\n", object.vertices_len); t_ftmmat4 model; t_ftmmat4 view; @@ -116,17 +150,22 @@ int main(int argc, char **argv) GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, 0)); GL_CALL(glBindVertexArray(0)); - GL_CALL(glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)); - GL_CALL(glUseProgram(state.shader)); gl_state_set_mvp(&state, &model, &view, &proj); + GL_CALL(glUniform1i(glGetUniformLocation(state.shader, "u_texture"), 0)); + GL_CALL(glActiveTexture(GL_TEXTURE0)); + /* printf("%u\n", texture); */ + /* GL_CALL(glBindTexture(GL_TEXTURE_2D, texture)); */ + float deg = 0.0; while (!glfwWindowShouldClose(window)) { + handle_event(window, &state); GL_CALL(glClearColor(0.2f, 0.3f, 0.3f, 1.0f)); GL_CALL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); + GL_CALL(glUseProgram(state.shader)); ftm_mat4init_eye(&model, 1.0); @@ -135,19 +174,16 @@ int main(int argc, char **argv) ftm_mat4mul(&model, ¢er_trans); deg += 0.4; - if (g_window_resized) - { - int w, h; - glfwGetFramebufferSize(window, &w, &h); - /* printf("%d %d\n", w, h); */ - ftm_mat4init_perspective(&proj, M_PI_4, (float)w / (float)h, 0.1, 100.0); - g_window_resized = false; - } + int w, h; + glfwGetFramebufferSize(window, &w, &h); + ftm_mat4init_perspective(&proj, state.fov, (float)w / (float)h, 0.1, 100.0); + g_window_resized = false; gl_state_set_mvp(&state, &model, &view, &proj); + GL_CALL(glBindVertexArray(state.vertex_array)); - GL_CALL(glDrawElements(GL_TRIANGLES, object.indices_len * sizeof(unsigned int), GL_UNSIGNED_INT, (void*)0)); + GL_CALL(glDrawElements(GL_TRIANGLES, object.indices_len * sizeof(unsigned int) * 3, GL_UNSIGNED_INT, (void*)0)); glfwSwapBuffers(window); glfwPollEvents(); |
