Skip to content

Commit 59f2218

Browse files
committed
Do not use depth buffer
1 parent 44416ba commit 59f2218

1 file changed

Lines changed: 21 additions & 25 deletions

File tree

src/opengl_visualization/main.clj

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@
7070
(def window
7171
(do
7272
(GLFW/glfwDefaultWindowHints)
73-
(GLFW/glfwWindowHint GLFW/GLFW_DEPTH_BITS 24)
74-
(GLFW/glfwWindowHint GLFW/GLFW_STENCIL_BITS 8)
7573
(GLFW/glfwWindowHint GLFW/GLFW_VISIBLE GLFW/GLFW_FALSE)
7674
(GLFW/glfwCreateWindow window-width window-height "Invisible Window" 0 0)))
7775

@@ -96,8 +94,7 @@
9694
;; A simple test is to set a clear color, clear depth, and clear the window.
9795
(do
9896
(GL11/glClearColor 1.0 0.5 0.25 1.0)
99-
(GL11/glClearDepth 0.0)
100-
(GL11/glClear (bit-or GL11/GL_COLOR_BUFFER_BIT GL11/GL_DEPTH_BUFFER_BIT))
97+
(GL11/glClear GL11/GL_COLOR_BUFFER_BIT)
10198
(screenshot))
10299

103100
;; ### Creating shader programs
@@ -346,18 +343,16 @@ in vec3 point;
346343
out vec3 vpoint;
347344
void main()
348345
{
349-
// Rotate by alpha around y axis
350-
vec3 ps = vec3(point.x * cos(alpha) - point.z * sin(alpha), point.y, point.x * sin(alpha) + point.z * cos(alpha));
351-
// Rotate by beta around x axis
352-
vec3 pss = vec3(ps.x, ps.y * cos(beta) - ps.z * sin(beta), ps.y * sin(beta) + ps.z * cos(beta));
353-
// Translate
354-
vec3 psss = pss + vec3(0, 0, distance);
355-
// Projection
346+
// Rotate and translate vertex
347+
mat3 rot_y = mat3(vec3(cos(alpha), 0, sin(alpha)), vec3(0, 1, 0), vec3(-sin(alpha), 0, cos(alpha)));
348+
mat3 rot_x = mat3(vec3(1, 0, 0), vec3(0, cos(beta), -sin(beta)), vec3(0, sin(beta), cos(beta)));
349+
vec3 p = rot_x * rot_y * point + vec3(0, 0, distance);
350+
// Project vertex creating normalized device coordinates
356351
float f = 1.0 / tan(fov / 2.0);
357352
float aspect = iResolution.x / iResolution.y;
358-
float proj_x = psss.x / psss.z * f;
359-
float proj_y = psss.y / psss.z * f * aspect;
360-
float proj_z = psss.z / (2.0 * distance);
353+
float proj_x = p.x / p.z * f;
354+
float proj_y = p.y / p.z * f * aspect;
355+
float proj_z = p.z / (2.0 * distance);
361356
gl_Position = vec4(proj_x, proj_y, proj_z, 1);
362357
vpoint = point;
363358
}")
@@ -391,8 +386,8 @@ void main()
391386
(GL20/glUseProgram program-moon)
392387
(GL20/glUniform2f (GL20/glGetUniformLocation program-moon "iResolution") window-width window-height)
393388
(GL20/glUniform1f (GL20/glGetUniformLocation program-moon "fov") (to-radians 25.0))
394-
(GL20/glUniform1f (GL20/glGetUniformLocation program-moon "alpha") (to-radians -30.0))
395-
(GL20/glUniform1f (GL20/glGetUniformLocation program-moon "beta") (to-radians 20.0))
389+
(GL20/glUniform1f (GL20/glGetUniformLocation program-moon "alpha") (to-radians 30.0))
390+
(GL20/glUniform1f (GL20/glGetUniformLocation program-moon "beta") (to-radians -20.0))
396391
(GL20/glUniform1f (GL20/glGetUniformLocation program-moon "distance") 10.0)
397392
(GL20/glUniform1i (GL20/glGetUniformLocation program-moon "moon") 0)
398393
(GL13/glActiveTexture GL13/GL_TEXTURE0)
@@ -403,8 +398,7 @@ void main()
403398
(GL11/glEnable GL11/GL_CULL_FACE)
404399
(GL11/glCullFace GL11/GL_BACK)
405400
(GL11/glClearColor 0.0 0.0 0.0 1.0)
406-
(GL11/glClearDepth 1.0)
407-
(GL11/glClear (bit-or GL11/GL_COLOR_BUFFER_BIT GL11/GL_DEPTH_BUFFER_BIT))
401+
(GL11/glClear GL11/GL_COLOR_BUFFER_BIT)
408402
(GL11/glDrawElements GL11/GL_QUADS (count indices-cube) GL11/GL_UNSIGNED_INT 0)
409403
(screenshot))
410404

@@ -449,7 +443,7 @@ v-vectors
449443
(GL20/glEnableVertexAttribArray 0))
450444

451445
(do
452-
(GL11/glClear (bit-or GL11/GL_COLOR_BUFFER_BIT GL11/GL_DEPTH_BUFFER_BIT))
446+
(GL11/glClear GL11/GL_COLOR_BUFFER_BIT)
453447
(GL11/glDrawElements GL11/GL_QUADS (count indices-sphere) GL11/GL_UNSIGNED_INT 0)
454448
(screenshot))
455449

@@ -465,7 +459,7 @@ v-vectors
465459
(GL20/glEnableVertexAttribArray 0))
466460

467461
(do
468-
(GL11/glClear (bit-or GL11/GL_COLOR_BUFFER_BIT GL11/GL_DEPTH_BUFFER_BIT))
462+
(GL11/glClear GL11/GL_COLOR_BUFFER_BIT)
469463
(GL11/glDrawElements GL11/GL_QUADS (count indices-sphere-2) GL11/GL_UNSIGNED_INT 0)
470464
(screenshot))
471465

@@ -502,20 +496,20 @@ void main()
502496
(do
503497
(GL20/glUseProgram program-diffuse)
504498
(GL20/glUniform2f (GL20/glGetUniformLocation program-diffuse "iResolution") window-width window-height)
505-
(GL20/glUniform1f (GL20/glGetUniformLocation program-diffuse "fov") (to-radians 25.0))
499+
(GL20/glUniform1f (GL20/glGetUniformLocation program-diffuse "fov") (to-radians 20.0))
506500
(GL20/glUniform1f (GL20/glGetUniformLocation program-diffuse "alpha") (to-radians 0.0))
507501
(GL20/glUniform1f (GL20/glGetUniformLocation program-diffuse "beta") (to-radians 0.0))
508502
(GL20/glUniform1f (GL20/glGetUniformLocation program-diffuse "distance") 10.0)
509-
(GL20/glUniform1f (GL20/glGetUniformLocation program-diffuse "ambient") 0.2)
510-
(GL20/glUniform1f (GL20/glGetUniformLocation program-diffuse "diffuse") 0.8)
503+
(GL20/glUniform1f (GL20/glGetUniformLocation program-diffuse "ambient") 0.0)
504+
(GL20/glUniform1f (GL20/glGetUniformLocation program-diffuse "diffuse") 1.0)
511505
(GL20/glUniform3f (GL20/glGetUniformLocation program-diffuse "light") (light 0) (light 1) (light 2))
512506
(GL20/glUniform1i (GL20/glGetUniformLocation program-diffuse "moon") 0)
513507
(GL13/glActiveTexture GL13/GL_TEXTURE0)
514508
(GL11/glBindTexture GL11/GL_TEXTURE_2D texture))
515509

516510
;; Enable backface culling and render.
517511
(do
518-
(GL11/glClear (bit-or GL11/GL_COLOR_BUFFER_BIT GL11/GL_DEPTH_BUFFER_BIT))
512+
(GL11/glClear GL11/GL_COLOR_BUFFER_BIT)
519513
(GL11/glDrawElements GL11/GL_QUADS (count indices-sphere-2) GL11/GL_UNSIGNED_INT 0)
520514
(screenshot))
521515

@@ -526,7 +520,9 @@ void main()
526520
;; Delete the texture
527521
(GL11/glDeleteTextures texture)
528522

529-
;; ### Finalizing GLFW
523+
;; ### Using normal mapping
524+
525+
;; ## Finalizing GLFW
530526
;;
531527
;; When we are finished, we destroy the window.
532528
(GLFW/glfwDestroyWindow window)

0 commit comments

Comments
 (0)