Missing GL version, how do i solve it?

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.

You don’t appear to be creating a window. No window means no context, and you can’t call any OpenGL functions (or glewInit()) without a context.

1 Like

Thanks! I didnt see that… xD

My programm now runs until the end, but somehow the compilation of the shader doesnt work.
The code that i mean is:



#include "stdafx.h"
#include <iostream>

#define GLEW_STATIC
#include <glew.h>

#include <glfw3.h>

// Function prototypes
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);

// Window dimensions
const GLuint WIDTH = 800, HEIGHT = 600;


int main()
{
	

	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);


	// Create a GLFWwindow object that we can use for GLFW's functions
    GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", nullptr, nullptr);    
    if (window == nullptr)
    {
        std::cout << "Failed to create GLFW window" << std::endl;
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);
    // Set the required callback functions
    glfwSetKeyCallback(window, key_callback);


	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;
}

// Is called whenever a key is pressed/released via GLFW
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode)
{
    std::cout << key << std::endl;
    if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
        glfwSetWindowShouldClose(window, GL_TRUE);
}


It says: ERROR::SHADER::VERTEX::COMPILATION_FAILED

0(1) : error C0205: invalid profile “corelayout”
0(1) : error C0206: invalid token “<invalid atom 137918016>” in version line

Do you know why?
Thanks for answering in the first place :smiley:

you have to put a ’
’ directly after you specified the GLSL version:

#version 330 core

or

#version 330

(which is the same as above)

or

#version 330 compatibility​

https://www.opengl.org/wiki/Core_Language_(GLSL)#Version

by the way:
your shader source code will then consist of only 2 lines, the first #version line and everything else
if you get another compilation error, it will then say:
error: 0(2) …blabla…
that makes it harder to actually spot the error

[QUOTE=john_connor;1284899]you have to put a ’
’ directly after you specified the GLSL version:

https://www.opengl.org/wiki/Core_Language_(GLSL)#Version[/QUOTE]

THANKS! Now everything works fine!
Im so glad that i found this Forum :smiley: