[racket] opengl hello world

From: Laurent (laurent.orseau at gmail.com)
Date: Sun Oct 24 03:15:22 EDT 2010

This following code is from Jay IIRC :

#lang racket/gui

(require (lib "gl.ss" "sgl")
         (lib "gl-vectors.ss" "sgl")
)


(define (resize w h)
  (glViewport 0 0 w h)
  #t
)

(define (draw-opengl)
  (glClearColor 0.0 0.0 0.0 0.0)
  (glClear GL_COLOR_BUFFER_BIT)
  (glColor3d 1.0 1.0 1.0)

  (glMatrixMode GL_PROJECTION)
  (glLoadIdentity)
  (glOrtho 0.0 1.0 0.0 1.0 -1.0 1.0)
  (glMatrixMode GL_MODELVIEW)
  (glLoadIdentity)

  (glBegin GL_QUADS)
  (glVertex3d 0.25 0.25 0.0)
  (glVertex3d 0.75 0.25 0.0)
  (glVertex3d 0.75 0.75 0.0)
  (glVertex3d 0.25 0.75 0.0)
  (glEnd)
)


(define my-canvas%
  (class* canvas% ()
    (inherit with-gl-context swap-gl-buffers)

   (define/override (on-paint)
      (with-gl-context
        (lambda ()
          (draw-opengl)
          (swap-gl-buffers)
        )
      )
    )

    (define/override (on-size width height)
      (with-gl-context
        (lambda ()
          (resize width height)
        )
      )
    )

    (super-instantiate () (style '(gl)))
  )
)

(define win (new frame% (label "OpenGl Test") (min-width 200) (min-height
200)))
(define gl  (new my-canvas% (parent win)))

(send win show #t)



It should be pretty easy to tweak it.

Hope this helps,
Laurent


On Sun, Oct 24, 2010 at 01:35, 김태윤 <kty1104 at gmail.com> wrote:

> thank you for your suggestion
> since I am a beginner, the code is pretty big for me
> is there any hello world level code?
>
> thanks in advanced
>
> 2010/10/24 김태윤 <kty1104 at gmail.com>
>
>> thank you!
>>
>> 2010/10/24 Noel Welsh <noelwelsh at gmail.com>
>>
>> Basically, you get the gl-context from a MrEd frame. See the example here:
>>>
>>>
>>> http://github.com/plt/racket/blob/master/collects/sgl/examples/gl-frame.rkt
>>>
>>> There are other examples in the same directory.
>>>
>>> HTH,
>>> N.
>>>
>>> On Sat, Oct 23, 2010 at 2:06 PM, 김태윤 <kty1104 at gmail.com> wrote:
>>> > but I realize that this code lack of frame that will shows the color or
>>> > object
>>> > and also I can't find how to use glFlush function in scheme
>>> > could somebody please help me how to display 3d object or just color?
>>> > thanks in advanced
>>>
>>
>>
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20101024/731442c1/attachment-0001.html>

Posted on the users mailing list.