unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Luis Souto Graña" <luissoutobueu@gmail.com>
To: Daniel Llorens <daniel.llorens@bluewin.ch>
Cc: guile-user <guile-user@gnu.org>
Subject: Re: Function set-gl-vertex-array in Guile-opengl
Date: Sat, 9 Feb 2019 19:59:15 +0100	[thread overview]
Message-ID: <CA+0Zd=_uhi4UOaV06AWGJFHi=aPeveJ7geDz4k66uNrxbf6Q0w@mail.gmail.com> (raw)
In-Reply-To: <CA+0Zd=8mGU3mtv5CFPfD4HU7ORZzktZszELKtCLD--_JKrkFsg@mail.gmail.com>

I found the mistake. I only had to add two lines. It works.

(use-modules (gl) (glut))
(use-modules (gl contrib packed-struct))

(define-packed-struct vertices
  (x float)
  (y float)
  (z float)
  (r float)
  (g float)
  (b float))

(define vertices-square (make-packed-array vertices 4))
(pack vertices-square 0 vertices 20.0 20.0 0.0 0.0 0.0 0.0)
(pack vertices-square 1 vertices 80.0 20.0 0.0 0.0 0.0 0.0)
(pack vertices-square 2 vertices 80.0 80.0 0.0 0.0 0.0 0.0)
(pack vertices-square 3 vertices 20.0 80.0 0.0 0.0 0.0 0.0)

;;vertices-square
;;#vu8(0 0 160 65 0 0 160 65 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
;;     0 0 160 66 0 0 160 65 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
;;     0 0 160 66 0 0 160 66 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
;;     0 0 160 65 0 0 160 66 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)


(define (init)
    (gl-ortho 0.0 100.0 0.0 100.0 -1.0 1.0)
    (set-gl-clear-color 1.0 1.0 1.0 0.0))

(define (draw-scene)
    (gl-clear (clear-buffer-mask color-buffer))
    (gl-enable-client-state (enable-cap vertex-array))
    (gl-enable-client-state (enable-cap color-array))
    (set-gl-vertex-array (vertex-pointer-type float)
                          vertices-square
                          #:stride (packed-struct-size vertices)  ;; 24
                          #:offset (packed-struct-offset vertices x)) ;; 0
    (set-gl-color-array (color-pointer-type float)
                          vertices-square
                          #:stride (packed-struct-size vertices)  ;; 24
                          #:offset (packed-struct-offset vertices r)) ;; 12

    (gl-draw-arrays (begin-mode quads) 0 (packed-array-length
vertices-square vertices)))  ;; 4

(define (on-display)
    (init)
    (draw-scene)
    (swap-buffers))

(initialize-glut #:window-size '(800 . 800))
(make-window "hallelujah")
(set-display-callback (lambda() (on-display)))
(glut-main-loop)

El jue., 31 ene. 2019 a las 12:14, Luis Souto Graña (<
luissoutobueu@gmail.com>) escribió:

> I think I almost have it. I made a minimal example with a square. It
> starts but the square doesn't appear. If anyone finds where the fault is,
> please let me know.
>
> (use-modules (gl) (glut))
> (use-modules (gl contrib packed-struct))
>
> (define-packed-struct vertices
>   (x float)
>   (y float)
>   (z float)
>   (r float)
>   (g float)
>   (b float))
>
> (define vertices-square (make-packed-array vertices 4))
> (pack vertices-square 0 vertices 20.0 20.0 0.0 0.0 0.0 0.0)
> (pack vertices-square 1 vertices 80.0 20.0 0.0 0.0 0.0 0.0)
> (pack vertices-square 2 vertices 80.0 80.0 0.0 0.0 0.0 0.0)
> (pack vertices-square 3 vertices 20.0 80.0 0.0 0.0 0.0 0.0)
>
> ;;vertices-square
> ;;#vu8(0 0 160 65 0 0 160 65 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> ;;     0 0 160 66 0 0 160 65 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> ;;     0 0 160 66 0 0 160 66 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> ;;     0 0 160 65 0 0 160 66 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
>
>
> (define (init)
>     (gl-ortho 0.0 100.0 0.0 100.0 -1.0 1.0)
>     (set-gl-clear-color 1.0 1.0 1.0 0.0))
>
> (define (draw-scene)
>     (gl-clear (clear-buffer-mask color-buffer))
>     (gl-color 0 0 0)
>     ;;(gl-begin (begin-mode polygon)
>     ;;    (gl-vertex 20.0  20.0  0.0)
>     ;;    (gl-vertex 80.0  20.0  0.0)
>     ;;    (gl-vertex 80.0  80.0  0.0)
>     ;;    (gl-vertex 20.0  80.0  0.0)))
>     (set-gl-vertex-array (vertex-pointer-type float)
>                           vertices-square
>                           #:stride (packed-struct-size vertices)  ;; 24
>                           #:offset (packed-struct-offset vertices x)) ;; 0
>     (set-gl-color-array (color-pointer-type float)
>                           vertices-square
>                           #:stride (packed-struct-size vertices)  ;; 24
>                           #:offset (packed-struct-offset vertices r)) ;; 12
>
>     (gl-draw-arrays (begin-mode polygon) 0 (packed-array-length vertices-square vertices)))  ;; 4
>
> (define (on-display)
>     (init)
>     (draw-scene)
>     (swap-buffers))
>
> (initialize-glut #:window-size '(800 . 800))
> (make-window "page 24")
> (set-display-callback (lambda() (on-display)))
> (glut-main-loop)
>
>
> El lun., 28 ene. 2019 a las 14:30, Luis Souto Graña (<
> luissoutobueu@gmail.com>) escribió:
>
>> Andy Wingo doesn't use f32vectors, he uses packed-struct.scm https://
>> github.com/guildhall/guile-ope
>> ngl/blob/master/gl/contrib/packed-struct.scm . There are
>> bytevector-ieee-single-native-set in it.
>>
>> It works because I wrote:
>>
>> $ cd /home/spectrumgomas/guile-opengl-01.0/examples/particle-system
>> $ guile client-arrays.scm
>>
>> And I see the particle system.
>>
>> Now I just need to understand it. :)
>>
>> El sáb., 26 ene. 2019 a las 16:39, Daniel Llorens (<
>> daniel.llorens@bluewin.ch>) escribió:
>>
>>>
>>>
>>> > On 26 Jan 2019, at 17:05, Luis Souto Graña <luissoutobueu@gmail.com>
>>> wrote:
>>> >
>>> > The structure of my byvector is:
>>> >
>>> > 30.0(float) --- IEE754 converter -->  0x41F00000 (hexadecimal) ---
>>> little endian ---> 0000F041 --- hexadecimal to decimal converter ---> 00 00
>>> 240 65
>>> >
>>> > But I didn't notice and there's a lot of zeros before the next 00 00
>>> 240 65.
>>> >
>>> > I have to study what is the structure of a f32vector in Guile. I don't
>>> know it.
>>>
>>> The storage of an f32vector is exactly the same as if you declared float
>>> a[n] in C, one float after another, each taking 4 bytes. Endianness doesn't
>>> matter if you are producing and consuming the floats on the same machine.
>>>
>>> The source data is floats, OpenGL takes floats, you don't need to deal
>>> with bytes.
>>>
>>>


  reply	other threads:[~2019-02-09 18:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.136.1548435627.3559.guile-user@gnu.org>
2019-01-25 18:25 ` Function set-gl-vertex-array in Guile-opengl Daniel Llorens
2019-01-26  1:33   ` Luis Souto Graña
2019-01-26 12:52     ` Daniel Llorens
2019-01-26 12:58       ` Daniel Llorens
2019-01-26 16:05         ` Luis Souto Graña
2019-01-26 15:39           ` Daniel Llorens
2019-01-26 19:00             ` Luis Souto Graña
2019-01-28 13:30             ` Luis Souto Graña
2019-01-31 11:14               ` Luis Souto Graña
2019-02-09 18:59                 ` Luis Souto Graña [this message]
2019-01-25 10:36 Luis Souto Graña
2019-01-26 10:33 ` Catonano
2019-01-26 16:02   ` Luis Souto Graña

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+0Zd=_uhi4UOaV06AWGJFHi=aPeveJ7geDz4k66uNrxbf6Q0w@mail.gmail.com' \
    --to=luissoutobueu@gmail.com \
    --cc=daniel.llorens@bluewin.ch \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).