FAQ
I am in the process of switching the OpenGL bind to go-gl
(https://github.com/go-gl) and I got stuck with this problem:

How (if possible) can I convert from a *float32 to a []float32 ? Is it
necessary to make a slice and manually copy the elements?

The binding does have some weird decisions.. for a vector of 3 floats it
passes a []float32 ,for a vector of 16 floats it passes a *[16]float32 ..
weird, considering OpenGL is then asking for a float* for all those
functions.

BTW, for the 16 float matrix thing I am using this, since the thing is not
compiling at the moment I wonder if that is something that will work at all:

func (sv *ShaderVarMat4) Set(value *float32) {


     sv.id.UniformMatrix4f(false, (*[16]float32)(unsafe.Pointer(value)))


}



--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Rui Ueyama at Apr 30, 2014 at 4:31 am

    On Tue, Apr 29, 2014 at 9:14 PM, Stefano Casillo wrote:

    I am in the process of switching the OpenGL bind to go-gl (
    https://github.com/go-gl) and I got stuck with this problem:

    How (if possible) can I convert from a *float32 to a []float32 ? Is it
    necessary to make a slice and manually copy the elements?
    For pointer p of type *float32, does this expression work?

       (*[10000000]float32)(unsafe.Pointer(p))[:]

    10000000 is just an arbitrarily large number. You need the last [:] to make
    a slice.

    The binding does have some weird decisions.. for a vector of 3 floats it
    passes a []float32 ,for a vector of 16 floats it passes a *[16]float32 ..
    weird, considering OpenGL is then asking for a float* for all those
    functions.

    BTW, for the 16 float matrix thing I am using this, since the thing is not
    compiling at the moment I wonder if that is something that will work at all:

    func (sv *ShaderVarMat4) Set(value *float32) {


    sv.id.UniformMatrix4f(false, (*[16]float32)(unsafe.Pointer(value)))


    }



    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Kevin Gillette at Apr 30, 2014 at 7:20 pm

    On Tuesday, April 29, 2014 10:31:13 PM UTC-6, Rui Ueyama wrote:
    (*[10000000]float32)(unsafe.Pointer(p))[:]
    That used to cause problems, and the 'arbitrarily large' approach is
    unwieldy. It's really not hard at all to properly construct a slice header.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Minux at Apr 30, 2014 at 7:29 pm

    On Apr 30, 2014 3:19 PM, "Kevin Gillette" wrote:
    On Tuesday, April 29, 2014 10:31:13 PM UTC-6, Rui Ueyama wrote:
    (*[10000000]float32)(unsafe.Pointer(p))[:]
    That used to cause problems, and the 'arbitrarily large' approach is
    unwieldy. It's really not hard at all to properly construct a slice header.
    you need to set len and cap at the same time to avoid potential problems.
    the cgo wiki page has this.

    or are you talking about another problem?

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Minux at Apr 30, 2014 at 4:33 am

    On Apr 30, 2014 12:15 AM, "Stefano Casillo" wrote:
    I am in the process of switching the OpenGL bind to go-gl (
    https://github.com/go-gl) and I got stuck with this problem:
    How (if possible) can I convert from a *float32 to a []float32 ? Is it
    necessary to make a slice and manually copy the elements?
    The binding does have some weird decisions.. for a vector of 3 floats it
    passes a []float32 ,for a vector of 16 floats it passes a *[16]float32 ..
    weird, considering OpenGL is then asking for a float* for all those
    functions.
    BTW, for the 16 float matrix thing I am using this, since the thing is
    not compiling at the moment I wonder if that is something that will work at
    all:
    func (sv *ShaderVarMat4) Set(value *float32) {


    sv.id.UniformMatrix4f(false, (*[16]float32)(unsafe.Pointer(value)))


    }
    please take a look at golang.org/wiki/cgo.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 30, '14 at 4:15a
activeApr 30, '14 at 7:29p
posts5
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase