GLFW/GLAD/OpenGL failing to start

Started by
2 comments, last by MarcusAseth 5 years, 3 months ago

Hi guys, noob question, I wanted to try and follow this tutorial https://learnopengl.com/Getting-started/Hello-Window, I've followed all the previous steps and I got this:


#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>

int main()
{
	glfwInit();
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_VERSION_MINOR, 3);
	//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

	GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
	if (window == NULL)
	{
		std::cout << "Failed to create window" << std::endl;
		glfwTerminate();
	}

	return 0;
}

Which succesfully creates the window, but as soon as I uncomment the line


glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);


the build still succed, but the window creation fails (window variable is NULL)...
I followed all the steps so I am scratching my head on what could be wrong...help ^_^'

Advertisement

I suggest you set up GLFW error handling (see https://www.glfw.org/docs/latest/intro_guide.html#error_handling) so you can see which error was returned from glfwCreateWindow. 

Also, you should check the return value of glfwInit() to make sure that it was successful, but I guess you don't have that problem since you got the window with the commented line.

thanks for the help @1024, though I ended up solving it right away as soon I watched the code now that I woked up, so I guess I was simply tired x_x

It was a typo. In the second glfwWindowHint call I had wrote GLFW_VERSION_MINOR rather than GLFW_CONTEXT_VERSION_MINOR.

Hurray for naming! :D

This topic is closed to new replies.

Advertisement