chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] OpenGL on MinGW


From: Brandon J. Van Every
Subject: [Chicken-users] OpenGL on MinGW
Date: Sun, 24 Sep 2006 11:06:31 -0700
User-agent: Thunderbird 1.5.0.7 (Windows/20060909)

I just want to make note of the status of OpenGL on MinGW.

- chicken-setup opengl fails with:

. "E:\Program Files\Chicken\bin\csc" -feature compiling-extension gl.scm -s -O2
-d0 -L "-L/usr/X11R6/lib -L/usr/X11/lib -lGL -LX11"
'E:\Program' is not recognized as an internal or external command,
operable program or batch file.
make: Failed to make gl.so: shell invocation failed with non-zero return status
Error: shell invocation failed with non-zero return status
"\"E:\\Program Files\\Chicken\\bin\\csc\" -feature compiling-extension gl.scm -.
..
1

- in opengl.egg-dir, if opengl.setup is replaced with the attached file, then chicken-setup opengl succeeds. Thanks Felix for this file. - I modified the attached opengl.setup file to remove GLUT support. GLUT is ancient. The last official release of GLUT was in 1998, it is unsupported, and the license does not allow modifications of the source code to be distributed. FreeGLUT is more recent, dating to 2005, but it didn't compile on MinGW. GLUT should not be assumed to be available or maintained on all platforms. As such, it needs to be moved to its own egg.


- the attached sdl-gears.scm demo (thanks again from Felix) will compile with the following build command. It then runs just fine, proving that the opengl support works.
 csc sdl-gears.scm -C `sdl-config --cflags` -L "`sdl-config --libs`"

- the build fails with:

 csc sdl-gears.scm -C "`sdl-config --cflags`" -L "`sdl-config --libs`"

There is a problem with -C and quoting the resultant -I/usr/local/include option.


Cheers,
Brandon Van Every

;;;; opengl.setup -*- Scheme -*-

(cond
 ((eq? (software-version) 'macosx)
  (make (("gl.so" ("gl.scm") (compile gl.scm -s -O2 -d0 -FOpenGL -framework 
OpenGL))
         ("glu.so" ("glu.scm") (compile -s glu.scm -O2 -d0 -FOpenGL -framework 
OpenGL))
         )
    '#("gl.so" "glu.so") ))
 ((and (eq? (software-type) 'windows) (eq? (build-platform) 'msvc))
  (make (("gl.dll" ("gl.scm") (compile -s -feature msvc gl.scm glprocs.c -O2 
-d0 -lopengl32 -C "/Iglprocs"))
         ("glu.dll" ("glu.scm") (compile -s -feature msvc 
-emit-external-prototypes-first glu.scm -O2 -d0 -lglu32 -C "/Iglprocs"))
         )
    '#("gl.dll" "glu.dll")))
 ((eq? (software-type) 'windows) 
  (make (("gl.so" ("gl.scm") (compile -s -feature cygwin gl.scm -O2 -d0 
-lopengl32))
         ("glu.so" ("glu.scm") (compile -s -feature cygwin glu.scm -O2 -d0 
-lopengl32 -lglu32))
         )
    '#("gl.so" "glu.so") ))
 (else
  (make (("gl.so" ("gl.scm") (compile gl.scm -s -O2 -d0 -L "\"-L/usr/X11R6/lib 
-L/usr/X11/lib -lGL -LX11\""))
         ("glu.so" ("glu.scm") (compile -s glu.scm -O2 -d0 -L 
"\"-L/usr/X11R6/lib -L/usr/X11/lib -lGLU -LX11\""))
         )
    '#("gl.so" "glu.so") ) ))

(install-extension 
 'gl
 '("gl.so" "glu.so") )
;; $Id: gears.ss,v 1.36 2002/12/10 06:19:48 neil Exp $
;;
;; This is a version of the venerable "gears" demo for PLT Scheme 200 using
;; Scott Owens' SGL OpenGL bindings.  It was ported from "glxgears.c" 1.3 from
;; XFree86, which had the following notices:
;;
;;     Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
;;
;;     Permission is hereby granted, free of charge, to any person obtaining a
;;     copy of this software and associated documentation files (the
;;     "Software"), to deal in the Software without restriction, including
;;     without limitation the rights to use, copy, modify, merge, publish,
;;     distribute, sublicense, and/or sell copies of the Software, and to
;;     permit persons to whom the Software is furnished to do so, subject to
;;     the following conditions:
;;
;;     The above copyright notice and this permission notice shall be included
;;     in all copies or substantial portions of the Software.
;;
;;     XFree86: xc/programs/glxgears/glxgears.c,v 1.3 2001/11/03 17:29:20 dawes
;;
;;     This is a port of the infamous "gears" demo to straight GLX (i.e. no
;;     GLUT).  Port by Brian Paul 23 March 2001.
;;
;; To run, evaluate this file in DrScheme, or execute "mred -r gears.ss"
;; from your OS shell.  If your version of SGL is missing "gl:End-list", then
;; add a line "void glEndList( void );" to file "collects/sgl/gl-specs/gl11.h",
;; and execute "setup-plt -l sgl".
;;
;; Scheme port by Neil W. Van Dyke <address@hidden>, 23 November 2002.
;; Originally called glxgears.ss.  Minor modifications since.
;; See "http://www.neilvandyke.org/opengl-plt/"; for more information.
;;
;; Ported to Chicken by Felix L. Winkelmann

#>
#include <SDL.h>

static SDL_Surface *screen;
<#

(require-extension srfi-4 gl)

(define pi 3.14)

(define rotation 0.0)

(define view-rotx 20.0)
(define view-roty 30.0)
(define view-rotz 0.0)

(define gear1 #f)
(define gear2 #f)
(define gear3 #f)

(define step? #f)

(define (refresh)
  (set! step? #t))

(define (move-left)
  (set! view-roty (+ view-roty 5.0)))

(define (move-right)
  (set! view-roty (- view-roty 5.0)))

(define (move-up)
  (set! view-rotx (+ view-rotx 5.0)))

(define (move-down)
  (set! view-rotx (- view-rotx 5.0)))

(define (build-gear inner-radius    ; radius of hole at center
                    outer-radius    ; radius at center of teeth
                    width           ; width of gear
                    teeth           ; number of teeth
                    tooth-depth)    ; depth of tooth
  (let* ((r0             inner-radius)
         (r1             (- outer-radius (/ tooth-depth 2.0)))
         (r2             (+ outer-radius (/ tooth-depth 2.0)))
         (da             (/ (* 2.0 pi) teeth 4.0))
         (da2            (* da 2))
         (da3            (* da 3))
         (half-width     (* width 0.5))
         (neg-half-width (- half-width)))

    ;; TODO: Generalize away some more redundant program text.

    (gl:ShadeModel gl:FLAT)

    (gl:Normal3f 0.0 0.0 1.0)

    ;; Draw front face.
    (gl:Begin gl:QUAD_STRIP)
    (do ((i 0 (+ 1 i))) ((> i teeth))
      (let* ((angle     (/ (* i 2.0 pi) teeth))
             (cos-angle (cos angle))
             (sin-angle (sin angle)))
        (gl:Vertex3f (* r0 cos-angle) (* r0 sin-angle) half-width)
        (gl:Vertex3f (* r1 cos-angle) (* r1 sin-angle) half-width)
        (when (< i teeth)
          (gl:Vertex3f (* r0 cos-angle)
                       (* r0 sin-angle)
                       (* half-width))
          (gl:Vertex3f (* r1 (cos (+ angle da3)))
                       (* r1 (sin (+ angle da3)))
                       half-width))))
    (gl:End)

    ;; Draw front sides of teeth.
    (gl:Begin gl:QUADS)
    (do ((i 0 (+ 1 i))) ((= i teeth))
      (let ((angle (/ (* i 2.0 pi) teeth)))
        (gl:Vertex3f (* r1 (cos angle))
                     (* r1 (sin angle))
                     half-width)
        (gl:Vertex3f (* r2 (cos (+ angle da)))
                     (* r2 (sin (+ angle da)))
                     half-width)
        (gl:Vertex3f (* r2 (cos (+ angle da2)))
                     (* r2 (sin (+ angle da2)))
                     half-width)
        (gl:Vertex3f (* r1 (cos (+ angle da3)))
                     (* r1 (sin (+ angle da3)))
                     half-width)))
    (gl:End)

    (gl:Normal3f 0.0 0.0 -1.0)

    ;; Draw back face.
    (gl:Begin gl:QUAD_STRIP)
    (do ((i 0 (+ 1 i))) ((> i teeth))
      (let* ((angle     (/ (* i 2.0 pi) teeth))
             (cos-angle (cos angle))
             (sin-angle (sin angle)))
        (gl:Vertex3f (* r1 cos-angle) (* r1 sin-angle) neg-half-width)
        (gl:Vertex3f (* r0 cos-angle) (* r0 sin-angle) neg-half-width)
        (when (< i teeth)
          (gl:Vertex3f (* r1 (cos (+ angle da3)))
                       (* r1 (sin (+ angle da3)))
                       neg-half-width)
          (gl:Vertex3f (* r0 cos-angle)
                       (* r0 sin-angle)
                       neg-half-width))))
    (gl:End)

    ;; Draw back sides of teeth.
    (gl:Begin gl:QUADS)
    (do ((i 0 (+ 1 i))) ((= i teeth))
      (let ((angle (/ (* i 2.0 pi) teeth)))
        (gl:Vertex3f (* r1 (cos (+ angle da3)))
                     (* r1 (sin (+ angle da3)))
                     neg-half-width)
        (gl:Vertex3f (* r2 (cos (+ angle da2)))
                     (* r2 (sin (+ angle da2)))
                     neg-half-width)
        (gl:Vertex3f (* r2 (cos (+ angle da)))
                     (* r2 (sin (+ angle da)))
                     neg-half-width)
        (gl:Vertex3f (* r1 (cos angle))
                     (* r1 (sin angle))
                     neg-half-width)))
    (gl:End)

    ;; Draw outward faces of teeth.
    (gl:Begin gl:QUAD_STRIP)
    (do ((i 0 (+ 1 i))) ((= i teeth))
      (let* ((angle     (/ (* i 2.0 pi) teeth))
             (cos-angle (cos angle))
             (sin-angle (sin angle)))

        (gl:Vertex3f (* r1 cos-angle) (* r1 sin-angle) half-width)
        (gl:Vertex3f (* r1 cos-angle) (* r1 sin-angle) neg-half-width)

        (let* ((u   (- (* r2 (cos (+ angle da))) (* r1 cos-angle)))
               (v   (- (* r2 (sin (+ angle da))) (* r1 sin-angle)))
               (len (sqrt (+ (* u u) (* v v)))))
          (gl:Normal3f (/ v len) (- (/ u len)) 0.0))

        (gl:Vertex3f (* r2 (cos (+ angle da)))
                     (* r2 (sin (+ angle da)))
                     half-width)
        (gl:Vertex3f (* r2 (cos (+ angle da)))
                     (* r2 (sin (+ angle da)))
                     neg-half-width)
        (gl:Normal3f cos-angle sin-angle 0.0)
        (gl:Vertex3f (* r2 (cos (+ angle da2)))
                     (* r2 (sin (+ angle da2)))
                     half-width)
        (gl:Vertex3f (* r2 (cos (+ angle da2)))
                     (* r2 (sin (+ angle da2)))
                     neg-half-width)

        (let ((u (- (* r1 (cos (+ angle da3)))
                    (* r2 (cos (+ angle da2)))))
              (v (- (* r1 (sin (+ angle da3)))
                    (* r2 (sin (+ angle da2))))))
          (gl:Normal3f v (- u) 0.0))

        (gl:Vertex3f (* r1 (cos (+ angle da3)))
                     (* r1 (sin (+ angle da3)))
                     half-width)
        (gl:Vertex3f (* r1 (cos (+ angle da3)))
                     (* r1 (sin (+ angle da3)))
                     neg-half-width)
        (gl:Normal3f cos-angle sin-angle 0.0)))

    (gl:Vertex3f (* r1 (cos 0)) (* r1 (sin 0)) half-width)
    (gl:Vertex3f (* r1 (cos 0)) (* r1 (sin 0)) neg-half-width)
    (gl:End)

    (gl:ShadeModel gl:SMOOTH)

    ;; Draw inside radius cylinder.
    (gl:Begin gl:QUAD_STRIP)
    (do ((i 0 (+ 1 i))) ((> i teeth))
      (let* ((angle     (/ (* i 2.0 pi) teeth))
             (cos-angle (cos angle))
             (sin-angle (sin angle)))
        (gl:Normal3f (- cos-angle) (- sin-angle) 0.0)
        (gl:Vertex3f (* r0 cos-angle) (* r0 sin-angle) neg-half-width)
        (gl:Vertex3f (* r0 cos-angle) (* r0 sin-angle) half-width)))
    (gl:End)))

(define (on-size width height)
  (gl:Viewport 0 0 width height)
  (gl:MatrixMode gl:PROJECTION)
  (gl:LoadIdentity)
  (let ((h (/ height width)))
    (gl:Frustum -1.0 1.0 (- h) h 5.0 60.0))
  (gl:MatrixMode gl:MODELVIEW)
  (gl:LoadIdentity)
  (gl:Translatef 0.0 0.0 -40.0)

  (gl:Lightfv gl:LIGHT0 gl:POSITION (f32vector 5.0 5.0 10.0 0.0))
  (gl:Enable gl:CULL_FACE)
  (gl:Enable gl:LIGHTING)
  (gl:Enable gl:LIGHT0)
  (gl:Enable gl:DEPTH_TEST)

  (unless gear1

    (set! gear1 (gl:GenLists 1))
    (gl:NewList gear1 gl:COMPILE)
    (gl:Materialfv gl:FRONT
                   gl:AMBIENT_AND_DIFFUSE
                   (f32vector 0.8 0.1 0.0 1.0))
    (build-gear 1.0 4.0 1.0 20 0.7)
    (gl:EndList)

    (set! gear2 (gl:GenLists 1))
    (gl:NewList gear2 gl:COMPILE)
    (gl:Materialfv gl:FRONT
                   gl:AMBIENT_AND_DIFFUSE
                   (f32vector 0.0 0.8 0.2 1.0))
    (build-gear 0.5 2.0 2.0 10 0.7)
    (gl:EndList)

    (set! gear3 (gl:GenLists 1))
    (gl:NewList gear3 gl:COMPILE)
    (gl:Materialfv gl:FRONT
                   gl:AMBIENT_AND_DIFFUSE
                   (f32vector 0.2 0.2 1.0 1.0))
    (build-gear 1.3 2.0 0.5 10 0.7)
    (gl:EndList)

    (gl:Enable gl:NORMALIZE)) )

(define (on-paint)
  ;; TODO: Add FPS instrumentation.
  (when step?
    ;; TODO: Don't increment this infinitely.
    (set! rotation (+ 2.0 rotation)))

  (gl:Clear (+ gl:COLOR_BUFFER_BIT gl:DEPTH_BUFFER_BIT))
  
  (gl:PushMatrix)
  (gl:Rotatef view-rotx 1.0 0.0 0.0)
  (gl:Rotatef view-roty 0.0 1.0 0.0)
  (gl:Rotatef view-rotz 0.0 0.0 1.0)

  (gl:PushMatrix)
  (gl:Translatef -3.0 -2.0 0.0)
  (gl:Rotatef rotation 0.0 0.0 1.0)
  (gl:CallList gear1)
  (gl:PopMatrix)

  (gl:PushMatrix)
  (gl:Translatef 3.1 -2.0 0.0)
  (gl:Rotatef (- (* -2.0 rotation) 9.0) 0.0 0.0 1.0)
  (gl:CallList gear2)
  (gl:PopMatrix)

  (gl:PushMatrix)
  (gl:Translatef -3.1 4.2 0.0)
  (gl:Rotatef (- (* -2.0 rotation) 25.0) 0.0 0.0 1.0)
  (gl:CallList gear3)
  (gl:PopMatrix)

  (gl:PopMatrix)
  ((foreign-lambda void "SDL_GL_SwapBuffers")) )

(foreign-code 
 "SDL_Init(SDL_INIT_VIDEO);
 screen = SDL_SetVideoMode(300, 300, 16, SDL_OPENGL|SDL_RESIZABLE);")

(on-size (foreign-value "screen->w" int) (foreign-value "screen->h" int))

(gl:ClearColor 0.0 0.0 0.0 0)

(define poll
  (foreign-lambda* bool ()
    "SDL_Event event; return(SDL_PollEvent(&event) && event.type == 
SDL_QUIT);"))

(do () ((poll))
  (refresh)
  (on-paint) )

((foreign-lambda void "SDL_Quit"))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]