Note that there are some explanatory texts on larger screens.

plurals
  1. PORendering from VBO with glDrawElements has a weird result
    text
    copied!<p>I just started to implement the librocket (an UI lib that generates mesh from HTML) one requirement is the <code>RenderInterface</code>. The lib basically sends your class that inherits from <code>RenderInterface</code> the generated mesh and wants you to save the mesh then it wants you to render this generated mesh. Sounds good since you have the chance to implement your own render system for an 3rd party lib. However my problem has probably nothing to do with the lib.</p> <p>As I told the lib sends mesh to my class:</p> <pre><code>GLuint m_BufferID[2]; //... glGenBuffers(2, m_BufferID); //.. glBindBuffer(GL_ARRAY_BUFFER, m_BufferID[0]); glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_BufferID[1]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, data, GL_STATIC_DRAW); </code></pre> <p>Thats basically happen when the Lib sends me mesh. Actually it also loads a texture etc. but this is not important at the moment. (NOTE: data is an pointer to an array of ROCKET_LIB::Vertex)</p> <pre><code>glEnableVertexAttribArray(0); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(ROCKET_CORE::Vertex), (GLvoid*)offsetof(Rocket::Core::Vertex, position)); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ROCKET_CORE::Vertex), (GLvoid*)offsetof(Rocket::Core::Vertex, colour)); glEnableVertexAttribArray(2); glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(ROCKET_CORE::Vertex), (GLvoid*)offsetof(Rocket::Core::Vertex, tex_coord)); glUniformMatrix4fv(0, 1, GL_FALSE, &amp;m_TransMatrix[0][0]); glUniform2f(1, translation.x, translation.y); glActiveTexture(GL_TEXTURE0); glBindBuffer(GL_ARRAY_BUFFER, m_BufferID[0]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_BufferID[1]); glDrawElements(GL_TRIANGLES, m_indices_count, GL_UNSIGNED_INT, NULL); glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); glDisableVertexAttribArray(2); </code></pre> <p>After the mesh is uploaded to the GPU I render it with upper code. To complete this question here are my shaders:</p> <p><strong>Vertex Shader:</strong></p> <pre><code>#version 330 layout(location = 0) in vec2 inPosition; layout(location = 1) in vec4 inColor; layout(location = 2) in vec2 inTexCoord; out vec4 fragColor; out vec2 fragTexCoord; layout(location = 0) uniform mat4 m_Ortho; layout(location = 1) uniform vec2 m_Translation; void main() { // Setting out values fragColor = inColor; fragTexCoord = inTexCoord; // Settings transformed position gl_Position = vec4(inPosition + m_Translation, 1.0f, 1.0f) * m_Ortho; } </code></pre> <p><strong>Fragment Shader:</strong></p> <pre><code>#version 330 in vec4 fragColor; in vec2 fragTexCoord; out vec4 outColor; layout (location = 2) uniform sampler2D m_TextureSampler; void main() { // Just for testing purpose show the text coord as color outColor = vec4(fragTexCoord, 0.0f, 1.0f); } </code></pre> <p>Oh and I simply generate the matrix with:</p> <pre><code>glm::ortho(0.0f, static_cast&lt;float&gt;(m_Width), static_cast&lt;float&gt;(m_Height), 0.0f, -1.0f, 1.0f); </code></pre> <p>From DirectX I learned that you have to transpose matrices and I also tried that in opengl but in the end both result were weird. Here is a screenshots which shows that something is definitely not right. (Wireframe is activated) <img src="https://i.stack.imgur.com/qc0BC.jpg" alt="enter image description here"></p>
 

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