Im learning OpenGL with GLEW and GLFW, and followed all instructions from the tutorial Learn OpenGL ( https://learnopengl.com/ ) until the “hello triangle”-part.
I am using Visual C++ 2010 Express, GLEW 2.0 and GLFW 3.2.1.
Here is my code:
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "Starting GLFW context, OpenGL 3.3" << std::endl;
// Init GLFW
glfwInit();
// Set all the required options for GLFW
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
std::cout << "GLFW init" << std::endl;
system("pause");
glewExperimental = GL_TRUE;
// Initialize GLEW to setup the OpenGL Function pointers
if (glewInit() != GLEW_OK)
{
std::cout << "Failed to initialize GLEW" << glewGetErrorString(glewInit()) << std::endl;
system("pause");
return -1;
}
std::cout << "GLEW init" << std::endl;
system("pause");
GLchar* vertexShaderSource = "#version 330 core"
"layout (location = 0) in vec3 position;"
"void main()"
"{"
" gl_Position = vec4(position.x, position.y, position.z, 1.0);"
"}";
std::cout << "ShaderCode read" << std::endl;
system("pause");
GLfloat vertices[] = {
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.0f, 0.5f, 0.0f
};
std::cout << "Vertizes read" << std::endl;
system("pause");
GLuint VBO;
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
std::cout << "GL Buffer initialised" << std::endl;
system("pause");
GLuint vertexShader;
vertexShader = glCreateShader(GL_VERTEX_SHADER);
std::cout << "Shaderobj." << std::endl;
system("pause");
glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
glCompileShader(vertexShader);
std::cout << "Shader´compiled" << std::endl;
system("pause");
GLint success;
GLchar infoLog[512];
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
if(!success){
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED
" << infoLog << std::endl;
}
std::cout << "Shader: success" << std::endl;
system("pause");
return 0;
}
BUT i get a ACCESS-VIOLATION message, and the code std::cout << “Failed to initialize GLEW” << glewGetErrorString(glewInit()) << std::endl; tells me, that the GL version is missing. How can i tell my Programm which GL version I am using?
I tried to de- and reinstall everything, but I get this error every time D:
I hope to hear from you soon.