On 1 July 2013 20:40, kilon <[email protected]> wrote:
> Thanks Igor , yes I was aware of String Cr because I have done some googling
> around and it did find information on the subject. Apparently it failed
> because I had an error in my source.
>
> So for our next challenge is learning how to fetch data that a pointer
> points to.
>
> in this case I have an array that contains my vertex positions , called
> vertexPositions
>
> vertexPositions
> "the positions of vertices to be passed to opengl"
>
>         ^ #( 0.75  0.75 0.0 1.0
>         0.75  -0.75 0.0 1.0
>          -0.75 -0.75 0.0 1.0 )
>
> so far so good
>
> so I create a pointer for that array
>
> vptrsize := (NBExternalType sizeOf: 'float')* self vertexPositions size.
>
> and then take that pointer and insert in each position the individual values
> from vertexPositions
>
> vertexPositions withIndexDo: [:each :i |
>            "using nbUInt32AtOffset because we know pointer is 4 bytes :) "
>             vpos nbFloat32AtOffset: (i-1)*(NBExternalType sizeOf: 'float') 
> put:
> each value.
>         Transcript show: ' I am putting to vpos in index: '; show: i-1; show:'
> value: '; show: each value; cr.
>         ].
>
> so far so good.
>

just one small advice:  do not use #sizeOf: sparingly.. it parsing the type
and doing full type resolution when you do that.
you can remember the size of the type you need at boot/startup time,
there is no chance
it can change within same session :)

but of course for demonstration purposes and readability it good.

> now the tricky part is that I have a function that expects that Array , not
> the smalltalk version but the C version we just created
>
> gl bufferData_target: GL_ARRAY_BUFFER size: vptrsize  data: .......  usage:
> GL_STATIC_DRAW.
>
> where you see the dots is where I should pass the data, in this case the C
> array
>
> I could do a vpo nbFloat32AtOffset: but that will return me only the
> individual value at the specific point (index) of the array, while I want to
> pass the entire array.
>
> So how I do that ?
>
> I explored NBExternalAdress and I cant find something that would return an
> array. Am I missing something obvious here ?
>

just pass NBExternalAdress instance as argument and you done.

> NBExternalAdress value , returns the number of the address and not that data
> contained in that address.
>
> I also see a  NBExternalArray but I am not sure if it is what I should be
> using .
>

arrayClass :=  NBExternalArray ofType: 'float'.
array := arrayClass new: 5. "or externalNew:5 , if you want to
allocate it in external memory"

array at: 1 put: 10.1   "use just like normal Array"

to pass it to function use:

self soemFunction: array address.

> Igor Stasenko wrote
>> On 30 June 2013 21:11, kilon <
>
>> [email protected]
>
>> > wrote:
>>> I am not going to post my code here cause it has become too big , you can
>>> find it here
>>>
>>> http://www.smalltalkhub.com/#!/~kilon/GLTutorial
>>> <http://www.smalltalkhub.com/#!/~kilon/GLTutorial>
>>>
>>> I tried adding newlines with String cr to my shaders strings, but
>>> apparently
>>> opengl is not convinced. It looks like smalltalk cr is not converted to C
>>> "\n" newlines. So how I do that ?
>>>
>>
>> simply replace all occurences of
>> Character cr
>> with
>> Character lf
>> (or crlf, if it wants that)
>>
>>> --
>>> View this message in context:
>>> http://forum.world.st/Understanding-NBOpenGL-tp4686514p4696465.html
>>> Sent from the Pharo Smalltalk Developers mailing list archive at
>>> Nabble.com.
>>>
>>
>>
>>
>> --
>> Best regards,
>> Igor Stasenko.
>
>
>
>
>
> --
> View this message in context: 
> http://forum.world.st/Understanding-NBOpenGL-tp4686514p4696666.html
> Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
>



-- 
Best regards,
Igor Stasenko.

Reply via email to