Reputation: 705
I just started to implement the librocket (an UI lib that generates mesh from HTML) one requirement is the RenderInterface
. The lib basically sends your class that inherits from RenderInterface
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.
As I told the lib sends mesh to my class:
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);
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)
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, &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);
After the mesh is uploaded to the GPU I render it with upper code. To complete this question here are my shaders:
Vertex Shader:
#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;
}
Fragment Shader:
#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);
}
Oh and I simply generate the matrix with:
glm::ortho(0.0f, static_cast<float>(m_Width), static_cast<float>(m_Height), 0.0f, -1.0f, 1.0f);
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)
Upvotes: 1
Views: 510
Reputation: 473192
I can't say that this is certainly your actual problem, but it is a problem:
#version 330
layout(location = 0) uniform mat4 m_Ortho;
layout(location = 1) uniform vec2 m_Translation;
These two things do not go together. The explicit assignment of uniform locations is a feature of OpenGL 4.3. And GLSL version 3.30 corresponds to OpenGL 3.3.
Now, may 3.3-capable drivers will expose the feature. But it will be exposed as an extension. So you'll need to activate it like an extension:
#version 330
#extension ARB_explicit_uniform_location : require
Obviously, such shaders will only compile if this extension is available.
Upvotes: 1