diff options
Diffstat (limited to 'inc')
| -rw-r--r-- | inc/scop.h | 88 |
1 files changed, 57 insertions, 31 deletions
@@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/05/09 10:41:44 by charles #+# #+# */ -/* Updated: 2020/05/13 16:36:10 by charles ### ########.fr */ +/* Updated: 2020/05/14 14:58:23 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ # include <stdbool.h> # include <stdlib.h> # include <GL/glew.h> -# include <GLFW/glfw3.h> +# include <SDL2/SDL.h> # include "libft.h" # include "libft_vec.h" @@ -26,28 +26,56 @@ # include "libftm_mat4.h" # include "libftm_vec3.h" +#define WINDOW_WIDTH 640 +#define WINDOW_HEIGHT 480 + typedef struct { float *vertices; unsigned int *indices; - size_t vertices_len; - size_t indices_len; -} t_object; + size_t vertices_size; + size_t indices_size; +} t_model_data; typedef struct { unsigned int vertex_buf; unsigned int index_buf; + size_t index_buf_size; unsigned int vertex_array; - unsigned int shader; - int model_location; - int view_location; - int proj_location; + struct + { + t_ftmmat4 center; + t_ftmmat4 model; + t_ftmmat4 view; + t_ftmmat4 proj; + } transform; +} t_scene; + +typedef struct +{ + unsigned int id; + struct + { + int model; + int view; + int proj; + } location; +} t_shader; + +typedef struct +{ + SDL_Window *window; + SDL_GLContext *context; + bool running; + int width; + int height; + t_scene scene; + t_shader shader; GLenum polygon_mode; - double polygon_mode_last_time; float fov; -} t_gl_state; +} t_state; union u_color { @@ -62,18 +90,26 @@ union u_color }; /* -** parse.c +** state.c */ -int parse(char *filepath, t_object *object); +bool state_init(t_state *state, t_model_data *data); +void state_run(t_state *state); +void state_quit(t_state *state); /* -** gl.c +** scene.c */ +void scene_init(t_scene *scene, t_model_data *data); +void scene_update_proj(t_scene *scene, float fov, int width, int height); +void scene_update_model(t_scene *scene, float rotation_radian); +void scene_quit(t_scene *scene); -int gl_state_init(t_gl_state *state, t_object *object); -void gl_state_quit(t_gl_state *state, t_object *object); -void gl_state_set_mvp(t_gl_state *state, t_ftmmat4 *model, t_ftmmat4 *view, t_ftmmat4 *proj); +/* +** parse.c +*/ + +int parse(char *filepath, t_model_data *object); /* ** error.c @@ -86,17 +122,13 @@ void gl_state_set_mvp(t_gl_state *state, t_ftmmat4 *model, t_ftmmat4 *view, t void error_clear(void); void error_check(char *code, char *filename, int line_num); -/* -** glfw.c -*/ - -GLFWwindow *glfw_init(int width, int height); /* ** shader.c */ -unsigned int shader_new(void); +bool shader_init(t_shader *shader); +void shader_update_mvp(t_shader *shader, t_scene *scene); /* ** texture.c @@ -111,19 +143,13 @@ unsigned int texture_new(char *filepath); bool has_extension(char *filepath, char *extension); /* -** center.c -*/ - -void center_mat4_init_translate(t_ftmmat4 *dst, float *vertices, size_t vertices_len); - -/* ** color.c */ -bool color_merge_vertices(t_object *object, float *coords); +bool color_merge_vertices(t_model_data *object, float *coords); -float *texture_coord_create(float *vertices, size_t vertices_len); +float *texture_coord_create(float *vertices, size_t vertices_len); #endif |
