Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is not much to making your own vertex format. It is all done in the <code>glVertexAttribPointer</code> calls. First of all, you are using 4 as stride parameter, but your vertex structure is 8 bytes wide, so there are 8 bytes from the start of one vertex to the next, so the stride has to be 8 (in both calls, of course). The offsets are correct, but you should set the normalized flag to true for the colors, as you surely want them to be in the [0,1] range (I don't know if this should also be the case for the vertex positions).</p> <p>Next, when using custom vertex attributes in shaders, you don't enable the deprecated fixed function arrays (the <code>gl...ClienState</code> things). Instead you have to use</p> <pre><code>GL.EnableVertexAttribArray(Shaders.PositionDataID); GL.EnableVertexAttribArray(Shaders.ColorDataID); </code></pre> <p>and the corresponding <code>glDisableVertexAttribArray</code> calls.</p> <p>And what does the <code>count/4</code> mean in the <code>glDrawArrays</code> call. Keep in mind that the last parameter specifies the number of vertices and not primitives (quads in your case). But maybe it's intended this way.</p> <p>Besides these real errors, you should not use such coplicated vertex format that you have to decode it in the shader yourself. That's what the stride and offset parameters of <code>glVertexAttribPointer</code> are for. For example redefine your vertex data a bit:</p> <pre><code>public struct SmallBlockVertex { public byte PositionX; public byte PositionY; public byte PositionZ; public byte ColorR; public byte ColorG; public byte ColorB; public byte TextureX; public byte TextureY; } </code></pre> <p>and then you can just use</p> <pre><code>GL.VertexAttribPointer(Shaders.PositionDataID, 3, VertexAttribPointerType.UnsignedByte, false, 8, 0); GL.VertexAttribPointer(Shaders.ColorDataID, 3, VertexAttribPointerType.UnsignedByte, true, 8, 3); GL.VertexAttribPointer(Shaders.TexCoordDataID, 2, VertexAttribPointerType.UnsignedByte, true, 8, 6); </code></pre> <p>And in the shader you have</p> <pre><code>attribute vec3 pos_data; attribute vec3 col_data; attribute vec2 tex_data; </code></pre> <p>and you don't have to extract the texture coordinate from the position and color yourself.</p> <p>And you should really think about if your space requirements really demand using bytes for vertex positions as this extremely limits the precision of your position data. Maybe shorts or half precision floats would be a good compromise.</p> <p>And also it should not be neccessary to call <code>glBindBuffer</code> in the render method, as this is only needed for <code>glVertexAttribPointer</code> and is saved in the VAO that gets activated by <code>glBindVertexArray</code>. You should also usually not call <code>glFlush</code> as this is done anyway by the OS when the buffers are swapped (assuming you use double buffering).</p> <p>And last but not least, be sure your hardware also supports all the features you are using (like VBOs and VAOs).</p> <p><strong>EDIT:</strong> Actually the enabled flags of the arrays are also stored in the VAO, so that you can call</p> <pre><code>GL.EnableVertexAttribArray(Shaders.PositionDataID); GL.EnableVertexAttribArray(Shaders.ColorDataID); </code></pre> <p>in the <code>SetData</code> method (after creating and binding the VAO, of course) and they then get enabled when you bind the VAO by <code>glBindVertexArray</code> in the render function. Oh, I just saw another error. When you bind the VAO in the render function, the enabled flags of the attribute arrays are overwritten by the state from the VAO and as you did not enable them after the VAO creation, they are still disabled. So you will have to do it like said, enable the arrays in the <code>SetData</code> method. Actually in your case you might be lucky and the VAO is still bound when you enable the arrays in the render function (as you didn't call <code>glBindVertexArray(0)</code>) but you shouldn't count on that.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload