CApplication::CApplication(void)
: m_appName("<Name> - <Build Version>")
, shader(GLSLProgram("basic_tex.vert", "basic_tex.frag"))
{
}
bool CApplication::Init(void)
{
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
shader.bindAttrib(0, "a_Vertex");
shader.bindAttrib(1, "a_Color");
shader.linkProgram();
shader.bindShader();
if (!glGenBuffers || !glBindBuffer || !glBufferData)
LOG->Send("VBOs not supported by your graphics card");
// VERTICIES
glGenBuffers(LAST_BUFFER, m_vbos);
vertices.push_back(CVertex(-1.0f, -0.5f, -4.0f));
vertices.push_back(CVertex(1.0f, -0.5f, -4.0f));
vertices.push_back(CVertex(0.0f, 0.5f, -4.0f));
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, m_vbos[VERTEX_BUFFER]);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(CVertex), &vertices[0], GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
// INDEX LIST
indices.push_back(CIndex(0));
indices.push_back(CIndex(1));
indices.push_back(CIndex(2));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vbos[INDEX_BUFFER]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(CIndex), &indices[0], GL_STATIC_DRAW);
// COLOURS
colorBuffer.push_back(CColour(1.0f, 0.0f, 0.0f));
colorBuffer.push_back(CColour(1.0f, 0.0f, 0.0f));
colorBuffer.push_back(CColour(1.0f, 0.0f, 0.0f));
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, m_vbos[COLOUR_BUFFER]);
glBufferData(GL_ARRAY_BUFFER, colorBuffer.size() * sizeof(CColour), &colorBuffer[0], GL_STATIC_DRAW);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vbos[INDEX_BUFFER]);
return true;
}
void CApplication::Render(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glGetFloatv(GL_PROJECTION, projMatrix);
glGetFloatv(GL_MODELVIEW, modelMatrix);
shader.sendUniform("modelview_matrix", modelMatrix);
shader.sendUniform("projection_matrix", projMatrix);
glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0);
}
void CApplication::OnResize(int width, int height)
{
if (width == 0)
height = 1;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(52.0f, float(width) / float(height), 1.0f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
vertshader
uniform mat4 projection_matrix;
uniform mat4 modelview_matrix;
layout(location = 0) in vec3 a_Vertex;
layout(location = 1) in vec3 a_Color;
out vec4 color;
void main(void)
{
gl_Position = projection_matrix * modelview_matrix * vec4(a_Vertex, 1.0);
color = vec4(a_Color, 1.0);
}
frag shader
in vec4 color;
out vec4 outColor;
void main(void)
{
outColor = color;
}
As mentioned my problem is a white triangle is shown on the screen. Currently I wanted it to show red, and eventually be able to specify each vertex a different colour.
Hope I managed to post across relevant information and placed it in the correct place
Is there anything that sticks out as wrong?
BTW if you need more information just ask and I'l put it up
Thankyou for any help !







