Home > Article > Backend Development > Why is My OpenGL Triangle Not Rendering in Go? Investigating a Vertex Buffer Issue.
OpenGL Vertex Buffer Issue in Go
In an attempt to display a triangle using OpenGL in Go, a user encountered a problem where the vertex buffer failed to render the shape. The Go code was derived from a tutorial, but unlike its C counterpart, it did not produce any output.
Cause of the Problem
The root cause of the issue lay in the arguments passed to vertexAttrib.AttribPointer(). Specifically, the user had incorrectly specified (void*)0 as the array buffer offset. This resulted in the application failing to find the vertex data.
Solution
To rectify the problem, the user switched to the work branch of the banthar bindings and made the following adjustments:
<code class="go">vertexAttrib.AttribPointer( 3, // size gl.FLOAT, //type false, // normalized? 0, // stride nil) // array buffer offset</code>
<code class="go">data := []float32{0, 1, 0, -1, -1, 0, 1, -1, 0} [...] gl.BufferData(gl.ARRAY_BUFFER, len(data)*4, data, gl.STATIC_DRAW) [...]</code>
Additional Notes
The above is the detailed content of Why is My OpenGL Triangle Not Rendering in Go? Investigating a Vertex Buffer Issue.. For more information, please follow other related articles on the PHP Chinese website!