Search code examples
arraysopenglvertexvoxel

OpenGL point array


I need to draw voxels using a float array like this:

{ v1.x, v1.y, v1.z, v1.size, v2.x, [...] }

which in my case, for testing purposes looks like this:

{ -0.6f, -0.4f, -0.0f, 1, 0.6f, -0.4f, -0.0f, 1, 0.f, 0.6f, -0.0f, 1, }

How do I load those up to the GPU and how do I then get the position and size values in the shaders?


Solution

  • You need to create a Buffer object of Vertices, then pass it to the GPU using specific APIs. In the shader, you can access data for each vertex. Take a look at the API glBufferData, for example in https://open.gl/drawing.

    I am not sure if you would really need the Size/number of the vertices, but if you need it, you would need it to pass it as an uniform via glUniform1f.