I have a project in OpenGL and I'm trying to load shaders. I use GLuint shader=glCreateShader(shaderType);
for that. The problem is, when it tries to run this line I get EXC_BAD_ACCESS (code=1, address=0x0) error (in XCode).
I found some answers that I might not have initialized glfw, or glew. But it seems it works just fine. This is my initialization code:
if (!glfwInit()) {
fprintf(stderr, "Couldn't initialize GLFW.\n");
exit(EXIT_FAILURE);
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwSetErrorCallback(errorCallback);
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "OpenGL Test", nullptr, nullptr);
if (!window) {
fprintf(stderr, "Couldn't create window.\n");
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
if (glewInit() != GLEW_OK) {
fprintf(stderr, (char*)"Couldn't initialize GLEW library.\n");
exit(EXIT_FAILURE);
}
initOpenGLProgram(window);
in initOpenGLProgram()
:
glClearColor(0, 0, 0, 1);
glEnable(GL_DEPTH_TEST);
glfwSetKeyCallback(window, keyCallback);
shaderProgram = new ShaderProgram((char*)"shaders/vshader.glsl", NULL, (char*)"shaders/fshader.glsl");
in new ShaderProgram
:
printf("Loading vertex shader...\n");
vertexShader=loadShader(GL_VERTEX_SHADER,vertexShaderFile);
and in loadShader
method (this line throws an error):
GLuint shader=glCreateShader(shaderType);
Also I have a question. I need to do my project in OpenGL 3.3, but when i check version with glGetString(GL_VERSION)
I get 4.1 version. Will there be now problem?