visual studio - Cannot create GLFWwindow in C++ - glfwCreateWindow returns nullptr? -


after running several tests on code, have determined both glfw , glew initialised yet when try , create glfwwindow* object used glfw functions, glfwcreatewindow() function returns nullptr. why , how fix it? here code:

#include <iostream> #define glew_static #include <gl/glew.h> #include <glfw/glfw3.h>  const gluint windowwidth = 500, windowheight = 500;  int main() {     glfwinit();      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);      glfwwindow* window = glfwcreatewindow(windowwidth, windowheight, "learn opengl", nullptr, nullptr);     if (window == nullptr) {         std::cout << "failed create glfw window!" << std::endl;         char myvar1; std::cin >> myvar1;         glfwterminate();         return -1;     }     glfwmakecontextcurrent(window);     glewexperimental = gl_true;     if (glewinit() != gl_true) {         std::cout << "failed initialize glew" << std::endl;         char myvar2; std::cin >> myvar2;         return -1;     }      glviewport(0, 0, windowwidth, windowheight);     while (!glfwwindowshouldclose(window)) {         glfwpollevents();         glfwswapbuffers(window);     }      glfwterminate();      return 0; } 

this because specifying version 3.3 context creation , opengl version lower 3.3.

opengl: glfw_context_version_major , glfw_context_version_minor not hard constraints, creation fail if opengl version of created context less 1 requested.

this might happen if using laptop has 2 gpu's. power-consumption reasons, applications run standard gpu , games example use high performance one.

for example laptop has built-in intel(r) hd graphics 3000(3.1 opengl version) gpu , nvidia geforce gt 630m(4.4 opengl version) gpu.

you can see if laptop has functionality if right click on application shortcut , have option "run graphics processor": - "high performance (nvidia) processor" - "integrated graphics (default)"

the problem editor(eclipse/ms visual studio, etc..)(in run code) use default 1 , has lower version of opengl other gpu.

you can fix running editor program high performance gpu.

if you're not using laptop or have 1 gpu try updating drivers.


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -