So I just followed example from superbible and wrote this code. unfortunately it works in compatibility profile but not in core. Can any one point out what is the reason. Code is compiling successfully.
#include <GLFW/glfw3.h>
#include <iostream>
#include <GL/glx.h>
#include <stdio.h>
#include "procs.hpp"
constexpr const GLchar * vertex_shader_source =
R"(#version 450 core
const vec2 vertices[3] = vec2[3](vec2(0.25, -0.25),
vec2(-0.25, -0.25),
vec2(0.25, 0.25));
void main(){
gl_Position = vec4(vertices[gl_VertexID].xy,0.5,1);
}
)";
constexpr const GLchar * fragment_shader_source =
R"(#version 450 core
out vec4 out_color;
void main(){
out_color= vec4(1,0,0,1);
}
)";
int main()
{
GLFWwindow* window;
GLuint vertex_shader;
GLuint fragment_shader;
GLuint program;
GLuint vertex_array_object;
/* Initialize the library */
if (!glfwInit()){
std::cerr<<"Error initializing glfw";
return -1;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, true);
//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(1000, 800, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
printf("Opengl : %s\n", glGetString(GL_VERSION));
vertex_shader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertex_shader, 1, &vertex_shader_source, nullptr);
glCompileShader(vertex_shader);
fragment_shader = glCreateShader(GL_FRAGMENT_SHADER) ;
glShaderSource(fragment_shader,1,&fragment_shader_source,nullptr);
glCompileShader(fragment_shader);
program = glCreateProgram();
glAttachShader(program,vertex_shader);
glAttachShader(program,fragment_shader);
glLinkProgram(program);
// Delete the shaders as the program has them now
glDeleteShader(vertex_shader);
glDeleteShader(fragment_shader);
glCreateVertexArrays(1, &vertex_array_object);
glBindVertexArray(vertex_array_object);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
static GLfloat color []= {1,0,1,1};
glClearBufferfv(GL_COLOR,0,color);
glUseProgram(program);
glDrawArrays(GL_TRIANGLES, 0, 3);
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glDeleteProgram(program);
glfwTerminate();
return 0;
}