depth test working
This commit is contained in:
parent
f6aff761f9
commit
c86bab2d8a
|
@ -6,7 +6,7 @@
|
|||
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/22 12:08:22 by gbrochar #+# #+# */
|
||||
/* Updated: 2020/12/23 21:55:38 by gbrochar ### ########.fr */
|
||||
/* Updated: 2020/12/24 14:32:38 by gbrochar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/22 18:56:21 by gbrochar #+# #+# */
|
||||
/* Updated: 2020/12/23 21:14:28 by gbrochar ### ########.fr */
|
||||
/* Updated: 2020/12/24 14:32:22 by gbrochar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/23 17:33:33 by gbrochar #+# #+# */
|
||||
/* Updated: 2020/12/24 12:34:38 by gbrochar ### ########.fr */
|
||||
/* Updated: 2020/12/24 14:32:30 by gbrochar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
27
src/run.c
27
src/run.c
|
@ -6,7 +6,7 @@
|
|||
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/23 19:38:05 by gbrochar #+# #+# */
|
||||
/* Updated: 2020/12/24 13:14:32 by gbrochar ### ########.fr */
|
||||
/* Updated: 2020/12/24 14:39:39 by gbrochar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
|||
GLuint VBO;
|
||||
GLuint IBO;
|
||||
GLuint gScaleLocation;
|
||||
GLuint gScaleIntLocation;
|
||||
GLuint gProjLocation;
|
||||
GLuint gViewLocation;
|
||||
GLuint gModelLocation;
|
||||
|
@ -30,7 +31,7 @@ static void RenderSceneCB()
|
|||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
static float Scale = 0.0f;
|
||||
|
||||
Scale += 0.01f;
|
||||
|
@ -41,18 +42,19 @@ static void RenderSceneCB()
|
|||
|
||||
eye.x = 0;
|
||||
eye.y = 0;
|
||||
eye.z = 30;
|
||||
eye.z = 10;
|
||||
up.x = 0;
|
||||
up.y = 1;
|
||||
up.z = 0;
|
||||
target.x = 0;
|
||||
target.y = 0;
|
||||
target.z = 29;
|
||||
|
||||
target.z = 9;
|
||||
|
||||
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 model = mat4_rotatey(mat4_identity(), Scale);
|
||||
//glUniform1f(gScaleLocation, sinf(Scale));
|
||||
t_mat4 model = mat4_rotatey(mat4_rotatex(mat4_identity(), Scale), Scale / 1.3);
|
||||
// glUniform1f(gScaleLocation, sinf(Scale));
|
||||
glUniform1f(gScaleIntLocation, 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);
|
||||
|
@ -63,6 +65,7 @@ static void RenderSceneCB()
|
|||
glVertexAttribPointer(0, 3, GL_DOUBLE, GL_FALSE, 0, 0);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, index_count, GL_UNSIGNED_INT, 0);
|
||||
|
||||
glDisableVertexAttribArray(0);
|
||||
|
@ -172,16 +175,16 @@ static void CompileShaders()
|
|||
|
||||
glUseProgram(ShaderProgram);
|
||||
|
||||
//gScaleLocation = glGetUniformLocation(ShaderProgram, "gScale");
|
||||
// gScaleLocation = glGetUniformLocation(ShaderProgram, "gScale");
|
||||
gScaleIntLocation = glGetUniformLocation(ShaderProgram, "time");
|
||||
gProjLocation = glGetUniformLocation(ShaderProgram, "proj");
|
||||
gViewLocation = glGetUniformLocation(ShaderProgram, "view");
|
||||
gModelLocation = glGetUniformLocation(ShaderProgram, "model");
|
||||
gCountLocation = glGetUniformLocation(ShaderProgram, "icount");
|
||||
//assert(gScaleLocation != 0xFFFFFFFF);
|
||||
// assert(gScaleLocation != 0xFFFFFFFF);
|
||||
assert(gScaleIntLocation != 0xFFFFFFFF);
|
||||
assert(gProjLocation != 0xFFFFFFFF);
|
||||
assert(gViewLocation != 0xFFFFFFFF);
|
||||
assert(gModelLocation != 0xFFFFFFFF);
|
||||
assert(gCountLocation != 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
void run(t_env *e)
|
||||
|
@ -191,7 +194,7 @@ void run(t_env *e)
|
|||
|
||||
argv[0] = strdup("scop");
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
|
||||
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
|
||||
glutInitWindowSize(e->window.width, e->window.height);
|
||||
glutInitWindowPosition(100, 100);
|
||||
glutCreateWindow("scop");
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
#version 330
|
||||
|
||||
uniform float time;
|
||||
|
||||
out vec4 FragColor;
|
||||
flat in int vID;
|
||||
flat in int maxID;
|
||||
|
||||
float rand(float n)
|
||||
{
|
||||
return fract(sin(n) * 43758.5453123);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 color = vec3(float(vID) / float(maxID));
|
||||
vec3 color = vec3(rand(float(vID + int(time))), rand(float(vID + 1 + int(time))), rand(float(vID + 2 + int(time))));
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
||||
|
|
|
@ -6,15 +6,12 @@ uniform float gScale;
|
|||
uniform mat4 view;
|
||||
uniform mat4 proj;
|
||||
uniform mat4 model;
|
||||
uniform int icount;
|
||||
|
||||
flat out int vID;
|
||||
flat out int maxID;
|
||||
|
||||
void main()
|
||||
{
|
||||
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;
|
||||
maxID = icount;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue