aboutsummaryrefslogtreecommitdiff
path: root/inc/scop.h
blob: fb48a8141dfbf8d0a7a1c56457a2805314f85aa2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   scop.h                                             :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   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       */
/*                                                                            */
/* ************************************************************************** */

#ifndef SCOP_H
# define SCOP_H

# include <unistd.h>
# include <fcntl.h>
# include <stdbool.h>
# include <stdlib.h>
# include <GL/glew.h>
# include <GLFW/glfw3.h>

# include "libft.h"
# include "libft_vec.h"
# include "libftm.h"
# include "libftm_mat4.h"
# include "libftm_vec3.h"


typedef struct
{
	float			*vertices;
	unsigned int	*indices;
	size_t			vertices_len;
	size_t			indices_len;
}					t_object;

typedef struct
{
	unsigned int	vertex_buf;
	unsigned int	index_buf;
	unsigned int	vertex_array;
	unsigned int	shader;
	int				model_location;
	int				view_location;
	int				proj_location;
	GLenum			polygon_mode;
	double			polygon_mode_last_time;
	float			fov;
}					t_gl_state;

union				u_color
{
	float			data[4];
	struct
	{
		float		r;
		float		g;
		float		b;
		float		a;
	};
};

/*
** parse.c
*/

int					parse(char *filepath, t_object *object);

/*
** gl.c
*/

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);

/*
** error.c
*/

# define GL_CALL(x) error_clear(); \
                    x; \
                    error_check(#x, __FILE__, __LINE__)

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);

/*
** texture.c
*/

unsigned int	texture_new(char *filepath);

/*
** helper.c
*/

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);


float	*texture_coord_create(float *vertices, size_t vertices_len);


#endif