www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Having trouble porting basic GLFW C++ example to D

reply Matt Jones <matthew.brennan.jones gmail.com> writes:
I've been trying to port a basic GLFW C++ example to D. The C++ 
version shows the textures correctly. But the D version shows 
nothing. The code is almost identical. Does anyone know why the D 
version does not work?

https://github.com/workhorsy/d_glfw
Oct 06
parent reply Joakim <dlang joakim.fea.st> writes:
On Saturday, 7 October 2017 at 03:12:09 UTC, Matt Jones wrote:
 I've been trying to port a basic GLFW C++ example to D. The C++ 
 version shows the textures correctly. But the D version shows 
 nothing. The code is almost identical.
Heh, that's the problem.
 Does anyone know why the D version does not work?

 https://github.com/workhorsy/d_glfw
I ran into this myself, took me awhile to track it down. I too took the size of dynamic arrays this way: https://github.com/workhorsy/d_glfw/blob/master/dlang/source/main.d#L158 https://github.com/workhorsy/d_glfw/blob/master/dlang/source/main.d#L161 That will give you 2 words for a slice or dynamic array, the length and pointer. What you want is the length of the array https://github.com/joakim-noah/android/blob/master/samples/Teapot/jni/TeapotRenderer.d#L192 multiplied by the size of the element https://github.com/joakim-noah/android/blob/master/samples/Teapot/jni/TeapotRenderer.d#L195 Sizeof works for static arrays, but is different for slices: that's likely your problem.
Oct 06
parent reply Matt Jones <matthew.brennan.jones gmail.com> writes:
On Saturday, 7 October 2017 at 03:47:27 UTC, Joakim wrote:
 On Saturday, 7 October 2017 at 03:12:09 UTC, Matt Jones wrote:
 [...]
Heh, that's the problem.
 [...]
I ran into this myself, took me awhile to track it down. I too took the size of dynamic arrays this way: [...]
Ah. I should have remembered that problem. Thanks. I'll see if that fixes it.
Oct 06
parent Matt Jones <matthew.brennan.jones gmail.com> writes:
On Saturday, 7 October 2017 at 04:24:07 UTC, Matt Jones wrote:
 On Saturday, 7 October 2017 at 03:47:27 UTC, Joakim wrote:
 On Saturday, 7 October 2017 at 03:12:09 UTC, Matt Jones wrote:
 [...]
Heh, that's the problem.
 [...]
I ran into this myself, took me awhile to track it down. I too took the size of dynamic arrays this way: [...]
Ah. I should have remembered that problem. Thanks. I'll see if that fixes it.
Nice! That worked. Thanks.
Oct 06