I have follow several tutorials and i do not understand why this code does not display anything.
Please not that LoadShaders works great.
I have made a copy and paste so i do not think the problem comes from it...
#include <iostream>
#include <fstream>
#include <vector>
#include <GL/glew.h>
#include <GL/gl.h>
#include <GLFW/glfw3.h>
GLFWwindow* window;
int main(int argc, const char * argv[])
{
if( !glfwInit() )
{
return -1;
}
glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // We want OpenGL 3.3
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
window = glfwCreateWindow(640, 480, "Test1", NULL, NULL);
if( window == NULL )
{
return -1;
}
glfwMakeContextCurrent(window);
glewExperimental = true; // Needed for core profile
if (glewInit() != GLEW_OK)
{
return -1;
}
GLuint programID = LoadShaders( "SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader" );
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
glClearColor(0.0f, 1.0f, 1.0f, 1.0f);
do
{
glfwPollEvents();
glUseProgram(programID);
float vertices[] = {-0.5, -0.5, 0.0, 0.5, 0.5, -0.5};
glClear(GL_COLOR_BUFFER_BIT);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
glfwSwapBuffers(window);
}
while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS && glfwWindowShouldClose(window) == 0 );
glfwTerminate();
return 0;
}
Thanks for your help
Note:
Here is SimpleFragmentShader.fragmentshader:
#version 330 core
out vec3 color;
void main()
{
color = vec3(1,0,0);
}
And here is SimpleVertexShader.vertexshader:
#version 330 core
layout(location = 0) in vec3 vertexPosition_modelspace;
void main()
{
gl_Position.xyz = vertexPosition_modelspace;
gl_Position.w = 1.0;
}
Please note i have also tried to work on 3D coordinates like this:
float vertices[] = {-0.5, -0.5,0.0, 0.0, 0.5,0.0, 0.5, -0.5,0.0};
glClear(GL_COLOR_BUFFER_BIT);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);