From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Daniel Llorens Newsgroups: gmane.lisp.guile.user Subject: Re: Function set-gl-vertex-array in Guile-opengl Date: Sat, 26 Jan 2019 13:52:04 +0100 Message-ID: <36DB9AAC-0B1F-4E3F-9FEC-B25A180F07CE@bluewin.ch> References: Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="30574"; mail-complaints-to="usenet@blaine.gmane.org" Cc: guile-user To: =?utf-8?Q?Luis_Souto_Gra=C3=B1a?= Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Jan 26 13:52:37 2019 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gnNRt-0007pU-7z for guile-user@m.gmane.org; Sat, 26 Jan 2019 13:52:37 +0100 Original-Received: from localhost ([127.0.0.1]:58882 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gnNRs-0004Ea-3L for guile-user@m.gmane.org; Sat, 26 Jan 2019 07:52:36 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:54130) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gnNRS-0004ER-Rr for guile-user@gnu.org; Sat, 26 Jan 2019 07:52:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gnNRR-0006CA-An for guile-user@gnu.org; Sat, 26 Jan 2019 07:52:10 -0500 Original-Received: from vimdzmsp-sfwd01.bluewin.ch ([195.186.120.131]:41316) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gnNRR-0006Ax-1Y for guile-user@gnu.org; Sat, 26 Jan 2019 07:52:09 -0500 Original-Received: from 4box.home ([100.91.106.162]) by vimdzmsp-sfwd01.bluewin.ch Swisscom AG with SMTP id nNROgJfOzGbd1nNROg3dsT; Sat, 26 Jan 2019 13:52:06 +0100 X-Bluewin-Spam-Analysis: v=2.1 cv=QtOTpQGd c=1 sm=1 tr=0 a=E/cB+Ag6Owp6h9AtTK67vw==:117 a=E/cB+Ag6Owp6h9AtTK67vw==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=IkcTkHD0fZMA:10 a=pGLkceISAAAA:8 a=mDV3o1hIAAAA:8 a=Wv9VcMZJAAAA:20 a=cda0nxGdAAAA:20 a=qeKQpWStbSsbA_HY_q4A:9 a=z992A5s_rADaji4h:21 a=OCPYAPtJH9SdIG-d:21 a=QEXdDO2ut3YA:10 a=W_lYvrw_ROsA:10 a=X72m5biD6ykA:10 a=_FVE-zBwftR9WsbkzFJk:22 X-Bluewin-Spam-Score: 0.00 X-FXIT-IP: IPv4[100.91.106.162] Epoch[1548507126] X-Bluewin-AuthAs: dll@bluewin.ch In-Reply-To: X-Mailer: Apple Mail (2.3445.102.3) X-CMAE-Envelope: MS4wfDn4tU1QRIC3WUZMvHaO1S4K7DwuSCs6mfEQesdKGSacyOLv9kRS/xWQDBa512Od+tl2G3ZHx3kaexGLFsKmQaVEJRnBeOEfDieD5tFWJyEuhG7iP++v znab/UGFVLm4kRVDLf/SdbITrqMD1r/bbxPIkSI/jGyQpGDedphSofnqjY776NTYTUJRLvxc/A0kydywOYS23gi85bdbx5wu4y8= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.186.120.131 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:15259 Archived-At: > On 26 Jan 2019, at 02:33, Luis Souto Gra=C3=B1a = wrote: >>>=20 >>> ,apropos set-gl-vertex-array >> (gl): set-gl-vertex-array #> bv-or-pointer #:optional size #:key stride offset)> >>=20 >>=20 >>> (set-gl-vertex-array (bytevector->pointer points) 3) >>=20 You should call set-gl-vertex-array like this: (set-gl-vertex-array (bytevector->pointer points) #:stride 3) That's what the #:key of the help means. You can read about that here: = https://www.gnu.org/software/guile/manual/html_node/lambda_002a-and-define= _002a.html#lambda_002a-and-define_002a > I don't know how to get #vu8(0 0 240 65 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 = 0 0 0 0 0 0 0 0 0 0 0 0 0 240... > from srfi-4. The coordinates are for a SquareAnnulus: = https://github.com/slackmoehrle/Computer-Graphics-Through-OpenGL-2nd/blob/= master/Chapter3/SquareAnnulus1/squareAnnulus1.cpp >=20 > 10 points x 3 coordinates =3D 30 I don't follow. You should still use (* n 4). Each f32 takes 4 bytes in = the bytevector. bytevector-ieee-single-native-ref/set! takes byte = addresses, not float addresses. The way you do it, you're putting the = first 30.0 at byte 0, and the second 30.0 at byte 30, so it's not even = aligned. scheme@(guile-user)> (bytevector-ieee-single-native-ref #f32(1.2 3.4 = 5.6) 0) $1 =3D 1.2000000476837158 scheme@(guile-user)> (bytevector-ieee-single-native-ref #f32(1.2 3.4 = 5.6) 4) $2 =3D 3.4000000953674316 scheme@(guile-user)> (bytevector-ieee-single-native-ref #f32(1.2 3.4 = 5.6) 8) $3 =3D 5.599999904632568 As you can see, in Guile, SRFI-4 vectors are bytevectors. The other way, = check it out: scheme@(guile-user)> (import (rnrs bytevectors)) scheme@(guile-user)> (bytevector-u8-ref #f32(3.14) 0) $1 =3D 195 scheme@(guile-user)> (bytevector-u8-ref #f32(3.14) 1) $2 =3D 245 scheme@(guile-user)> (bytevector-u8-ref #f32(3.14) 2) $3 =3D 72 scheme@(guile-user)> (bytevector-u8-ref #f32(3.14) 3) $4 =3D 64 scheme@(guile-user)> (bytevector-ieee-single-native-ref #u8(195 245 72 = 64) 0) $5 =3D 3.140000104904175 But you shouldn't need to care about any of this. You can pass an f32 = vector to any function that takes bytevectors if that bytevector is = supposed to contain floats. Don't use bytevector-ieee-single-ref/set!. Use make-f32vector, = f32vector-set! and f32-vector-ref instead. Those take float addresses. It's unnecessary and error prone to use the bytevector functions to = handle typed vectors unless you really need to address the bytes. Don't define your own f32vector. Use SRFI-4. Regards Daniel >=20 > If anyone could make an minimal example with set-gl-vertex-array I = would be very grateful. >=20 > El vie., 25 ene. 2019 a las 19:25, Daniel Llorens = () escribi=C3=B3: >=20 > Hi Luis,=20 >=20 > I don't really have an answer to your question, but I wanted to point = out that Guile already has make-f32vector, f32vector-set!, etc. You = don't need to define your own. IMO it's not a good idea to use = bytevector-xxx-set!/ref to operate on typed vectors unless you are type = punning. >=20 > The make-f32vector, etc. functions are in SRFI-4, they aren't specific = to Guile. >=20 > PS I didn't understand the purpose of (* n 30) on your code. The = original you link has (* n 4) which is what I'd expect for f32. >=20 > Regards >=20 > Daniel >=20 >=20 >> From: Luis Souto Gra=C3=B1a >> Subject: Function set-gl-vertex-array in Guile-opengl >> Date: 25 January 2019 at 11:36:33 CET >> To: guile-user@gnu.org >>=20 >>=20 >> Hello, I'm trying to use the function set-gl-vertex-array in = Guile-opengl . >> It needs a bytevector as an argument. I wrote this doing a copy-paste = from >> here: = https://github.com/marcomaggi/vicare/blob/master/attic/lab/gears.scm >>=20 >> (use-modules (rnrs bytevectors)) >> (use-modules (system foreign)) >>=20 >> (define (f32vector . lst) >> (define-syntax f32set! >> (syntax-rules () >> ((_ bv n value) >> (bytevector-ieee-single-native-set! bv (* n 30) value)))) >> (let ((bv (make-bytevector (* (length lst) 30)))) >> (let loop ((i 0) (lst lst)) >> (cond ((null? lst) bv) >> (else >> (f32set! bv i (car lst)) >> (loop (+ i 1) (cdr lst))))))) >>=20 >> (define points (f32vector 30.0 30.0 0.0 >> 10.0 10.0 0.0 >> 70.0 30.0 0.0 >> 90.0 10.0 0.0 >> 70.0 70.0 0.0 >> 90.0 90.0 0.0 >> 30.0 70.0 0.0 >> 10.0 90.0 0.0 >> 30.0 30.0 0.0 >> 10.0 10.0 0.0)) >>=20 >>> points >> #vu8(0 0 240 65 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 = 0 240 >> ..... >>=20 >>> (bytevector-length points) >> 900 >>=20 >>> (bytevector->pointer points) >> # >>=20 >>=20 >> So, it works well. >>=20 >> Now, if I write: >>=20 >> (use-modules (gl) (glut)) >>=20 >>> ,apropos set-gl-vertex-array >> (gl): set-gl-vertex-array #> bv-or-pointer #:optional size #:key stride offset)> >>=20 >>=20 >>> (set-gl-vertex-array (bytevector->pointer points) 3) >>=20 >> ERROR: In procedure scm-error: >> unhandled array-pointer type 3 >>=20 >> Can someone tell me what the solution is? >>=20 >>=20 >>=20 >> _______________________________________________ >> guile-user mailing list >> guile-user@gnu.org >> https://lists.gnu.org/mailman/listinfo/guile-user >=20