Problem setting up an OpenGL 3.1 context

hburd wrote on Tuesday, August 06, 2013:

Hi,
I’m roughly following this tutorial (it’s in french, sorry) to learn the basics of modern OpenGL, except I’m adapting the tutorial to use GLFW instead of SDL.

The earlier parts of the tutorial were working fine, which only used basic OpenGL functions (glClear, glClearColor), but the functions glVertexAttribPointer, glEnableVertexAttribArray and glDisableVertexAttribArray are giving me implicit declaration of function warnings, and when I try to run the program it says There is no current context. Here’s the relevent code:

#define GL3_PROTOTYPES 1
#define GLFW_INCLUDE_GL3
#include <GLFW/glfw.h>

...

glfwInit();

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

GLFWwindow* window = glfwCreateWindow(...

glfwMakeContextCurrent(window);

float vertices[] = ...

glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

...

glfwPollEvents();
glfwSwapBuffers(window);
glClear(GL_COLOR_BUFER_BIT);

...

Am I doing all the required steps to set up an OpenGL 3.1 context? What am I doing wrong?

I’m doing this on Ubuntu by the way.

Thanks.

elmindreda wrote on Tuesday, August 06, 2013:

You need to use GLEW or a similar library, like the tutorial does.

hburd wrote on Tuesday, August 06, 2013:

Thanks, using GLEW fixed it.
The tutorial actually said that GLEW wasn’t needed for Linux, and just to include gl3.h, but I guess that’s not right.

siavashserver wrote on Monday, August 19, 2013:

I think your problem is here:

glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

Core profile is not supported on OGL 3.1 and requires OGL 3.2+. You can stick to a forward compatibility profile instead.

1 Like

your answer solved my problem,thanks very much