You've created a core OpenGL 3.3 profile while using deprecated render methods (immediate mode). Adding VAOs around the rendering calls won't help. Either use VBOs and shaders for rendering or set
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
to
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
It is still supposed to work.
I have couple of shader renderers and they don't work either.
Before I moved MakeCurrent it was working fine, with shaders and without.
But then I read to move it after glfwShowWindow() so I could create gl objects (vao, vbo, etc...) and after that, nothing is rendered.
Ok I've managed to draw something on my screen,
However, the result doesn't get affected by the shaders at all.
Doesn't matter if I change the uniform MVP or the color... it simply doesn't change anything...
#include "SimpleRenderer.h"
const GLfloat triangle[] =
{
-0.5f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.5f, 0.0f, 0.0f
};
const GLfloat colors[] =
{
1.0f, 0.0f, 1.0f,
1.0f, 0.0f, 1.0f,
1.0f, 0.0f, 1.0f
};
SimpleRenderer::SimpleRenderer()
{
mVao.Bind();
mVbo = new Vbo<GLfloat>(GL_ARRAY_BUFFER);
mVbo->PopulateData(triangle, sizeof(GLfloat) * 9);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
mColors = new Vbo<GLfloat>(GL_ARRAY_BUFFER);
mColors->PopulateData(colors, sizeof(GLbyte) * 9);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT , GL_FALSE, 0, (void*)0);
mProgram = new ShaderProgram();
Shader* vertShader = new Shader();
vertShader->Load(string("SimpleVertShader.glsl"), ShaderType::Vertex);
delete vertShader;
Shader* fragShader = new Shader();
fragShader->Load(string("FragShader.glsl"), ShaderType::Fragment);
mProgram->AttachShader(vertShader);
mProgram->AttachShader(fragShader);
delete fragShader;
mProgram->LinkProgram();
}
SimpleRenderer::~SimpleRenderer()
{
}
void SimpleRenderer::Draw()
{
mProgram->UseThis();
glm::mat4 modelMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -8.0f));
modelMatrix = glm::scale(modelMatrix, glm::vec3(2.0f, 2.0f, 2.0f));
auto perspectiveMat = glm::perspective(35.0f, 4.0f / 3.0f, 0.1f, 100.0f);
glm::mat4 viewMat = glm::lookAt(glm::vec3(0.0f, 0.0f, -8.0f), glm::vec3(0.0f, 0.0f, -2.0f), glm::vec3(0.0f, 1.0f, 0.0f));
auto modelView = perspectiveMat *viewMat* modelMatrix;
auto mvpLocation = mProgram->FindUniform("MVP");
glUniformMatrix4fv(mvpLocation, 1, GL_FALSE, glm::value_ptr(modelView));
mVao.Bind();
glDrawArrays(GL_TRIANGLES, 0, 3);
}
Frag:
#version 330
// Interpolated values from the vertex shaders
in vec3 shapeColor;
// Ouput data
out vec4 color;
void main()
{
// Output color = color of the texture at the specified UV
color = vec4(shapeColor,1.0);
}
Vert:
#version 330
// Input vertex data, different for all executions of this shader.
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec3 vertexColor;
// Output data ; will be interpolated for each fragment.
out vec3 shapeColor;
// Values that stay constant for the whole mesh.
uniform mat4 MVP;
void main(){
// Output position of the vertex, in clip space : MVP * position
gl_Position = MVP * vec4(vertexPosition_modelspace,1);
shapeColor= vertexColor;
}