www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - bindbc-opengl: Now drawing triangle

reply Luhrel <lucien.perregaux gmail.com> writes:
Hello,

I made a simple OpenGL file using bindbc-opengl and glfw 
(https://pastebin.com/ehmcHwxj) based on 
https://github.com/SonarSystems/Modern-OpenGL-Tutorials/blob/master/%5BGETTING%20STARTED%5D/%5B1%5D%20Triangle/main.cpp

The cpp project compiles and runs fine (g++ main.cpp -lGL -lglfw 
-o gl_test && ./gl_test), but my d-translated file not: the 
triangle isn't shown.

Do you have any idea ?
Jan 25 2020
next sibling parent reply lithium iodate <whatdoiknow doesntexist.net> writes:
On Saturday, 25 January 2020 at 19:52:25 UTC, Luhrel wrote:
 Hello,

 I made a simple OpenGL file using bindbc-opengl and glfw 
 (https://pastebin.com/ehmcHwxj) based on 
 https://github.com/SonarSystems/Modern-OpenGL-Tutorials/blob/master/%5BGETTING%20STARTED%5D/%5B1%5D%20Triangle/main.cpp

 The cpp project compiles and runs fine (g++ main.cpp -lGL 
 -lglfw -o gl_test && ./gl_test), but my d-translated file not: 
 the triangle isn't shown.

 Do you have any idea ?
In line 146 glBufferData(GL_ARRAY_BUFFER, vertices.sizeof, vertices.ptr, GL_STATIC_DRAW); you are calculating the size of `vertices` incorrectly. As `vertices` is a dynamic array, .sizeof will only give you the size of the array reference (size_t.sizeof * 2, note that .sizeof will always give you a compile-time constant in D). Change it to glBufferData(GL_ARRAY_BUFFER, vertices.length * GLfloat.sizeof, vertices.ptr, GL_STATIC_DRAW); and the data will be correctly copied into the buffer.
Jan 25 2020
parent Luhrel <lucien.perregaux gmail.com> writes:
On Saturday, 25 January 2020 at 20:21:31 UTC, lithium iodate 
wrote:
 In line 146

 glBufferData(GL_ARRAY_BUFFER, vertices.sizeof, vertices.ptr, 
 GL_STATIC_DRAW);

 you are calculating the size of `vertices` incorrectly. As 
 `vertices` is a dynamic array, .sizeof will only give you the 
 size of the array reference (size_t.sizeof * 2, note that 
 .sizeof will always give you a compile-time constant in D).
 Change it to

 glBufferData(GL_ARRAY_BUFFER, vertices.length * GLfloat.sizeof, 
 vertices.ptr, GL_STATIC_DRAW);

 and the data will be correctly copied into the buffer.
Many thanks !
Jan 25 2020
prev sibling parent reply JN <666total wp.pl> writes:
On Saturday, 25 January 2020 at 19:52:25 UTC, Luhrel wrote:
 Hello,

 I made a simple OpenGL file using bindbc-opengl and glfw 
 (https://pastebin.com/ehmcHwxj) based on 
 https://github.com/SonarSystems/Modern-OpenGL-Tutorials/blob/master/%5BGETTING%20STARTED%5D/%5B1%5D%20Triangle/main.cpp

 The cpp project compiles and runs fine (g++ main.cpp -lGL 
 -lglfw -o gl_test && ./gl_test), but my d-translated file not: 
 the triangle isn't shown.

 Do you have any idea ?
I assume it's working now? For future, learn to use RenderDoc: https://renderdoc.org/ it allows you to debug your OpenGL application and see what kind of data is sent by your app.
Jan 25 2020
parent Luhrel <lucien.perregaux gmail.com> writes:
On Saturday, 25 January 2020 at 21:33:09 UTC, JN wrote:
 I assume it's working now?
Yup it works.
 For future, learn to use RenderDoc:

 https://renderdoc.org/

 it allows you to debug your OpenGL application and see what 
 kind of data is sent by your app.
Wow that's what I need. Thanks for sharing this.
Jan 27 2020