matrices not working
This commit is contained in:
parent
01a06b09a1
commit
71c9d90cee
10
inc/mat4.h
10
inc/mat4.h
|
@ -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 20:17:35 by gbrochar ### ########.fr */
|
/* Updated: 2020/12/23 22:05:17 by gbrochar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
||||||
# define MAT4_H
|
# define MAT4_H
|
||||||
|
|
||||||
# include "vec4.h"
|
# include "vec4.h"
|
||||||
|
# include "vec3.h"
|
||||||
# include <math.h>
|
# include <math.h>
|
||||||
|
|
||||||
typedef struct s_mat4 t_mat4;
|
typedef struct s_mat4 t_mat4;
|
||||||
|
@ -43,6 +44,13 @@ t_mat4 mat4_frustrum(
|
||||||
t_persp_tool tool, double near, double far);
|
t_persp_tool tool, double near, double far);
|
||||||
t_mat4 mat4_frustrum_tmp(double x, double y, t_vec4 tool);
|
t_mat4 mat4_frustrum_tmp(double x, double y, t_vec4 tool);
|
||||||
|
|
||||||
|
t_mat4 mat4_lookat(t_vec3 eye, t_vec3 up, t_vec3 target);
|
||||||
|
t_mat4 mat4_lookat_make_mat(
|
||||||
|
t_vec3 x, t_vec3 y, t_vec3 z, t_vec3 eye);
|
||||||
|
t_vec3 mat4_lookat_make_y(t_vec3 x, t_vec3 z);
|
||||||
|
t_vec3 mat4_lookat_make_x(t_vec3 z, t_vec3 up);
|
||||||
|
t_vec3 mat4_lookat_make_z(t_vec3 eye, t_vec3 target);
|
||||||
|
|
||||||
t_mat4 mat4_identity(void);
|
t_mat4 mat4_identity(void);
|
||||||
|
|
||||||
t_mat4 mat4_inverse(t_mat4 m);
|
t_mat4 mat4_inverse(t_mat4 m);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2020/12/22 12:08:22 by gbrochar #+# #+# */
|
/* Created: 2020/12/22 12:08:22 by gbrochar #+# #+# */
|
||||||
/* Updated: 2020/12/23 21:16:08 by gbrochar ### ########.fr */
|
/* Updated: 2020/12/23 21:55:38 by gbrochar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
|
# include <assert.h>
|
||||||
# include <math.h>
|
# include <math.h>
|
||||||
|
|
||||||
# include <GL/glew.h>
|
# include <GL/glew.h>
|
||||||
|
|
42
src/run.c
42
src/run.c
|
@ -6,16 +6,20 @@
|
||||||
/* 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 21:25:26 by gbrochar ### ########.fr */
|
/* Updated: 2020/12/23 22:22:44 by gbrochar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "scop.h"
|
#include "scop.h"
|
||||||
|
#include "mat4.h"
|
||||||
|
#include "vec3.h"
|
||||||
|
|
||||||
GLuint VBO;
|
GLuint VBO;
|
||||||
GLuint IBO;
|
GLuint IBO;
|
||||||
GLuint gScaleLocation;
|
GLuint gScaleLocation;
|
||||||
|
GLuint gProjLocation;
|
||||||
|
GLuint gViewLocation;
|
||||||
|
GLuint gModelLocation;
|
||||||
|
|
||||||
const char* pVSFileName = "src/shader.vs";
|
const char* pVSFileName = "src/shader.vs";
|
||||||
const char* pFSFileName = "src/shader.fs";
|
const char* pFSFileName = "src/shader.fs";
|
||||||
|
@ -28,7 +32,27 @@ static void RenderSceneCB()
|
||||||
|
|
||||||
Scale += 0.01f;
|
Scale += 0.01f;
|
||||||
|
|
||||||
glUniform1f(gScaleLocation, sinf(Scale));
|
t_vec3 eye;
|
||||||
|
t_vec3 up;
|
||||||
|
t_vec3 target;
|
||||||
|
|
||||||
|
eye.x = 0;
|
||||||
|
eye.y = 0;
|
||||||
|
eye.z = 10;
|
||||||
|
up.x = 0;
|
||||||
|
up.y = 1;
|
||||||
|
up.z = 0;
|
||||||
|
target.x = 0;
|
||||||
|
target.y = 0;
|
||||||
|
target.z = 9;
|
||||||
|
|
||||||
|
t_mat4 proj = mat4_perspective(1., 800.0 / 600.0, 0.001, 1000);
|
||||||
|
t_mat4 view = mat4_inverse(mat4_lookat(eye, up, target));
|
||||||
|
t_mat4 model = mat4_identity();
|
||||||
|
//glUniform1f(gScaleLocation, sinf(Scale));
|
||||||
|
glUniformMatrix4fv(gProjLocation, 1, GL_FALSE, (GLfloat *)proj.data);
|
||||||
|
glUniformMatrix4fv(gViewLocation, 1, GL_FALSE, (GLfloat *)view.data);
|
||||||
|
glUniformMatrix4fv(gModelLocation, 1, GL_FALSE, (GLfloat *)model.data);
|
||||||
|
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
@ -121,8 +145,6 @@ static void CompileShaders()
|
||||||
strcat(fs, buffer);
|
strcat(fs, buffer);
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
printf("%s", vs);
|
|
||||||
printf("%s", fs);
|
|
||||||
AddShader(ShaderProgram, vs, GL_VERTEX_SHADER);
|
AddShader(ShaderProgram, vs, GL_VERTEX_SHADER);
|
||||||
AddShader(ShaderProgram, fs, GL_FRAGMENT_SHADER);
|
AddShader(ShaderProgram, fs, GL_FRAGMENT_SHADER);
|
||||||
|
|
||||||
|
@ -149,8 +171,14 @@ static void CompileShaders()
|
||||||
|
|
||||||
glUseProgram(ShaderProgram);
|
glUseProgram(ShaderProgram);
|
||||||
|
|
||||||
gScaleLocation = glGetUniformLocation(ShaderProgram, "gScale");
|
//gScaleLocation = glGetUniformLocation(ShaderProgram, "gScale");
|
||||||
// assert(gScaleLocation != 0xFFFFFFFF);
|
gProjLocation = glGetUniformLocation(ShaderProgram, "proj");
|
||||||
|
gViewLocation = glGetUniformLocation(ShaderProgram, "view");
|
||||||
|
gModelLocation = glGetUniformLocation(ShaderProgram, "model");
|
||||||
|
//assert(gScaleLocation != 0xFFFFFFFF);
|
||||||
|
assert(gProjLocation != 0xFFFFFFFF);
|
||||||
|
assert(gViewLocation != 0xFFFFFFFF);
|
||||||
|
assert(gModelLocation != 0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
void run(t_env *e)
|
void run(t_env *e)
|
||||||
|
|
|
@ -3,11 +3,15 @@
|
||||||
layout (location = 0) in vec3 Position;
|
layout (location = 0) in vec3 Position;
|
||||||
|
|
||||||
uniform float gScale;
|
uniform float gScale;
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 proj;
|
||||||
|
uniform mat4 model;
|
||||||
|
|
||||||
flat out int vID;
|
flat out int vID;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = vec4(gScale * Position.x,gScale * Position.y, gScale * Position.z, 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);
|
||||||
vID = gl_VertexID;
|
vID = gl_VertexID;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue