matrices working, transparency issues
This commit is contained in:
parent
71c9d90cee
commit
f6aff761f9
3
Makefile
3
Makefile
|
@ -6,7 +6,7 @@
|
||||||
# By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ #
|
# By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2020/12/17 19:47:03 by gbrochar #+# #+# #
|
# Created: 2020/12/17 19:47:03 by gbrochar #+# #+# #
|
||||||
# Updated: 2020/12/23 20:33:29 by gbrochar ### ########.fr #
|
# Updated: 2020/12/24 12:29:48 by gbrochar ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ SRC_FILE = main.c \
|
||||||
mat4_lookat.c \
|
mat4_lookat.c \
|
||||||
mat4_identity.c \
|
mat4_identity.c \
|
||||||
mat4_inverse.c \
|
mat4_inverse.c \
|
||||||
|
mat4_rotate.c \
|
||||||
|
|
||||||
OBJ_FILE = $(SRC_FILE:.c=.o)
|
OBJ_FILE = $(SRC_FILE:.c=.o)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2020/12/22 20:35:00 by gbrochar #+# #+# */
|
/* Created: 2020/12/22 20:35:00 by gbrochar #+# #+# */
|
||||||
/* Updated: 2020/12/23 22:05:17 by gbrochar ### ########.fr */
|
/* Updated: 2020/12/24 12:30:50 by gbrochar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ typedef struct s_persp_tool t_persp_tool;
|
||||||
|
|
||||||
struct s_mat4
|
struct s_mat4
|
||||||
{
|
{
|
||||||
double data[16];
|
float data[16];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct s_persp_tool
|
struct s_persp_tool
|
||||||
|
@ -55,4 +55,7 @@ t_mat4 mat4_identity(void);
|
||||||
|
|
||||||
t_mat4 mat4_inverse(t_mat4 m);
|
t_mat4 mat4_inverse(t_mat4 m);
|
||||||
|
|
||||||
|
t_mat4 mat4_rotatex(t_mat4 m, double theta);
|
||||||
|
t_mat4 mat4_rotatey(t_mat4 m, double theta);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* mat4_rotate.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/24 12:24:54 by gbrochar #+# #+# */
|
||||||
|
/* Updated: 2020/12/24 12:32:22 by gbrochar ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "mat4.h"
|
||||||
|
|
||||||
|
t_mat4 mat4_rotatex(t_mat4 m, double theta)
|
||||||
|
{
|
||||||
|
double s = sin(theta);
|
||||||
|
double c = cos(theta);
|
||||||
|
t_mat4 ret;
|
||||||
|
|
||||||
|
ret.data[0] = m.data[0];
|
||||||
|
ret.data[1] = m.data[1];
|
||||||
|
ret.data[2] = m.data[2];
|
||||||
|
ret.data[3] = m.data[3];
|
||||||
|
ret.data[4] = m.data[4] * c + m.data[8] * s;
|
||||||
|
ret.data[5] = m.data[5] * c + m.data[9] * s;
|
||||||
|
ret.data[6] = m.data[6] * c + m.data[10] * s;
|
||||||
|
ret.data[7] = m.data[7] * c + m.data[11] * s;
|
||||||
|
ret.data[8] = m.data[8] * c - m.data[4] * s;
|
||||||
|
ret.data[9] = m.data[9] * c - m.data[5] * s;
|
||||||
|
ret.data[10] = m.data[10] * c - m.data[6] * s;
|
||||||
|
ret.data[11] = m.data[11] * c - m.data[7] * s;
|
||||||
|
ret.data[12] = m.data[12];
|
||||||
|
ret.data[13] = m.data[13];
|
||||||
|
ret.data[14] = m.data[14];
|
||||||
|
ret.data[15] = m.data[15];
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
t_mat4 mat4_rotatey(t_mat4 m, double theta)
|
||||||
|
{
|
||||||
|
double s = sin(theta);
|
||||||
|
double c = cos(theta);
|
||||||
|
t_mat4 ret;
|
||||||
|
|
||||||
|
ret.data[0] = m.data[0] * c - m.data[8] * s;
|
||||||
|
ret.data[1] = m.data[1] * c - m.data[9] * s;
|
||||||
|
ret.data[2] = m.data[2] * c - m.data[10] * s;
|
||||||
|
ret.data[3] = m.data[3] * c - m.data[11] * s;
|
||||||
|
ret.data[4] = m.data[4];
|
||||||
|
ret.data[5] = m.data[5];
|
||||||
|
ret.data[6] = m.data[6];
|
||||||
|
ret.data[7] = m.data[7];
|
||||||
|
ret.data[8] = m.data[8] * c + m.data[0] * s;
|
||||||
|
ret.data[9] = m.data[9] * c + m.data[1] * s;
|
||||||
|
ret.data[10] = m.data[10] * c + m.data[2] * s;
|
||||||
|
ret.data[11] = m.data[11] * c + m.data[3] * s;
|
||||||
|
ret.data[12] = m.data[12];
|
||||||
|
ret.data[13] = m.data[13];
|
||||||
|
ret.data[14] = m.data[14];
|
||||||
|
ret.data[15] = m.data[15];
|
||||||
|
return (ret);
|
||||||
|
}
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2020/12/23 17:33:33 by gbrochar #+# #+# */
|
/* Created: 2020/12/23 17:33:33 by gbrochar #+# #+# */
|
||||||
/* Updated: 2020/12/23 21:23:38 by gbrochar ### ########.fr */
|
/* Updated: 2020/12/24 12:34:38 by gbrochar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
29
src/run.c
29
src/run.c
|
@ -6,7 +6,7 @@
|
||||||
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2020/12/23 19:38:05 by gbrochar #+# #+# */
|
/* Created: 2020/12/23 19:38:05 by gbrochar #+# #+# */
|
||||||
/* Updated: 2020/12/23 22:22:44 by gbrochar ### ########.fr */
|
/* Updated: 2020/12/24 13:14:32 by gbrochar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -20,14 +20,17 @@ GLuint gScaleLocation;
|
||||||
GLuint gProjLocation;
|
GLuint gProjLocation;
|
||||||
GLuint gViewLocation;
|
GLuint gViewLocation;
|
||||||
GLuint gModelLocation;
|
GLuint gModelLocation;
|
||||||
|
GLuint gCountLocation;
|
||||||
|
GLuint index_count;
|
||||||
|
|
||||||
const char* pVSFileName = "src/shader.vs";
|
const char* pVSFileName = "src/shader.vs";
|
||||||
const char* pFSFileName = "src/shader.fs";
|
const char* pFSFileName = "src/shader.fs";
|
||||||
|
|
||||||
static void RenderSceneCB()
|
static void RenderSceneCB()
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
static float Scale = 0.0f;
|
static float Scale = 0.0f;
|
||||||
|
|
||||||
Scale += 0.01f;
|
Scale += 0.01f;
|
||||||
|
@ -38,31 +41,29 @@ static void RenderSceneCB()
|
||||||
|
|
||||||
eye.x = 0;
|
eye.x = 0;
|
||||||
eye.y = 0;
|
eye.y = 0;
|
||||||
eye.z = 10;
|
eye.z = 30;
|
||||||
up.x = 0;
|
up.x = 0;
|
||||||
up.y = 1;
|
up.y = 1;
|
||||||
up.z = 0;
|
up.z = 0;
|
||||||
target.x = 0;
|
target.x = 0;
|
||||||
target.y = 0;
|
target.y = 0;
|
||||||
target.z = 9;
|
target.z = 29;
|
||||||
|
|
||||||
t_mat4 proj = mat4_perspective(1., 800.0 / 600.0, 0.001, 1000);
|
t_mat4 proj = mat4_perspective(45.0 * M_PI / 180.0, 800.0 / 600.0, 0.001, 1000);
|
||||||
t_mat4 view = mat4_inverse(mat4_lookat(eye, up, target));
|
t_mat4 view = mat4_inverse(mat4_lookat(eye, up, target));
|
||||||
t_mat4 model = mat4_identity();
|
t_mat4 model = mat4_rotatey(mat4_identity(), Scale);
|
||||||
//glUniform1f(gScaleLocation, sinf(Scale));
|
//glUniform1f(gScaleLocation, sinf(Scale));
|
||||||
glUniformMatrix4fv(gProjLocation, 1, GL_FALSE, (GLfloat *)proj.data);
|
glUniformMatrix4fv(gProjLocation, 1, GL_FALSE, (GLfloat *)proj.data);
|
||||||
glUniformMatrix4fv(gViewLocation, 1, GL_FALSE, (GLfloat *)view.data);
|
glUniformMatrix4fv(gViewLocation, 1, GL_FALSE, (GLfloat *)view.data);
|
||||||
glUniformMatrix4fv(gModelLocation, 1, GL_FALSE, (GLfloat *)model.data);
|
glUniformMatrix4fv(gModelLocation, 1, GL_FALSE, (GLfloat *)model.data);
|
||||||
|
glUniform1i(gCountLocation, index_count);
|
||||||
|
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
glVertexAttribPointer(0, 3, GL_DOUBLE, GL_FALSE, 0, 0);
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||||
// first GL_POINT or GL_TRIANGLES
|
glDrawElements(GL_TRIANGLES, index_count, GL_UNSIGNED_INT, 0);
|
||||||
// second start of draw
|
|
||||||
// third number of vertices to draw
|
|
||||||
glDrawElements(GL_TRIANGLES, 228, GL_UNSIGNED_INT, 0);
|
|
||||||
|
|
||||||
glDisableVertexAttribArray(0);
|
glDisableVertexAttribArray(0);
|
||||||
|
|
||||||
|
@ -175,10 +176,12 @@ static void CompileShaders()
|
||||||
gProjLocation = glGetUniformLocation(ShaderProgram, "proj");
|
gProjLocation = glGetUniformLocation(ShaderProgram, "proj");
|
||||||
gViewLocation = glGetUniformLocation(ShaderProgram, "view");
|
gViewLocation = glGetUniformLocation(ShaderProgram, "view");
|
||||||
gModelLocation = glGetUniformLocation(ShaderProgram, "model");
|
gModelLocation = glGetUniformLocation(ShaderProgram, "model");
|
||||||
|
gCountLocation = glGetUniformLocation(ShaderProgram, "icount");
|
||||||
//assert(gScaleLocation != 0xFFFFFFFF);
|
//assert(gScaleLocation != 0xFFFFFFFF);
|
||||||
assert(gProjLocation != 0xFFFFFFFF);
|
assert(gProjLocation != 0xFFFFFFFF);
|
||||||
assert(gViewLocation != 0xFFFFFFFF);
|
assert(gViewLocation != 0xFFFFFFFF);
|
||||||
assert(gModelLocation != 0xFFFFFFFF);
|
assert(gModelLocation != 0xFFFFFFFF);
|
||||||
|
assert(gCountLocation != 0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
void run(t_env *e)
|
void run(t_env *e)
|
||||||
|
@ -193,7 +196,9 @@ void run(t_env *e)
|
||||||
glutInitWindowPosition(100, 100);
|
glutInitWindowPosition(100, 100);
|
||||||
glutCreateWindow("scop");
|
glutCreateWindow("scop");
|
||||||
|
|
||||||
printf("%ld", e->object.indices.ptr);
|
index_count = e->object.indices.ptr;
|
||||||
|
printf("%ld\n", e->object.indices.ptr);
|
||||||
|
printf("%ld\n", e->object.vertices.ptr);
|
||||||
InitializeGlutCallbacks();
|
InitializeGlutCallbacks();
|
||||||
// Must be done after glut is initialized !
|
// Must be done after glut is initialized !
|
||||||
GLenum res = glewInit();
|
GLenum res = glewInit();
|
||||||
|
|
|
@ -2,8 +2,10 @@
|
||||||
|
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
flat in int vID;
|
flat in int vID;
|
||||||
|
flat in int maxID;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
FragColor = vec4(float(vID) / 42.0, float(vID) / 42.0, float(vID) / 42.0, 1.0);
|
vec3 color = vec3(float(vID) / float(maxID));
|
||||||
|
FragColor = vec4(color, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,15 @@ uniform float gScale;
|
||||||
uniform mat4 view;
|
uniform mat4 view;
|
||||||
uniform mat4 proj;
|
uniform mat4 proj;
|
||||||
uniform mat4 model;
|
uniform mat4 model;
|
||||||
|
uniform int icount;
|
||||||
|
|
||||||
flat out int vID;
|
flat out int vID;
|
||||||
|
flat out int maxID;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = proj * view * model * vec4(Position, 1.0);
|
gl_Position = proj * view * model * vec4(Position, 1.0);
|
||||||
// gl_Position = vec4(gScale * Position.x,gScale * Position.y, gScale * Position.z, 1.0);
|
// gl_Position = vec4(gScale * Position.x,gScale * Position.y, gScale * Position.z, 1.0);
|
||||||
vID = gl_VertexID;
|
vID = gl_VertexID;
|
||||||
|
maxID = icount;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue