![]() GLFW gives us glfwGetProcAddress that defines the correct function based on which OS we're compiling for.īefore we can start rendering we have to do one last thing. We pass GLAD the function to load the address of the OpenGL function pointers which is OS-specific. Std::cout << "Failed to initialize GLAD" << std::endl If (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) In the previous chapter we mentioned that GLAD manages function pointers for OpenGL so we want to initialize GLAD before we call any OpenGL function: After that we tell GLFW to make the context of our window the main context on the current thread. The function returns a GLFWwindow object that we'll later need for other GLFW operations. The third argument allows us to create a name for the window for now we call it "LearnOpenGL" but you're allowed to name it however you like. The glfwCreateWindow function requires the window width and height as its first two arguments respectively. Std::cout << "Failed to create GLFW window" << std::endl GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL) This window object holds all the windowing data and is required by most of GLFW's other functions. Next we're required to create a window object. OPENGL GETTING MOUSE COORDINATES UPDATEIf your supported version is lower try to check if your video card supports OpenGL 3.3+ (otherwise it's really old) and/or update your drivers. To find the OpenGL version on your machine either call glxinfo on Linux machines or use a utility like the OpenGL Extension Viewer for Windows. Make sure you have OpenGL versions 3.3 or higher installed on your system/hardware otherwise the application will crash or display undefined behavior. OPENGL GETTING MOUSE COORDINATES MAC OS XNote that on Mac OS X you need to add glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE) to your initialization code for it to work. Telling GLFW we want to use the core-profile means we'll get access to a smaller subset of OpenGL features without backwards-compatible features we no longer need. We also tell GLFW we want to explicitly use the core-profile. We set the major and minor version both to 3. This ensures that when a user does not have the proper OpenGL version GLFW fails to run. This way GLFW can make the proper arrangements when creating the OpenGL context. Since the focus of this book is on OpenGL version 3.3 we'd like to tell GLFW that 3.3 is the OpenGL version we want to use. If you try to run the application now and it gives a lot of undefined reference errors it means you didn't successfully link the GLFW library. A list of all the possible options and its corresponding values can be found at GLFW's window handling documentation. The second argument is an integer that sets the value of our option. The first argument of glfwWindowHint tells us what option we want to configure, where we can select the option from a large enum of possible options prefixed with GLFW_. In the main function we first initialize GLFW with glfwInit, after which we can configure GLFW using glfwWindowHint. glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE) GlfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE) GlfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3) GlfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3) Next, we create the main function where we will instantiate the GLFW window: The include file for GLAD includes the required OpenGL headers behind the scenes (like GL/gl.h) so be sure to include GLAD before other header files that require OpenGL (like GLFW). cpp file and add the following includes to the top of your newly created file.īe sure to include GLAD before GLFW. Let's see if we can get GLFW up and running. Hello Window Getting-started/Hello-Window ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |