3/6/2024 0 Comments Glsl tessellation exampleflip buffer # ) buffer # ))) ( def-make-buffer make-float-buffer BufferUtils/createFloatBuffer ) ( def-make-buffer make-int-buffer BufferUtils/createIntBuffer ) ( Display/setTitle "mini" ) ( Display/setDisplayMode ( DisplayMode. ( GL20/glGetProgramInfoLog program 1024 )))) program )) ( defmacro def-make-buffer ` ( defn ~ method ( let (. ( GL20/glGetShaderInfoLog shader 1024 )))) shader )) ( defn make-program ( let ( doseq ( GL20/glAttachShader program shader )) ( GL20/glLinkProgram program ) ( if ( zero? ( GL20/glGetProgrami program GL20/GL_LINK_STATUS )) ( throw ( Exception. }" ) ( def vertices ( float-array )) ( def indices ( int-array )) ( def pixels ( float-array )) ( defn make-shader ( let ( GL20/glShaderSource shader source ) ( GL20/glCompileShader shader ) ( if ( zero? ( GL20/glGetShaderi shader GL20/GL_COMPILE_STATUS )) ( throw ( Exception. }" ) ( def fragment-source "#version 410 core Layout(triangle_strip, max_vertices = 3) out Texcoord_geo = mix(c, d, gl_TessCoord.y) Vec2 d = mix(texcoord_tes, texcoord_tes, gl_TessCoord.x) Vec2 c = mix(texcoord_tes, texcoord_tes, gl_TessCoord.x) Vec4 b = mix(gl_in.gl_Position, gl_in.gl_Position, gl_TessCoord.x) Vec4 a = mix(gl_in.gl_Position, gl_in.gl_Position, gl_TessCoord.x) See code below: ( ns tessellation-opengl ( :import )) ( def vertex-source "#version 410 core The polygon mode was switched to display lines only so that one can observe how the triangle is split up. The example not only shows how to set the tessellation level but it also shows how one can pass through texture coordinates. The example uses several shaders required when doing tessellation using OpenGL: The example is implemented in Clojure but could be easily ported to C if you prefer. I didn’t find any small single-page code examples for tessellation shaders, so I decided to publish one here. Watching the videos I realised that I should investigate tessellation shaders. I found an impressive free software called the Oreon Engine which is implemented in Java. My motivation is to implement a space flight game, which requires rendering of planetary bodies. The example was implemented using LWJGL version 2 (see LWJGL Wiki for documentation). Last week I published a minimal OpenGL example in Clojure. Tessellation OpenGL example using Clojure and LWJGL
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |