aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
blob: c02bc2f9f61a627c695d2a08f98bb681c71277dd (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
130
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.c                                             :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: charles <charles.cabergs@gmail.com>        +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/05/09 10:20:09 by charles           #+#    #+#             */
/*   Updated: 2020/05/14 14:49:02 by charles          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "scop.h"

/*
** TODO
** - texture
**   - parse vt
**   - parse coord index of f
**   - transition color/texture
** - cleaner code
*/

/* void	handle_event(GLFWwindow *window) */
/* { */
/* 	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++)
	{
		for (int j = 0; j < 4; j++)
		{
			printf("%.2f, ", mat->m[i * 4 + j]);
		}
		printf("\n");
	}
	printf("\n");
}

int main(int argc, char **argv)
{
	t_state	state;
	t_model_data data;

	if (argc != 2)
	{
		ft_putstr("Usage: ");
		ft_putstr(argv[0]);
		ft_putendl(" [obj file]");
		return (1);
	}
	if (parse(argv[1], &data) == -1)
	{
		ft_putstr("Error: couldn't parse ");
		ft_putendl(argv[1]);
		return (1);
	}

	/* unsigned int texture = texture_new("res/brick.bmp"); */
	/* float *coords = texture_coord_create(object.vertices, object.vertices_len); */
    /*  */
	/* if (!color_merge_vertices(&object, coords)) */
	/* { */
	/* 	ft_putstr("Error: couldn't create colors"); */
	/* 	return (1); */
	/* } */

	printf("size %lu\n", data.indices_size);
	for (size_t i = 0; i < data.indices_size; i++)
	{
		printf("%u, ", data.indices[i++]);
		printf("%u, ", data.indices[i++]);
		printf("%u\n", data.indices[i]);
	}

	printf("size %lu\n", data.vertices_size);
	for (size_t i = 0; i < data.vertices_size; i++)
	{
		printf("% f, ", data.vertices[i++]);
		printf("% f, ", data.vertices[i++]);
		printf("% f, ", data.vertices[i++]);
		printf("% f\n", data.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]); */
	}

	/* GL_CALL(glUniform1i(glGetUniformLocation(state.shader, "u_texture"), 0)); */
	/* GL_CALL(glActiveTexture(GL_TEXTURE0)); */
	/* GL_CALL(glBindTexture(GL_TEXTURE_2D, texture)); */

	if (!state_init(&state, &data))
		return (1);
	state_run(&state);
	state_quit(&state);
	free(data.vertices);
	free(data.indices);
	return 0;
}