stuff
This commit is contained in:
parent
266f7381ae
commit
750e001cda
10
Makefile
10
Makefile
|
@ -41,7 +41,7 @@ SRC = $(addprefix $(SRC_DIR), $(SRC_FILE))
|
||||||
OBJ = $(addprefix $(OBJ_DIR), $(OBJ_FILE))
|
OBJ = $(addprefix $(OBJ_DIR), $(OBJ_FILE))
|
||||||
INC = $(addprefix $(INC_DIR), $(INC_FILE))
|
INC = $(addprefix $(INC_DIR), $(INC_FILE))
|
||||||
|
|
||||||
LIB = -lm -lGL -lglfw glew-2.2.0/lib/libGLEW.a
|
LIB = -lm -lGL -lglfw -lGLEW #glew-2.2.0/lib/libGLEW.a
|
||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
|
|
||||||
|
@ -57,8 +57,8 @@ WHITE = \033[0m
|
||||||
all: $(NAME)
|
all: $(NAME)
|
||||||
|
|
||||||
$(NAME): $(OBJ) $(INC)
|
$(NAME): $(OBJ) $(INC)
|
||||||
@make -C glew-2.2.0
|
# @make -C glew-2.2.0
|
||||||
@$(CC) $(CFLAGS) -c $(SRC) -I $(INC_DIR) -I glew-2.2.0/include/
|
@$(CC) $(CFLAGS) -c $(SRC) -I $(INC_DIR) #-I glew-2.2.0/include/
|
||||||
@mv $(OBJ_FILE) $(OBJ_DIR)
|
@mv $(OBJ_FILE) $(OBJ_DIR)
|
||||||
@$(CC) $(CFLAGS) $(OBJ) -o $(NAME) $(LIB)
|
@$(CC) $(CFLAGS) $(OBJ) -o $(NAME) $(LIB)
|
||||||
@echo -e "$(GREEN)[OK]$(WHITE) $(NAME)"
|
@echo -e "$(GREEN)[OK]$(WHITE) $(NAME)"
|
||||||
|
@ -67,7 +67,7 @@ $(OBJ_DIR)%.o: $(SRC_DIR)%.c inc/
|
||||||
@if [ ! -d ./obj ]; then \
|
@if [ ! -d ./obj ]; then \
|
||||||
mkdir -p ./obj; \
|
mkdir -p ./obj; \
|
||||||
fi;
|
fi;
|
||||||
@$(CC) $(CFLAGS) -I $(INC_DIR) -I glew-2.2.0/include/ -o $@ -c $<
|
@$(CC) $(CFLAGS) -I $(INC_DIR) -o $@ -c $< #-I glew-2.2.0/include/ -o $@ -c $<
|
||||||
@echo -e "$(CYAN)[CC]$(WHITE) $<"
|
@echo -e "$(CYAN)[CC]$(WHITE) $<"
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
@ -75,7 +75,7 @@ clean:
|
||||||
@echo -e "$(RED)[REMOVED]$(WHITE) obj files"
|
@echo -e "$(RED)[REMOVED]$(WHITE) obj files"
|
||||||
|
|
||||||
fclean: clean
|
fclean: clean
|
||||||
make -C glew-2.2.0 clean
|
# make -C glew-2.2.0 clean
|
||||||
@rm -f $(NAME)
|
@rm -f $(NAME)
|
||||||
@echo -e "$(RED)[REMOVED]$(WHITE) $(NAME)"
|
@echo -e "$(RED)[REMOVED]$(WHITE) $(NAME)"
|
||||||
|
|
||||||
|
|
10
inc/scop.h
10
inc/scop.h
|
@ -3,11 +3,13 @@
|
||||||
|
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
# include <fcntl.h>
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# include <assert.h>
|
# include <assert.h>
|
||||||
# include <math.h>
|
# include <math.h>
|
||||||
# include <float.h>
|
# include <float.h>
|
||||||
|
# include <stdbool.h>
|
||||||
# include <GL/glew.h>
|
# include <GL/glew.h>
|
||||||
# include <GLFW/glfw3.h>
|
# include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
@ -79,13 +81,17 @@ struct s_env {
|
||||||
t_cam camera;
|
t_cam camera;
|
||||||
t_window window;
|
t_window window;
|
||||||
t_obj object;
|
t_obj object;
|
||||||
double *vbo_data;
|
float *vbo_data;
|
||||||
GLuint shader_program;
|
GLuint shader_program;
|
||||||
GLuint vertex_shader;
|
GLuint vertex_shader;
|
||||||
GLuint fragment_shader;
|
GLuint fragment_shader;
|
||||||
t_vec3 translate;
|
t_vec3 translate;
|
||||||
t_vec3 rotate;
|
t_vec3 rotate;
|
||||||
t_vec3 scale;
|
t_vec3 scale;
|
||||||
|
bool rotating;
|
||||||
|
bool texture;
|
||||||
|
bool lighting;
|
||||||
|
float texture_level;
|
||||||
};
|
};
|
||||||
|
|
||||||
int parse(t_env *e, int argc, char **argv);
|
int parse(t_env *e, int argc, char **argv);
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 2.3 MiB |
|
@ -0,0 +1,12 @@
|
||||||
|
# Blender 4.2.1 LTS MTL File: 'None'
|
||||||
|
# www.blender.org
|
||||||
|
|
||||||
|
newmtl Material.001
|
||||||
|
Ns 96.078453
|
||||||
|
Ka 1.000000 1.000000 1.000000
|
||||||
|
Kd 0.640000 0.640000 0.640000
|
||||||
|
Ks 0.500000 0.500000 0.500000
|
||||||
|
Ke 0.000000 0.000000 0.000000
|
||||||
|
Ni 1.000000
|
||||||
|
d 1.000000
|
||||||
|
illum 2
|
|
@ -0,0 +1,220 @@
|
||||||
|
# Blender 4.2.1 LTS
|
||||||
|
# www.blender.org
|
||||||
|
mtllib 42_textured.mtl
|
||||||
|
o Cube.001
|
||||||
|
v 0.231702 -1.182178 -0.175533
|
||||||
|
v 0.231702 -0.711052 1.533746
|
||||||
|
v -0.228179 -0.711052 1.533746
|
||||||
|
v -0.228179 -1.182178 -0.175533
|
||||||
|
v 0.231703 1.154434 -0.175533
|
||||||
|
v 0.231702 1.154434 0.293462
|
||||||
|
v -0.228179 1.154434 0.293461
|
||||||
|
v -0.228179 1.154434 -0.175534
|
||||||
|
v 0.231702 -0.305864 1.533746
|
||||||
|
v -0.228179 -0.305864 1.533746
|
||||||
|
v 0.231703 -0.270741 -0.175533
|
||||||
|
v 0.231703 -0.260044 0.988585
|
||||||
|
v -0.228179 -0.270741 -0.175533
|
||||||
|
v -0.228179 -0.260044 0.988585
|
||||||
|
v 0.231702 -1.188117 0.187844
|
||||||
|
v 0.231702 -0.711052 0.168380
|
||||||
|
v -0.228179 -0.711052 0.168380
|
||||||
|
v -0.228179 -1.188117 0.187843
|
||||||
|
v -0.228107 -0.696726 -0.407874
|
||||||
|
v -0.228107 -0.696726 -1.346972
|
||||||
|
v 0.223000 -0.696726 -1.346972
|
||||||
|
v 0.223000 -0.696726 -0.407874
|
||||||
|
v -0.228107 1.153829 -0.407875
|
||||||
|
v -0.228107 1.153829 -1.346972
|
||||||
|
v 0.223000 1.153829 -1.346972
|
||||||
|
v 0.223000 1.153829 -0.407875
|
||||||
|
v -0.228107 -0.095320 -0.407875
|
||||||
|
v -0.228107 0.585944 -0.924865
|
||||||
|
v -0.228107 1.138720 -0.900851
|
||||||
|
v -0.228107 0.541788 -0.407875
|
||||||
|
v 0.223000 0.541788 -0.407875
|
||||||
|
v 0.223000 1.138721 -0.900851
|
||||||
|
v 0.223000 0.585944 -0.924865
|
||||||
|
v 0.223000 -0.095320 -0.407875
|
||||||
|
v -0.228107 0.668586 -1.346972
|
||||||
|
v -0.228107 -0.032316 -0.910776
|
||||||
|
v -0.228107 -0.650197 -0.919671
|
||||||
|
v -0.228107 -0.041071 -1.346972
|
||||||
|
v 0.223000 0.668586 -1.346972
|
||||||
|
v 0.223000 -0.032316 -0.910776
|
||||||
|
v 0.223000 -0.650197 -0.919671
|
||||||
|
v 0.223000 -0.041071 -1.346972
|
||||||
|
vn -0.0000 -1.0000 -0.0000
|
||||||
|
vn -0.0000 1.0000 -0.0000
|
||||||
|
vn -1.0000 -0.0000 -0.0000
|
||||||
|
vn -0.0000 0.6474 0.7622
|
||||||
|
vn -0.0000 -0.0000 -1.0000
|
||||||
|
vn -0.0000 -0.0000 1.0000
|
||||||
|
vn -0.0000 -0.6355 -0.7721
|
||||||
|
vn -0.0000 1.0000 -0.0092
|
||||||
|
vn -0.0000 -0.9999 -0.0163
|
||||||
|
vn -0.0000 0.0408 0.9992
|
||||||
|
vn 1.0000 -0.0000 -0.0000
|
||||||
|
vn -0.0000 -0.6368 -0.7711
|
||||||
|
vn -0.0000 -0.0434 0.9991
|
||||||
|
vn -0.0000 0.6045 0.7966
|
||||||
|
vn -0.0000 -0.5284 -0.8490
|
||||||
|
vn -0.0000 0.0144 -0.9999
|
||||||
|
vn -0.0000 0.5743 0.8187
|
||||||
|
vt 0.749960 0.539512
|
||||||
|
vt 0.749960 0.853365
|
||||||
|
vt 0.644248 0.853365
|
||||||
|
vt 0.644248 0.539512
|
||||||
|
vt 0.643558 0.865344
|
||||||
|
vt 0.537846 0.865344
|
||||||
|
vt 0.537846 0.973151
|
||||||
|
vt 0.643558 0.973151
|
||||||
|
vt 0.102894 0.542985
|
||||||
|
vt 0.216213 0.680200
|
||||||
|
vt 0.216213 0.539512
|
||||||
|
vt 0.893253 0.093485
|
||||||
|
vt 0.893253 0.429160
|
||||||
|
vt 0.787541 0.429160
|
||||||
|
vt 0.787541 0.093485
|
||||||
|
vt 0.267938 0.325487
|
||||||
|
vt 0.000345 0.327946
|
||||||
|
vt 0.079400 0.429160
|
||||||
|
vt 0.999655 0.426413
|
||||||
|
vt 0.999655 0.216903
|
||||||
|
vt 0.893943 0.216903
|
||||||
|
vt 0.893943 0.426413
|
||||||
|
vt 0.893253 0.000345
|
||||||
|
vt 0.787541 0.000345
|
||||||
|
vt 0.643558 0.864654
|
||||||
|
vt 0.643558 0.539512
|
||||||
|
vt 0.537846 0.539512
|
||||||
|
vt 0.537846 0.864654
|
||||||
|
vt 0.997638 0.697443
|
||||||
|
vt 0.997638 0.429850
|
||||||
|
vt 0.891926 0.429850
|
||||||
|
vt 0.891926 0.697443
|
||||||
|
vt 0.787541 0.855922
|
||||||
|
vt 0.871070 0.855922
|
||||||
|
vt 0.871069 0.961634
|
||||||
|
vt 0.787541 0.961634
|
||||||
|
vt 0.749960 0.854055
|
||||||
|
vt 0.749960 0.963717
|
||||||
|
vt 0.644248 0.963717
|
||||||
|
vt 0.644248 0.854055
|
||||||
|
vt 0.787541 0.580564
|
||||||
|
vt 0.891236 0.580564
|
||||||
|
vt 0.891236 0.429850
|
||||||
|
vt 0.787541 0.429850
|
||||||
|
vt 0.313932 0.670050
|
||||||
|
vt 0.216903 0.651053
|
||||||
|
vt 0.216903 0.539512
|
||||||
|
vt 0.319452 0.542984
|
||||||
|
vt 0.537156 0.677755
|
||||||
|
vt 0.433461 0.677755
|
||||||
|
vt 0.433461 0.539512
|
||||||
|
vt 0.537156 0.539512
|
||||||
|
vt 0.891926 0.914001
|
||||||
|
vt 0.891926 0.698133
|
||||||
|
vt 0.995621 0.698133
|
||||||
|
vt 0.995621 0.914001
|
||||||
|
vt 0.997638 0.216213
|
||||||
|
vt 0.997638 0.000345
|
||||||
|
vt 0.893943 0.000345
|
||||||
|
vt 0.893943 0.216213
|
||||||
|
vt 0.537156 0.964894
|
||||||
|
vt 0.433461 0.964894
|
||||||
|
vt 0.433461 0.824206
|
||||||
|
vt 0.537156 0.824206
|
||||||
|
vt 0.433461 0.961421
|
||||||
|
vt 0.537156 0.961421
|
||||||
|
vt 0.433461 0.834356
|
||||||
|
vt 0.537156 0.834356
|
||||||
|
vt 0.787541 0.855232
|
||||||
|
vt 0.891236 0.855232
|
||||||
|
vt 0.891236 0.743691
|
||||||
|
vt 0.787541 0.743691
|
||||||
|
vt 0.891236 0.582576
|
||||||
|
vt 0.787541 0.582576
|
||||||
|
vt 0.891236 0.440545
|
||||||
|
vt 0.787541 0.440545
|
||||||
|
vt 0.432771 0.539511
|
||||||
|
vt 0.432771 0.680200
|
||||||
|
vt 0.098568 0.954198
|
||||||
|
vt 0.000345 0.814180
|
||||||
|
vt 0.000345 0.964894
|
||||||
|
vt 0.216903 0.964894
|
||||||
|
vt 0.216903 0.814180
|
||||||
|
vt 0.315126 0.954198
|
||||||
|
vt 0.519258 0.213679
|
||||||
|
vt 0.786851 0.538821
|
||||||
|
vt 0.679044 0.538821
|
||||||
|
vt 0.432771 0.964894
|
||||||
|
vt 0.000345 0.000345
|
||||||
|
vt 0.108152 0.000345
|
||||||
|
vt 0.097374 0.670050
|
||||||
|
vt 0.100612 0.812168
|
||||||
|
vt 0.216213 0.826650
|
||||||
|
vt 0.393253 0.336020
|
||||||
|
vt 0.393253 0.429160
|
||||||
|
vt 0.317170 0.812168
|
||||||
|
vt 0.432771 0.826650
|
||||||
|
vt 0.786851 0.211220
|
||||||
|
vt 0.707797 0.110007
|
||||||
|
vt 0.703322 0.000345
|
||||||
|
vt 0.786851 0.001710
|
||||||
|
vt 0.393943 0.110007
|
||||||
|
vt 0.393943 0.203146
|
||||||
|
vt 0.083873 0.538821
|
||||||
|
vt 0.000345 0.537456
|
||||||
|
vt 0.000345 0.651053
|
||||||
|
vt 0.216213 0.964894
|
||||||
|
vt 0.000345 0.539512
|
||||||
|
s 0
|
||||||
|
usemtl Material.001
|
||||||
|
f 16/1/1 2/2/1 3/3/1 17/4/1
|
||||||
|
f 5/5/2 8/6/2 7/7/2 6/8/2
|
||||||
|
f 29/9/3 30/10/3 23/11/3
|
||||||
|
f 9/12/4 6/13/4 7/14/4 10/15/4
|
||||||
|
f 14/16/3 13/17/3 17/18/3
|
||||||
|
f 11/19/5 1/20/5 4/21/5 13/22/5
|
||||||
|
f 2/23/6 9/12/6 10/15/6 3/24/6
|
||||||
|
f 5/25/7 12/26/7 14/27/7 8/28/7
|
||||||
|
f 12/29/8 11/30/8 13/31/8 14/32/8
|
||||||
|
f 1/33/9 15/34/9 18/35/9 4/36/9
|
||||||
|
f 15/37/10 16/38/10 17/39/10 18/40/10
|
||||||
|
f 38/41/5 42/42/5 21/43/5 20/44/5
|
||||||
|
f 33/45/11 39/46/11 25/47/11 32/48/11
|
||||||
|
f 34/49/6 27/50/6 19/51/6 22/52/6
|
||||||
|
f 19/53/1 20/54/1 21/55/1 22/56/1
|
||||||
|
f 26/57/2 25/58/2 24/59/2 23/60/2
|
||||||
|
f 26/61/6 23/62/6 30/63/6 31/64/6
|
||||||
|
f 31/64/12 30/63/12 29/65/12 32/66/12
|
||||||
|
f 32/66/13 29/65/13 28/67/13 33/68/13
|
||||||
|
f 33/68/14 28/67/14 27/50/14 34/49/14
|
||||||
|
f 24/69/5 25/70/5 39/71/5 35/72/5
|
||||||
|
f 35/72/15 39/71/15 40/73/15 36/74/15
|
||||||
|
f 36/74/16 40/73/16 41/75/16 37/76/16
|
||||||
|
f 37/76/17 41/75/17 42/42/17 38/41/17
|
||||||
|
f 26/77/11 31/78/11 32/48/11
|
||||||
|
f 37/79/3 38/80/3 20/81/3
|
||||||
|
f 21/82/11 42/83/11 41/84/11
|
||||||
|
f 12/85/11 5/86/11 6/87/11
|
||||||
|
f 25/47/11 26/77/11 32/48/11
|
||||||
|
f 22/88/11 21/82/11 41/84/11
|
||||||
|
f 8/89/3 14/16/3 7/90/3
|
||||||
|
f 28/91/3 36/92/3 27/93/3
|
||||||
|
f 10/94/3 14/16/3 17/18/3 3/95/3
|
||||||
|
f 33/45/11 40/96/11 39/46/11
|
||||||
|
f 40/96/11 33/45/11 34/97/11
|
||||||
|
f 11/98/11 16/99/11 15/100/11 1/101/11
|
||||||
|
f 14/16/3 10/94/3 7/90/3
|
||||||
|
f 2/102/11 16/99/11 12/85/11 9/103/11
|
||||||
|
f 11/98/11 12/85/11 16/99/11
|
||||||
|
f 40/96/11 34/97/11 22/88/11 41/84/11
|
||||||
|
f 12/85/11 6/87/11 9/103/11
|
||||||
|
f 18/104/3 17/18/3 13/17/3 4/105/3
|
||||||
|
f 36/92/3 28/91/3 35/106/3
|
||||||
|
f 37/79/3 20/81/3 19/107/3
|
||||||
|
f 29/9/3 23/11/3 24/108/3
|
||||||
|
f 19/107/3 27/93/3 36/92/3 37/79/3
|
||||||
|
f 24/108/3 35/106/3 28/91/3 29/9/3
|
|
@ -0,0 +1,7 @@
|
||||||
|
░▒▓███████▓▒░ ░▒▓██████▓▒░ ███████ ░▒▓███████▓▒░
|
||||||
|
░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ █ █ █ ░▒▓█▓▒░░▒▓█▓▒░
|
||||||
|
░▒▓█▓▒░ ░▒▓█▓▒░ █ █ █ ░▒▓█▓▒░░▒▓█▓▒░
|
||||||
|
░▒▓██████▓▒░ ░▒▓█▓▒░ ████ o ████ ░▒▓███████▓▒░
|
||||||
|
░▒▓█▓▒░ ░▒▓█▓▒░ █ █ █ ░▒▓█▓▒░
|
||||||
|
░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ █ █ █ ░▒▓█▓▒░
|
||||||
|
░▒▓███████▓▒░ ░▒▓██████▓▒░ ███████ ░▒▓█▓▒░
|
12
src/main.c
12
src/main.c
|
@ -13,10 +13,22 @@
|
||||||
#include "scop.h"
|
#include "scop.h"
|
||||||
#include "mat4.h"
|
#include "mat4.h"
|
||||||
|
|
||||||
|
void banner(void) {
|
||||||
|
int fd = open("resources/scop.ans", O_RDONLY);
|
||||||
|
if (fd == -1) {
|
||||||
|
printf("warning: can't open banner file\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char buffer[902];
|
||||||
|
ssize_t len = read(fd, buffer, 902);
|
||||||
|
write(1, buffer, len);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
t_env e;
|
t_env e;
|
||||||
|
|
||||||
|
banner();
|
||||||
init_env(&e);
|
init_env(&e);
|
||||||
if (parse(&e, argc, argv) == SUCCESS)
|
if (parse(&e, argc, argv) == SUCCESS)
|
||||||
{
|
{
|
||||||
|
|
70
src/run.c
70
src/run.c
|
@ -26,6 +26,8 @@ GLuint gViewLocation;
|
||||||
GLuint gModelLocation;
|
GLuint gModelLocation;
|
||||||
GLuint gNormalLocation;
|
GLuint gNormalLocation;
|
||||||
GLuint has_texture_location;
|
GLuint has_texture_location;
|
||||||
|
GLuint texture_level_location;
|
||||||
|
GLuint lighting_location;
|
||||||
//GLuint gCountLocation;
|
//GLuint gCountLocation;
|
||||||
GLuint index_count;
|
GLuint index_count;
|
||||||
|
|
||||||
|
@ -64,6 +66,17 @@ static void RenderSceneCB(t_env *e)
|
||||||
t_mat4 view = mat4_inverse(mat4_lookat(eye, up, target));
|
t_mat4 view = mat4_inverse(mat4_lookat(eye, up, target));
|
||||||
// t_mat4 model = mat4_rotatey(mat4_rotatex(mat4_identity(), Scale), Scale / 1.3);
|
// t_mat4 model = mat4_rotatey(mat4_rotatex(mat4_identity(), Scale), Scale / 1.3);
|
||||||
//t_mat4 model = mat4_rotatey(mat4_identity(), Scale);
|
//t_mat4 model = mat4_rotatey(mat4_identity(), Scale);
|
||||||
|
|
||||||
|
if (e->rotating == true) {
|
||||||
|
e->rotate.y += 0.01;
|
||||||
|
//mat4_rotatey(e->rotate, 0.01);
|
||||||
|
}
|
||||||
|
if (e->texture == true) {
|
||||||
|
e->texture_level += 0.006;
|
||||||
|
if (e->texture_level > 1) {
|
||||||
|
e->texture_level = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
t_mat4 model = mat4_scale(
|
t_mat4 model = mat4_scale(
|
||||||
mat4_rotatexyz(
|
mat4_rotatexyz(
|
||||||
mat4_translate(mat4_identity(), e->translate), e->rotate), e->scale);
|
mat4_translate(mat4_identity(), e->translate), e->rotate), e->scale);
|
||||||
|
@ -74,29 +87,31 @@ static void RenderSceneCB(t_env *e)
|
||||||
glUniformMatrix4fv(gModelLocation, 1, GL_FALSE, (GLfloat *)model.data);
|
glUniformMatrix4fv(gModelLocation, 1, GL_FALSE, (GLfloat *)model.data);
|
||||||
glUniformMatrix4fv(gNormalLocation, 1, GL_FALSE, (GLfloat *)normal.data);
|
glUniformMatrix4fv(gNormalLocation, 1, GL_FALSE, (GLfloat *)normal.data);
|
||||||
//glUniform1i(gCountLocation, index_count);
|
//glUniform1i(gCountLocation, index_count);
|
||||||
glUniform1i(gSamplerLocation, 0);
|
|
||||||
glUniform1i(has_texture_location, is_good);
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glUniform1i(gSamplerLocation, 0);
|
||||||
|
glUniform1i(has_texture_location, e->texture);
|
||||||
|
glUniform1f(texture_level_location, e->texture_level);
|
||||||
|
glUniform1i(lighting_location, e->lighting);
|
||||||
|
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
glVertexAttribPointer(0, 3, GL_DOUBLE, GL_FALSE, 8 * sizeof(double), 0);
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), 0);
|
||||||
|
|
||||||
if (is_good) {
|
//if (e->texture) {
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
glVertexAttribPointer(1, 2, GL_DOUBLE, GL_FALSE, 8 * sizeof(double), (void *)(3 * sizeof(double)));
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void *)(3 * sizeof(float)));
|
||||||
|
|
||||||
glEnableVertexAttribArray(2);
|
glEnableVertexAttribArray(2);
|
||||||
glVertexAttribPointer(2, 3, GL_DOUBLE, GL_FALSE, 8 * sizeof(double), (void *)(5 * sizeof(double)));
|
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void *)(5 * sizeof(float)));
|
||||||
}
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, index_count);
|
|
||||||
//glBindTexture(GL_TEXTURE_2D, texture);
|
//glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
|
//}
|
||||||
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||||
|
|
||||||
//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);
|
||||||
glDisableVertexAttribArray(0);
|
glDisableVertexAttribArray(0);
|
||||||
glDisableVertexAttribArray(1);
|
//glDisableVertexAttribArray(1);
|
||||||
glDisableVertexAttribArray(2);
|
//glDisableVertexAttribArray(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CreateVertexBuffer(t_env *e)
|
static void CreateVertexBuffer(t_env *e)
|
||||||
|
@ -109,7 +124,7 @@ 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 = (double *)malloc(e->object.vertices_indices.ptr * 8 * sizeof(double));
|
e->vbo_data = (float *)malloc(e->object.vertices_indices.ptr * 8 * sizeof(float));
|
||||||
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];
|
||||||
|
@ -131,7 +146,7 @@ static void CreateVertexBuffer(t_env *e)
|
||||||
|
|
||||||
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(double), e->vbo_data, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, e->object.vertices_indices.ptr * 8 * sizeof(float), e->vbo_data, GL_STATIC_DRAW);
|
||||||
printf("Buffer created with success !\n");
|
printf("Buffer created with success !\n");
|
||||||
/* glGenBuffers(1, &VBO);
|
/* glGenBuffers(1, &VBO);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
@ -236,6 +251,8 @@ static void CompileShaders(t_env *e)
|
||||||
gNormalLocation = glGetUniformLocation(e->shader_program, "normalMat");
|
gNormalLocation = glGetUniformLocation(e->shader_program, "normalMat");
|
||||||
gSamplerLocation = glGetUniformLocation(e->shader_program, "ourTexture");
|
gSamplerLocation = glGetUniformLocation(e->shader_program, "ourTexture");
|
||||||
has_texture_location = glGetUniformLocation(e->shader_program, "has_texture");
|
has_texture_location = glGetUniformLocation(e->shader_program, "has_texture");
|
||||||
|
texture_level_location = glGetUniformLocation(e->shader_program, "texture_level");
|
||||||
|
lighting_location = glGetUniformLocation(e->shader_program, "lighting");
|
||||||
// assert(gScaleLocation != 0xFFFFFFFF);
|
// assert(gScaleLocation != 0xFFFFFFFF);
|
||||||
assert(gTimeLocation != 0xFFFFFFFF);
|
assert(gTimeLocation != 0xFFFFFFFF);
|
||||||
assert(gProjLocation != 0xFFFFFFFF);
|
assert(gProjLocation != 0xFFFFFFFF);
|
||||||
|
@ -259,6 +276,17 @@ void free_shaders(t_env *e)
|
||||||
void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||||
{
|
{
|
||||||
t_env *e = (t_env *)glfwGetWindowUserPointer(window);
|
t_env *e = (t_env *)glfwGetWindowUserPointer(window);
|
||||||
|
if (key == GLFW_KEY_N && (action == GLFW_PRESS))
|
||||||
|
e->rotating = !e->rotating;
|
||||||
|
if (key == GLFW_KEY_B && (action == GLFW_PRESS)) {
|
||||||
|
e->texture = !e->texture;
|
||||||
|
if (e->texture == true) {
|
||||||
|
e->texture_level = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (key == GLFW_KEY_V && (action == GLFW_PRESS)) {
|
||||||
|
e->lighting = !e->lighting;
|
||||||
|
}
|
||||||
if (key == GLFW_KEY_Q && (action == GLFW_PRESS || action == GLFW_REPEAT))
|
if (key == GLFW_KEY_Q && (action == GLFW_PRESS || action == GLFW_REPEAT))
|
||||||
e->translate.x += 0.03;
|
e->translate.x += 0.03;
|
||||||
if (key == GLFW_KEY_A && (action == GLFW_PRESS || action == GLFW_REPEAT))
|
if (key == GLFW_KEY_A && (action == GLFW_PRESS || action == GLFW_REPEAT))
|
||||||
|
@ -320,8 +348,8 @@ int run(t_env *e)
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
index_count = e->object.vertices_indices.ptr;
|
index_count = e->object.vertices_indices.ptr;
|
||||||
printf("%ld\n", e->object.vertices.ptr);
|
//printf("%ld\n", e->object.vertices.ptr);
|
||||||
printf("%ld\n", e->object.vertices_indices.ptr);
|
//printf("%ld\n", e->object.vertices_indices.ptr);
|
||||||
GLenum res = glewInit();
|
GLenum res = glewInit();
|
||||||
if (res != GLEW_OK)
|
if (res != GLEW_OK)
|
||||||
{
|
{
|
||||||
|
@ -341,8 +369,16 @@ int run(t_env *e)
|
||||||
|
|
||||||
int tex_width, tex_height, nrChannels;
|
int tex_width, tex_height, nrChannels;
|
||||||
|
|
||||||
unsigned char *tex_data = stbi_load("resources/fox.jpg", &tex_width, &tex_height, &nrChannels, 0);
|
unsigned char *tex_data = stbi_load("resources/42.png", &tex_width, &tex_height, &nrChannels, 0);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_width, tex_height, 0, GL_RGB, GL_UNSIGNED_BYTE, tex_data);
|
printf("number of channels : %d\n", nrChannels);
|
||||||
|
if (nrChannels == 4) {
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_width, tex_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_data);
|
||||||
|
} else if (nrChannels == 3) {
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_width, tex_height, 0, GL_RGB, GL_UNSIGNED_BYTE, tex_data);
|
||||||
|
} else {
|
||||||
|
printf("error: sus text file detected, aborting NOW\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
stbi_image_free(tex_data);
|
stbi_image_free(tex_data);
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
uniform float time;
|
uniform float time;
|
||||||
uniform sampler2D ourTexture;
|
uniform sampler2D ourTexture;
|
||||||
uniform int has_texture;
|
uniform int has_texture;
|
||||||
|
uniform float texture_level;
|
||||||
|
uniform int lighting;
|
||||||
|
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
flat in int vID;
|
flat in int vID;
|
||||||
|
@ -19,15 +21,16 @@ float rand(float n)
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 color = vec3(rand(float(vID + int(time))), rand(float(vID + int(time))), rand(float(vID + int(time))));
|
vec3 color = vec3(rand(float(vID + int(time))), rand(float(vID + int(time))), rand(float(vID + int(time))));
|
||||||
vec3 n = normalize(vec3(10. * cos(time), 10., 10. * sin(time)) - position);
|
|
||||||
float phong = 0.2 + 0.8 * max(0., dot(n, normalize(normal)));
|
|
||||||
float specular = pow(max(dot(reflect(n, normalize(normal)), normalize(vec3(0, 0, -2) - position)), 0.), 10.);
|
|
||||||
if (has_texture == 1) {
|
if (has_texture == 1) {
|
||||||
FragColor = vec4(texture(ourTexture, texCoord).rgb * phong + vec3(1.) * specular, 1.);
|
color = color * (1 - texture_level) + texture_level * texture(ourTexture, vec2(texCoord.x, 1.- texCoord.y)).rgb;
|
||||||
//FragColor = vec4(texCoord.xyx / 2. * phong + vec3(1.) * specular, 1.);
|
|
||||||
}
|
}
|
||||||
else {
|
if (lighting == 1) {
|
||||||
FragColor = vec4(color, 1.);
|
vec3 n = normalize(vec3(10. * cos(time), 10., 10. * sin(time)) - position);
|
||||||
}
|
float ambient = 0.2;
|
||||||
//FragColor = vec4(color * 0.001 + normal, 1.);
|
float phong = max(0., dot(n, normalize(normal)));
|
||||||
|
float specular = pow(max(dot(reflect(n, normalize(normal)), normalize(vec3(0, 0, -2) - position)), 0.), 10.);
|
||||||
|
color = color * (ambient + (1. - ambient) * phong) + vec3(1.) * specular;
|
||||||
|
}
|
||||||
|
FragColor = vec4(color, 1.);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ layout (location = 0) in vec3 Position;
|
||||||
layout (location = 1) in vec2 Uvs;
|
layout (location = 1) in vec2 Uvs;
|
||||||
layout (location = 2) in vec3 Normal;
|
layout (location = 2) in vec3 Normal;
|
||||||
|
|
||||||
uniform float gScale;
|
//uniform float gScale;
|
||||||
uniform mat4 view;
|
uniform mat4 view;
|
||||||
uniform mat4 proj;
|
uniform mat4 proj;
|
||||||
uniform mat4 model;
|
uniform mat4 model;
|
||||||
|
|
Loading…
Reference in New Issue