GLUSboolean GLUSAPIENTRY glusCreateWindow(const char* title, const GLUSint width, const GLUSint height, const GLUSint depthBits, const GLUSint stencilBits, const GLUSboolean fullscreen) { GLUSenum err; if (g_window) { glusLogPrint(GLUS_LOG_ERROR, "Window already exists"); return GLUS_FALSE; } if (!glfwInit()) { glusLogPrint(GLUS_LOG_ERROR, "GLFW could not be initialized"); return GLUS_FALSE; } glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, g_major); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, g_minor); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, g_flags & GLUS_FORWARD_COMPATIBLE_BIT); glfwWindowHint(GLFW_OPENGL_PROFILE, (g_flags & GLUS_FORWARD_COMPATIBLE_BIT) ? GLFW_OPENGL_CORE_PROFILE : GLFW_OPENGL_COMPAT_PROFILE); glfwWindowHint(GLFW_SAMPLES, g_numberSamples); glfwWindowHint(GLFW_RESIZABLE, !g_noResize); glfwWindowHint(GLFW_DEPTH_BITS, depthBits); glfwWindowHint(GLFW_STENCIL_BITS, stencilBits); glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, g_debug || (g_flags & GLUS_DEBUG_CONTEXT_BIT)); g_window = glfwCreateWindow(width, height, title, fullscreen ? glfwGetPrimaryMonitor() : 0, 0); if (!g_window) { glfwTerminate(); glusLogPrint(GLUS_LOG_ERROR, "GLFW window could not be opened"); return GLUS_FALSE; } glfwMakeContextCurrent(g_window); glewExperimental = GLUS_TRUE; err = glewInit(); if (GLUS_OK != err) { glusDestroyWindow(); glusLogPrint(GLUS_LOG_ERROR, "GLEW could not be initialized: %x", err); return GLUS_FALSE; } // Catch all OpenGL errors so far. glGetError(); if (!glusIsSupported(g_major, g_minor)) { glusDestroyWindow(); glusLogPrint(GLUS_LOG_ERROR, "OpenGL %u.%u not supported", g_major, g_minor); return GLUS_FALSE; } glfwSetWindowSizeCallback(g_window, glusInternalReshape); glfwSetWindowCloseCallback(g_window, glusInternalClose); glfwSetKeyCallback(g_window, glusInternalKey); glfwSetMouseButtonCallback(g_window, glusInternalMouse); glfwSetScrollCallback(g_window, glusInternalMouseWheel); glfwSetCursorPosCallback(g_window, glusInternalMouseMove); glfwGetWindowSize(g_window, &g_width, &g_height); if (g_debug && glusIsSupported(4, 3)) { glusLogSetLevel(GLUS_LOG_DEBUG); glDebugMessageCallback(&glusInternalDebugMessage, 0); } return GLUS_TRUE; // Success }
GLUSboolean GLUSAPIENTRY glusCreateWindow(const char* title, const GLUSint width, const GLUSint height, const GLUSint depthBits, const GLUSint stencilBits, const GLUSboolean fullscreen) { GLUSenum err; if (g_windowCreated) { glusLogPrint(GLUS_LOG_ERROR, "Window already exists"); return GLUS_FALSE; } if (!glfwInit()) { glusLogPrint(GLUS_LOG_ERROR, "GLFW could not be initialized"); return GLUS_FALSE; } glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, g_major); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, g_minor); glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, g_flags & GLUS_FORWARD_COMPATIBLE_BIT); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, (g_flags & GLUS_FORWARD_COMPATIBLE_BIT) ? GLFW_OPENGL_CORE_PROFILE : GLFW_OPENGL_COMPAT_PROFILE); glfwOpenWindowHint(GLFW_FSAA_SAMPLES, g_numberSamples); glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, g_noResize); // If we do not call this function in advance, glfwOpenWindow crashes in Debug under Windows glfwSetWindowTitle(""); if (!glfwOpenWindow(width, height, 8, 8, 8, 8, depthBits, stencilBits, fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW)) { glfwTerminate(); glusLogPrint(GLUS_LOG_ERROR, "GLFW window could not be opened"); return GLUS_FALSE; } glfwSetWindowTitle(title); glewExperimental = GLUS_TRUE; err = glewInit(); if (GLUS_OK != err) { glusDestroyWindow(); glusLogPrint(GLUS_LOG_ERROR, "GLEW could not be initialized: %x", err); return GLUS_FALSE; } if (!glusIsSupported(g_major, g_minor)) { glusDestroyWindow(); glusLogPrint(GLUS_LOG_ERROR, "OpenGL %u.%u not supported", g_major, g_minor); return GLUS_FALSE; } glfwSetWindowSizeCallback(glusInternalReshape); glfwSetWindowCloseCallback(glusInternalClose); glfwSetKeyCallback(glusInternalKey); glfwSetMouseButtonCallback(glusInternalMouse); glfwSetMouseWheelCallback(glusInternalMouseWheel); glfwSetMousePosCallback(glusInternalMouseMove); glfwGetWindowSize(&g_width, &g_height); g_windowCreated = GLUS_TRUE; return GLUS_TRUE; // Success }