aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-05-09 21:31:30 +0200
committerCharles <sircharlesaze@gmail.com>2020-05-09 21:33:14 +0200
commit0ae5be6c6697f5f5f578a27c5ad9ba845aec43c9 (patch)
tree4cda3590f185cb485bf57e2dbd3d9b8b81dba6d7 /src
parent6618fed5933f26d9bee8a42f049115146d4a1113 (diff)
downloadscop-0ae5be6c6697f5f5f578a27c5ad9ba845aec43c9.tar.gz
scop-0ae5be6c6697f5f5f578a27c5ad9ba845aec43c9.tar.bz2
scop-0ae5be6c6697f5f5f578a27c5ad9ba845aec43c9.zip
Added basic vector and matrix library
Diffstat (limited to 'src')
-rw-r--r--src/main.c47
-rw-r--r--src/parse.c83
2 files changed, 111 insertions, 19 deletions
diff --git a/src/main.c b/src/main.c
index fc50f41..3eb0acc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,33 +6,42 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/09 10:20:09 by charles #+# #+# */
-/* Updated: 2020/05/09 10:39:09 by charles ### ########.fr */
+/* Updated: 2020/05/09 11:08:59 by charles ### ########.fr */
/* */
/* ************************************************************************** */
-#include "libft.h"
-#include <GL/glew.h>
-#include <GLFW/glfw3.h>
+#include "scop.h"
int main(int argc, char **argv)
{
- GLFWwindow* window;
+ /* GLFWwindow *window; */
+ float *buffer;
- if (!glfwInit())
- return -1;
- window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
- if (!window)
+ if (argc != 2)
{
- glfwTerminate();
- return -1;
+ ft_putstr("Usage: ");
+ ft_putstr(argv[0]);
+ ft_putendl(" [obj file]");
+ return (1);
}
- glfwMakeContextCurrent(window);
- while (!glfwWindowShouldClose(window))
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glfwSwapBuffers(window);
- glfwPollEvents();
- }
- glfwTerminate();
+ if ((buffer = parse(argv[1])) == NULL)
+ return 1;
+
+ /* if (!glfwInit()) */
+ /* return 1; */
+ /* window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL); */
+ /* if (window == NULL) */
+ /* { */
+ /* glfwTerminate(); */
+ /* return 1; */
+ /* } */
+ /* glfwMakeContextCurrent(window); */
+ /* while (!glfwWindowShouldClose(window)) */
+ /* { */
+ /* glClear(GL_COLOR_BUFFER_BIT); */
+ /* glfwSwapBuffers(window); */
+ /* glfwPollEvents(); */
+ /* } */
+ /* glfwTerminate(); */
return 0;
}
diff --git a/src/parse.c b/src/parse.c
new file mode 100644
index 0000000..4add0b3
--- /dev/null
+++ b/src/parse.c
@@ -0,0 +1,83 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* parse.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/09 11:02:00 by charles #+# #+# */
+/* Updated: 2020/05/09 12:07:36 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "scop.h"
+
+#define SCOP_VEC_DEFAULT_SIZE 32
+
+static int st_parse_line(char *line, t_ftvec *vertices, t_ftvec *indices)
+{
+ unsigned int tmp;
+ float tmpf;
+
+ if (*line == 'v')
+ {
+ tmpf = ft_strtof(line, &line);
+ ft_vecpush(indices, *((void**)&tmp));
+ tmpf = ft_strtof(line, &line);
+ ft_vecpush(indices, *((void**)&tmp));
+ tmpf = ft_strtof(line, &line);
+ ft_vecpush(indices, *((void**)&tmp));
+ }
+ if (*line == 'f')
+ {
+ tmp = ft_strtol(line, &line, 10);
+ ft_vecpush(indices, *((void**)&tmp));
+ tmp = ft_strtol(line, &line, 10);
+ ft_vecpush(indices, *((void**)&tmp));
+ tmp = ft_strtol(line, &line, 10);
+ ft_vecpush(indices, *((void**)&tmp));
+ }
+
+
+ return (0);
+}
+
+static int st_parse_file(int fd, t_ftvec *vertices, t_ftvec *indices)
+{
+ char *line;
+ int ret;
+
+ while ((ret = ft_getline(fd, &line)) == FT_LINE)
+ {
+ ret = st_parse_line(line, vertices, indices);
+ free(line);
+ if (ret == -1)
+ break ;
+ }
+ if (ret == FT_ERROR)
+ return (-1);
+ if (*line != '\0')
+ {
+ free(line);
+ return (-1);
+ }
+ return (0);
+}
+
+int parse(char *filepath, t_object *object)
+{
+ int fd;
+ t_ftvec *vertices;
+ t_ftvec *indices;
+
+ if ((fd = open(filepath, O_RDONLY)) == -1)
+ return (-1);
+ if ((vertices = ft_vecnew(SCOP_VEC_DEFAULT_SIZE)) == NULL)
+ return (-1);
+ if ((indices = ft_vecnew(SCOP_VEC_DEFAULT_SIZE)) == NULL)
+ return (-1);
+ st_parse_file(fd, vertices, indices);
+ object->vertices = (float*)ft_vectobuf32(vertices);
+ object->indices = (unsigned int*)ft_vectobuf32(indices);
+ return (0);
+}