moar stuff
This commit is contained in:
parent
750e001cda
commit
b040b27fed
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
|
# include <ctype.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
|
@ -103,7 +104,7 @@ t_gl_buf_type parse_gl_buf_type(char *token);
|
||||||
void parse_triangulate(t_buf_ui *indices, int token_count);
|
void parse_triangulate(t_buf_ui *indices, int token_count);
|
||||||
void parse_append_data_tmp(t_buf_ui *indices, int vertex_count, unsigned int *data_tmp);
|
void parse_append_data_tmp(t_buf_ui *indices, int vertex_count, unsigned int *data_tmp);
|
||||||
|
|
||||||
int parse_token(t_env *e, char *token, t_gl_buf_type gl_buf_type);
|
int parse_token(t_env *e, char *token, t_gl_buf_type gl_buf_typei, int token_count);
|
||||||
int parse_append_data_d(t_buf_d *buffer, char *token);
|
int parse_append_data_d(t_buf_d *buffer, char *token);
|
||||||
int parse_append_data_ui(t_buf_ui *buffer, char *token);
|
int parse_append_data_ui(t_buf_ui *buffer, char *token);
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 3.0 MiB |
Binary file not shown.
After Width: | Height: | Size: 3.5 MiB |
Binary file not shown.
After Width: | Height: | Size: 3.7 MiB |
Binary file not shown.
After Width: | Height: | Size: 3.7 MiB |
|
@ -0,0 +1,18 @@
|
||||||
|
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
|
||||||
|
# File Created: 20.12.2011 11:12:50
|
||||||
|
|
||||||
|
newmtl Cat
|
||||||
|
Ns 10.0000
|
||||||
|
Ni 1.5000
|
||||||
|
d 1.0000
|
||||||
|
Tr 0.0000
|
||||||
|
Tf 1.0000 1.0000 1.0000
|
||||||
|
illum 2
|
||||||
|
Ka 1.0000 1.0000 1.0000
|
||||||
|
Kd 1.0000 1.0000 1.0000
|
||||||
|
Ks 0.0000 0.0000 0.0000
|
||||||
|
Ke 0.0000 0.0000 0.0000
|
||||||
|
map_Ka Cat_diffuse.jpg
|
||||||
|
map_Kd Cat_diffuse.jpg
|
||||||
|
map_bump Cat_bump.jpg
|
||||||
|
bump Cat_bump.jpg
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
After Width: | Height: | Size: 555 KiB |
Binary file not shown.
After Width: | Height: | Size: 339 KiB |
|
@ -48,6 +48,7 @@ void parse_triangulate(t_buf_ui *indices, int vertex_count)
|
||||||
unsigned int *data_tmp;
|
unsigned int *data_tmp;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
printf("vertex count : %d\n", vertex_count);
|
||||||
i = 0;
|
i = 0;
|
||||||
data_tmp = (unsigned int *)malloc(
|
data_tmp = (unsigned int *)malloc(
|
||||||
sizeof(unsigned int) * 3 * (vertex_count - 2));
|
sizeof(unsigned int) * 3 * (vertex_count - 2));
|
||||||
|
@ -72,6 +73,14 @@ void parse_triangulate_dispatcher(t_env *e, int vertex_count) {
|
||||||
parse_triangulate(&(e->object.normals_indices), vertex_count);
|
parse_triangulate(&(e->object.normals_indices), vertex_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void strtrim(char *line) {
|
||||||
|
size_t i = strlen(line) - 1;
|
||||||
|
while (isspace(line[i])) {
|
||||||
|
line[i] = '\0';
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int parse_line(t_env *e, char *line)
|
int parse_line(t_env *e, char *line)
|
||||||
{
|
{
|
||||||
char *token;
|
char *token;
|
||||||
|
@ -81,18 +90,22 @@ int parse_line(t_env *e, char *line)
|
||||||
|
|
||||||
token_count = 0;
|
token_count = 0;
|
||||||
ret = SUCCESS;
|
ret = SUCCESS;
|
||||||
|
strtrim(line);
|
||||||
while ((token = strtok_r(line, " \t", &line)))
|
while ((token = strtok_r(line, " \t", &line)))
|
||||||
{
|
{
|
||||||
if (token_count == 0)
|
if (token_count == 0)
|
||||||
gl_buf_type = parse_gl_buf_type(token);
|
gl_buf_type = parse_gl_buf_type(token);
|
||||||
else
|
else
|
||||||
ret = parse_token(e, token, gl_buf_type);
|
ret = parse_token(e, token, gl_buf_type, token_count);
|
||||||
if (ret == FAILURE)
|
if (ret == FAILURE)
|
||||||
return (FAILURE);
|
return (FAILURE);
|
||||||
|
if (ret != BREAK)
|
||||||
token_count++;
|
token_count++;
|
||||||
}
|
}
|
||||||
if (gl_buf_type == INDEX && token_count > 4)
|
if (gl_buf_type == INDEX && token_count > 4) {
|
||||||
|
//printf("spongebob squared face\n");
|
||||||
parse_triangulate_dispatcher(e, token_count - 1);
|
parse_triangulate_dispatcher(e, token_count - 1);
|
||||||
|
}
|
||||||
return (SUCCESS);
|
return (SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,8 @@ int parse_append_data_index(t_env *e, char *phrase) {
|
||||||
int parse_token(
|
int parse_token(
|
||||||
t_env *e,
|
t_env *e,
|
||||||
char *token,
|
char *token,
|
||||||
t_gl_buf_type gl_buf_type)
|
t_gl_buf_type gl_buf_type,
|
||||||
|
int token_count)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -69,7 +70,7 @@ int parse_token(
|
||||||
ret = BREAK;
|
ret = BREAK;
|
||||||
if (gl_buf_type == VERTEX)
|
if (gl_buf_type == VERTEX)
|
||||||
ret = parse_append_data_d(&(e->object.vertices), token);
|
ret = parse_append_data_d(&(e->object.vertices), token);
|
||||||
if (gl_buf_type == UV)
|
if (gl_buf_type == UV && token_count < 3)
|
||||||
ret = parse_append_data_d(&(e->object.uvs), token);
|
ret = parse_append_data_d(&(e->object.uvs), token);
|
||||||
if (gl_buf_type == NORMAL)
|
if (gl_buf_type == NORMAL)
|
||||||
ret = parse_append_data_d(&(e->object.normals), token);
|
ret = parse_append_data_d(&(e->object.normals), token);
|
||||||
|
|
13
src/run.c
13
src/run.c
|
@ -110,8 +110,8 @@ static void RenderSceneCB(t_env *e)
|
||||||
//glDrawElements(GL_TRIANGLES, index_count * 3, GL_UNSIGNED_INT, 0);
|
//glDrawElements(GL_TRIANGLES, index_count * 3, GL_UNSIGNED_INT, 0);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, index_count);
|
glDrawArrays(GL_TRIANGLES, 0, index_count);
|
||||||
glDisableVertexAttribArray(0);
|
glDisableVertexAttribArray(0);
|
||||||
//glDisableVertexAttribArray(1);
|
glDisableVertexAttribArray(1);
|
||||||
//glDisableVertexAttribArray(2);
|
glDisableVertexAttribArray(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CreateVertexBuffer(t_env *e)
|
static void CreateVertexBuffer(t_env *e)
|
||||||
|
@ -124,7 +124,10 @@ static void CreateVertexBuffer(t_env *e)
|
||||||
printf("uvs indices len %ld\n", e->object.uvs_indices.ptr);
|
printf("uvs indices len %ld\n", e->object.uvs_indices.ptr);
|
||||||
printf("normals indices len %ld\n", e->object.normals_indices.ptr);
|
printf("normals indices len %ld\n", e->object.normals_indices.ptr);
|
||||||
is_good = 1;
|
is_good = 1;
|
||||||
e->vbo_data = (float *)malloc(e->object.vertices_indices.ptr * 8 * sizeof(float));
|
if (!(e->vbo_data = (float *)malloc(e->object.vertices_indices.ptr * 8 * sizeof(float)))) {
|
||||||
|
perror("malloc");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
for (size_t i = 0; i < e->object.vertices_indices.ptr * 8; i += 8) {
|
for (size_t i = 0; i < e->object.vertices_indices.ptr * 8; i += 8) {
|
||||||
e->vbo_data[i] = e->object.vertices.data[e->object.vertices_indices.data[i / 8] * 3];
|
e->vbo_data[i] = e->object.vertices.data[e->object.vertices_indices.data[i / 8] * 3];
|
||||||
e->vbo_data[i + 1] = e->object.vertices.data[e->object.vertices_indices.data[i / 8] * 3 + 1];
|
e->vbo_data[i + 1] = e->object.vertices.data[e->object.vertices_indices.data[i / 8] * 3 + 1];
|
||||||
|
@ -143,7 +146,7 @@ static void CreateVertexBuffer(t_env *e)
|
||||||
is_good = 0;
|
is_good = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//printf("bruh\n");
|
||||||
glGenBuffers(1, &VBO);
|
glGenBuffers(1, &VBO);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
glBufferData(GL_ARRAY_BUFFER, e->object.vertices_indices.ptr * 8 * sizeof(float), e->vbo_data, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, e->object.vertices_indices.ptr * 8 * sizeof(float), e->vbo_data, GL_STATIC_DRAW);
|
||||||
|
@ -369,7 +372,7 @@ int run(t_env *e)
|
||||||
|
|
||||||
int tex_width, tex_height, nrChannels;
|
int tex_width, tex_height, nrChannels;
|
||||||
|
|
||||||
unsigned char *tex_data = stbi_load("resources/42.png", &tex_width, &tex_height, &nrChannels, 0);
|
unsigned char *tex_data = stbi_load("resources/42_5.png", &tex_width, &tex_height, &nrChannels, 0);
|
||||||
printf("number of channels : %d\n", nrChannels);
|
printf("number of channels : %d\n", nrChannels);
|
||||||
if (nrChannels == 4) {
|
if (nrChannels == 4) {
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_width, tex_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_data);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_width, tex_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_data);
|
||||||
|
|
Loading…
Reference in New Issue