1414 [org.lwjgl BufferUtils]
1515 [org.lwjgl.glfw GLFW]
1616 [org.lwjgl.opengl GL GL11 GL13 GL15 GL20 GL30]
17- [org.lwjgl.stb STBImage STBImageWrite]))
17+ [org.lwjgl.stb STBImageWrite]))
1818
1919; ; ## Getting dependencies
2020; ;
3333; ; (import '[javax.imageio ImageIO]
3434; ; '[org.lwjgl BufferUtils]
3535; ; '[org.lwjgl.glfw GLFW]
36- ; ; '[org.lwjgl.opengl GL GL11 GL15 GL20 GL30]
36+ ; ; '[org.lwjgl.opengl GL GL11 GL13 GL15 GL20 GL30]
3737; ; '[org.lwjgl.stb STBImageWrite])
3838; ; ```
3939
@@ -237,34 +237,28 @@ void main()
237237(when (not (.exists (io/file moon-tif)))
238238 (download " https://svs.gsfc.nasa.gov/vis/a000000/a004700/a004720/lroc_color_poles_2k.tif" moon-tif))
239239
240- ; ; Use ImageIO to convert it to PNG
241- (def moon-png " src/opengl_visualization/lroc_color_poles_2k.png" )
242- (when (not (.exists (io/file moon-png)))
243- (ImageIO/write (ImageIO/read (io/file moon-tif)) " png" (io/file moon-png)))
244-
245240; ; ### Create a texture
246241; ;
247242; ; Loading the image
248- (do
249- (def color-width ( int-array 1 ))
250- (def color-height ( int-array 1 ))
251- (def color-channels ( int-array 1 ))
252- (def color-buffer ( STBImage/stbi_load moon-png color-width color-height color-channels 4 ) ))
253- (aget color-width 0 )
254- (aget color-height 0 )
243+ (def color ( ImageIO/read ( io/file moon-tif)))
244+ (def color-raster ( .getRaster color ))
245+ (def color-width ( .getWidth color-raster ))
246+ (def color-height ( .getHeight color-raster ))
247+ (def color-channels ( .getNumBands color-raster ))
248+ (def color-pixels ( int-array ( * color- width color-height color-channels)) )
249+ (do ( .getPixels color-raster 0 0 color-width color-height color-pixels) nil )
255250
256251; ; Set up the color texture.
257252(do
258253 (def texture-color (GL11/glGenTextures ))
259254 (GL11/glBindTexture GL11/GL_TEXTURE_2D texture-color)
260- (GL11/glTexImage2D GL11/GL_TEXTURE_2D 0 GL11/GL_RGBA ( aget color-width 0 ) ( aget color-height 0 )
261- 0 GL11/GL_RGBA GL11/GL_UNSIGNED_BYTE color- buffer)
255+ (GL11/glTexImage2D GL11/GL_TEXTURE_2D 0 GL11/GL_RGBA color-width color-height 0
256+ GL11/GL_RGB GL11/GL_UNSIGNED_BYTE ( make-byte- buffer ( byte-array ( map unchecked-byte color-pixels))) )
262257 (GL11/glTexParameteri GL11/GL_TEXTURE_2D GL11/GL_TEXTURE_MIN_FILTER GL11/GL_LINEAR)
263258 (GL11/glTexParameteri GL11/GL_TEXTURE_2D GL11/GL_TEXTURE_MAG_FILTER GL11/GL_LINEAR)
264259 (GL11/glTexParameteri GL11/GL_TEXTURE_2D GL11/GL_TEXTURE_WRAP_S GL11/GL_REPEAT)
265260 (GL11/glTexParameteri GL11/GL_TEXTURE_2D GL11/GL_TEXTURE_WRAP_T GL11/GL_REPEAT)
266- (GL11/glBindTexture GL11/GL_TEXTURE_2D 0 )
267- (STBImage/stbi_image_free color-buffer))
261+ (GL11/glBindTexture GL11/GL_TEXTURE_2D 0 ))
268262
269263; ; ### Rendering the texture
270264(def vertex-tex "
@@ -579,11 +573,11 @@ void main()
579573
580574; ; The image is read using ImageIO and the floating point elevation data is extracted.
581575(def ldem (ImageIO/read (io/file moon-ldem)))
582- (def raster (.getRaster ldem))
576+ (def ldem- raster (.getRaster ldem))
583577(def ldem-width (.getWidth ldem))
584578(def ldem-height (.getHeight ldem))
585- (def pixels (float-array (* ldem-width ldem-height)))
586- (do (.getPixels raster 0 0 ldem-width ldem-height pixels) nil )
579+ (def ldem- pixels (float-array (* ldem-width ldem-height)))
580+ (do (.getPixels ldem- raster 0 0 ldem-width ldem-height ldem- pixels) nil )
587581(def resolution (/ (* 2.0 PI radius) ldem-width))
588582
589583; ; The floating point pixel data is converted into a texture
@@ -594,7 +588,7 @@ void main()
594588 (GL11/glTexParameteri GL11/GL_TEXTURE_2D GL11/GL_TEXTURE_MAG_FILTER GL11/GL_LINEAR)
595589 (GL11/glTexParameteri GL11/GL_TEXTURE_2D GL11/GL_TEXTURE_WRAP_S GL11/GL_REPEAT)
596590 (GL11/glTexParameteri GL11/GL_TEXTURE_2D GL11/GL_TEXTURE_WRAP_T GL11/GL_REPEAT)
597- (GL11/glTexImage2D GL11/GL_TEXTURE_2D 0 GL30/GL_R32F ldem-width ldem-height 0 GL11/GL_RED GL11/GL_FLOAT pixels))
591+ (GL11/glTexImage2D GL11/GL_TEXTURE_2D 0 GL30/GL_R32F ldem-width ldem-height 0 GL11/GL_RED GL11/GL_FLOAT ldem- pixels))
598592
599593; ; ### Create shader program with normal mapping
600594(def vertex-normal "
0 commit comments