Hi,<br><br>this is a question about how to run a code in DrRacket which displays a 3D (volumetric) texture in an OpenGL window.<br>Displaying a 2D Texture works beautifully. <br>Displaying a 3D Texture returns an Error:<br>
<br>Racket\collects\sgl\gl.rkt:21:23: glTexImage3D: unavailable on this
system <br>(I`m working on the windows version of DrRacket)<br><br>Does anybody know about the implementation of sgl/gl.rkt in detail ? <br>The problem is, i think, in the following:<br>The following C++ GLUT code works fine on my machine and needs an external
DLL glut32.dll and a dynamic load of the function "glTexImage3D" on the run.<br>
However, Racket\collects\sgl\gl.rkt only creates FFI functions for
C:\Windows\system32\glu32.dll <br>
where the OpenGL extensions are not available in glu32.dll .<br><br>Is there a book, or an example code which could help showing that Racket can do magic with OpenGL in a REPL on volumetric textures ?<br>Backup plan: is there a good book on MZScheme, FFI, dynamic loading of DLL functions ?<br>
(The mzscheme examples in DrRacket don`t seem to work out of the box on Windows)<br><br>I have experience with SBCL and C++, Racket is fairly new to me.<br><br>--------------------<br>Here is what I tried so far:<br><br>
I used and modified the following code by Brendan Burns with modifications by Scott Owens:<br>
<br>C:\Program Files\Racket\collects\sgl\examples\alpha.rkt <br>C:\Program Files\Racket\collects\sgl\examples\gl-frame.rkt<br><br>which displays 2D textures on a cube.<br><br>The following C++ GLUT code works fine on my machine, needs an external DLL glut32.dll.<br>
However, Racket\collects\sgl\gl.rkt only creates FFI functions for C:\Windows\system32\glu32.dll <br>where the OpenGL Extensions are not available.<br>...<br>#include <GL/glext.h><br>...<br> // VERY IMPORTANT:<br>
// this line loads the address of the glTexImage3D function into the function pointer of the same name.<br> // glTexImage3D is not implemented in the standard GL libraries and must be loaded dynamically at run time,<br>
// the environment the program is being run in MAY OR MAY NOT support it, if not we'll get back a NULL pointer.<br> // this is necessary to use any OpenGL function declared in the glext.h header file<br> // the Pointer to FunctioN ... PROC types are declared in the same header file with a type appropriate to the function name<br>
glTexImage3D = (glTexImage3D) wglGetProcAddress("glTexImage3D");<br> if (glTexImage3D == NULL) {<br> printf("Error in line %d: Couldn't load glTexImage3D function. Aborting.\n", __LINE__);<br>
return -1;<br> }<br>...<br><br>The code displays a nice 3D texture on a pyramid.<br><br>Now trying to do the same in DrRacket:<br>;;----------- Code Excerpt for GL_TEXTURE_3D -------------<br>(glEnable GL_3D)<br>
(glEnable GL_TEXTURE_3D)<br>...<br><br>;; --- Create a 3D texture for OpenGL ---<br><br> (define (get-tex3d fname)<br> (let* ((xx 4)<br> (yy 6)<br> (zz 12) <br> (pixels (* xx yy zz))<br>
(vec (make-gl-ubyte-vector (* pixels 3)))<br> (data (make-bytes (* pixels 4)))<br> (i 0)<br> (cr (round (* (/ 255 pixels) 1))) ; color range increment from pixel to pixel<br> )<br>
<br> (letrec<br> ([loop<br> (lambda ()<br> (if (< i pixels)<br> (begin<br> (gl-vector-set! vec (* i 3) (- 255 (round (* cr i))))<br> (gl-vector-set! vec (+ (* i 3) 1) (round (* cr i)))<br>
(gl-vector-set! vec (+ (* i 3) 2) (- 124 (round (* (/ cr 2) i))))<br> (set! i (+ i 1))<br> (loop))))])<br> (loop))<br> (list xx yy zz vec)))<br><br>;; ---------- Try to Load a 3D openGL texture into OpenGL ----------<br>
(define gl-load-texture3d<br> (lambda (image-vector width height depth min-filter mag-filter ix)<br> (glBindTexture GL_TEXTURE_3D (gl-vector-ref *textures* ix))<br> (glTexParameteri GL_TEXTURE_3D GL_TEXTURE_MIN_FILTER min-filter)<br>
(glTexParameteri GL_TEXTURE_3D GL_TEXTURE_MAG_FILTER mag-filter)<br> (let* ((new-img-vec (make-gl-ubyte-vector <br> (* width height depth 3)))<br> ; (new-img-vec image-vector)<br>
) <br> (if (or (= min-filter GL_LINEAR_MIPMAP_NEAREST)<br> (= mag-filter GL_LINEAR_MIPMAP_NEAREST))<br> (gluBuild3DMipmaps GL_TEXTURE_3D 3 width height depth GL_RGB GL_UNSIGNED_BYTE new-img-vec) ;; this is not supported in my Racket ! ? ! <br>
(glTexImage3D GL_TEXTURE_3D 0 3 width height depth 0 GL_RGB GL_UNSIGNED_BYTE new-img-vec) ;; this is not supported in my Racket ! ? !<br> )))<br> )<br><br>;;...<br>;; Perform the 3D Texture Load <br>
(unless (gl-load-texture3d (list-ref res 3) (list-ref res 0) (list-ref res 1) (list-ref res 2) GL_NEAREST GL_NEAREST 0)<br> (error "Couldn't load texture"))<br><br><br>Thank you for your comments.<br>
<br>mosi<br><br><br>