void ImGui_ImplGlfwGL3_NewFrame() { if (!g_FontTexture) ImGui_ImplGlfwGL3_CreateDeviceObjects(); ImGuiIO& io = ImGui::GetIO(); // Setup display size (every frame to accommodate for window resizing) int w, h; int display_w, display_h; glfwGetWindowSize(g_Window, &w, &h); glfwGetFramebufferSize(g_Window, &display_w, &display_h); io.DisplaySize = ImVec2((float)w, (float)h); io.DisplayFramebufferScale = ImVec2(w > 0 ? ((float)display_w / w) : 0, h > 0 ? ((float)display_h / h) : 0); // Setup time step double current_time = glfwGetTime(); io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f); g_Time = current_time; // Setup inputs // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents()) if (glfwGetWindowAttrib(g_Window, GLFW_FOCUSED)) { double mouse_x, mouse_y; glfwGetCursorPos(g_Window, &mouse_x, &mouse_y); io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position in screen coordinates (set to -1,-1 if no mouse / on another screen, etc.) } else { io.MousePos = ImVec2(-1,-1); } for (int i = 0; i < 3; i++) { io.MouseDown[i] = g_MousePressed[i] || glfwGetMouseButton(g_Window, i) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. g_MousePressed[i] = false; } io.MouseWheel = g_MouseWheel; g_MouseWheel = 0.0f; // Hide OS mouse cursor if ImGui is drawing it glfwSetInputMode(g_Window, GLFW_CURSOR, io.MouseDrawCursor ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL); // Start the frame ImGui::NewFrame(); }
void AppMain() { if(!glfwInit()) throw std::runtime_error("glfwInit failed"); // open a window with GLFW glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); window = glfwCreateWindow((int)SCREEN_SIZE.x, (int)SCREEN_SIZE.y, "test window",NULL, NULL); if(!window) throw std::runtime_error("glfwOpenWindow failed. Can your hardware handle OpenGL 4.2?"); // GLFW settings glfwMakeContextCurrent(window); // initialise GLEW glewExperimental = GL_TRUE; //stops glew crashing on OSX :-/ if(glewInit() != GLEW_OK) throw std::runtime_error("glewInit failed"); // print out some info about the graphics drivers std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl; std::cout << "GLSL version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl; std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl; // make sure OpenGL version 3.2 API is available if(!GLEW_VERSION_4_2) throw std::runtime_error("OpenGL 4.2 API is not available."); // create buffer and fill it with the points of the triangle LoadTriangle(); // run while the window is open while(glfwGetWindowAttrib(window,GLFW_FOCUSED)){ // process pending events glfwPollEvents(); // draw one frame Render(); } // clean up and exit glfwTerminate(); }
void _keypressCallback(int rawKey, int scanCode, int state, int mods) { if (!glfwGetWindowAttrib(this->_window, GLFW_FOCUSED) && !this->GetFullscreen()) { return; } std::string key = glfwGetKeyName(rawKey); if (rawKey == -1) { // On OSX -1 is the function key and should be ignored return; } Json::Value val(Json::objectValue); val["rawKey"] = rawKey; val["key"] = key; val["rawPress"] = state; val["state"] = glfwGetKeyStateName(state); val["shift"] = (mods & GLFW_MOD_SHIFT); GetEventsSingilton()->GetEvent("rawInput")->Emit(val); }
static void joystick_callback(int jid, int event) { if (event == GLFW_CONNECTED) joysticks[joystick_count++] = jid; else if (event == GLFW_DISCONNECTED) { int i; for (i = 0; i < joystick_count; i++) { if (joysticks[i] == jid) break; } for (i = i + 1; i < joystick_count; i++) joysticks[i - 1] = joysticks[i]; joystick_count--; } if (!glfwGetWindowAttrib(window, GLFW_FOCUSED)) glfwRequestWindowAttention(window); }
void Screen::initialize(GLFWwindow *window) { mGLFWWindow = window; glfwGetWindowSize(mGLFWWindow, &mSize[0], &mSize[1]); glfwGetFramebufferSize(mGLFWWindow, &mFBSize[0], &mFBSize[1]); #ifdef NDEBUG mNVGContext = nvgCreateGL3(NVG_STENCIL_STROKES | NVG_ANTIALIAS); #else mNVGContext = nvgCreateGL3(NVG_STENCIL_STROKES | NVG_ANTIALIAS | NVG_DEBUG); #endif mVisible = glfwGetWindowAttrib(window, GLFW_VISIBLE) != 0; mTheme = new Theme(mNVGContext); mMousePos = Vector2i::Zero(); mMouseState = mModifiers = 0; mDragActive = false; mLastInteraction = glfwGetTime(); mProcessEvents = true; mBackground = Vector3f(0.3f, 0.3f, 0.32f); __nanogui_screens[mGLFWWindow] = this; for (int i=0; i < (int) Cursor::CursorCount; ++i) mCursors[i] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR + i); }
bool j_is_window_open(J_Context_Shared_t i_context){ return glfwGetWindowAttrib(i_context->M_window, GLFW_VISIBLE); }
bool CWindow::IsFocused() const { return glfwGetWindowAttrib(WindowHandle, GLFW_FOCUSED) != 0; }
bool IsFocused() override { assert(this->_window != NULL); return glfwGetWindowAttrib(this->_window, GLFW_FOCUSED); }
bool Window::IsVisible() const { return glfwGetWindowAttrib(window, GLFW_VISIBLE) == GL_TRUE; }
bool Window::IsFocused() const { return glfwGetWindowAttrib(window, GLFW_FOCUSED) == GL_TRUE; }
int kit::Window::getGLFWAttribute(int attribute) { return glfwGetWindowAttrib(this->m_glfwHandle, attribute); }
int main(int argc, char** argv) { int ch, i, window_count; int auto_iconify = GLFW_TRUE, fullscreen = GLFW_FALSE, all_monitors = GLFW_FALSE; GLFWwindow** windows; while ((ch = getopt(argc, argv, "afhn")) != -1) { switch (ch) { case 'a': all_monitors = GLFW_TRUE; break; case 'h': usage(); exit(EXIT_SUCCESS); case 'f': fullscreen = GLFW_TRUE; break; case 'n': auto_iconify = GLFW_FALSE; break; default: usage(); exit(EXIT_FAILURE); } } glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); glfwWindowHint(GLFW_AUTO_ICONIFY, auto_iconify); if (fullscreen && all_monitors) { int monitor_count; GLFWmonitor** monitors = glfwGetMonitors(&monitor_count); window_count = monitor_count; windows = calloc(window_count, sizeof(GLFWwindow*)); for (i = 0; i < monitor_count; i++) { windows[i] = create_window(monitors[i]); if (!windows[i]) break; } } else { GLFWmonitor* monitor = NULL; if (fullscreen) monitor = glfwGetPrimaryMonitor(); window_count = 1; windows = calloc(window_count, sizeof(GLFWwindow*)); windows[0] = create_window(monitor); } for (i = 0; i < window_count; i++) { glfwSetKeyCallback(windows[i], key_callback); glfwSetFramebufferSizeCallback(windows[i], framebuffer_size_callback); glfwSetWindowSizeCallback(windows[i], window_size_callback); glfwSetWindowFocusCallback(windows[i], window_focus_callback); glfwSetWindowIconifyCallback(windows[i], window_iconify_callback); glfwSetWindowRefreshCallback(windows[i], window_refresh_callback); window_refresh_callback(windows[i]); printf("Window is %s and %s\n", glfwGetWindowAttrib(windows[i], GLFW_ICONIFIED) ? "iconified" : "restored", glfwGetWindowAttrib(windows[i], GLFW_FOCUSED) ? "focused" : "defocused"); } for (;;) { glfwWaitEvents(); for (i = 0; i < window_count; i++) { if (glfwWindowShouldClose(windows[i])) break; } if (i < window_count) break; // Workaround for an issue with msvcrt and mintty fflush(stdout); } glfwTerminate(); exit(EXIT_SUCCESS); }
int main() { GLFWwindow *window; char *userptr = "userptr"; glfwSetErrorCallback(errorcb); assert(glfwInit() == GL_TRUE); assert(!strcmp(glfwGetVersionString(), "3.2.1 JS WebGL Emscripten")); assert(glfwGetCurrentContext() == NULL); { int major, minor, rev; glfwGetVersion(&major, &minor, &rev); assert(major == 3); assert(minor == 2); assert(rev == 1); } { int count, x, y, w, h; GLFWmonitor **monitors = glfwGetMonitors(&count); assert(count == 1); for (int i = 0; i < count; ++i) { assert(monitors[i] != NULL); } assert(glfwGetPrimaryMonitor() != NULL); glfwGetMonitorPos(monitors[0], &x, &y); glfwGetMonitorPhysicalSize(monitors[0], &w, &h); assert(glfwGetMonitorName(monitors[0]) != NULL); glfwSetMonitorCallback(monitcb); // XXX: not implemented // assert(glfwGetVideoModes(monitors[0], &count) != NULL); // assert(glfwGetVideoMode(monitors[0]) != NULL); // glfwSetGamma(monitors[0], 1.0f); // assert(glfwGetGammaRamp(monitors[0]) != NULL); // glfwSetGammaRamp(monitors[0], ramp); } { int x, y, w, h; glfwDefaultWindowHints(); glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); window = glfwCreateWindow(640, 480, "glfw3.c", NULL, NULL); assert(window != NULL); glfwSetWindowPosCallback(window, wposicb); glfwSetWindowSizeCallback(window, wsizecb); glfwSetWindowCloseCallback(window, wcloscb); glfwSetWindowRefreshCallback(window, wrfrscb); glfwSetWindowFocusCallback(window, wfocucb); glfwSetWindowIconifyCallback(window, wiconcb); glfwSetFramebufferSizeCallback(window, wfsizcb); assert(glfwWindowShouldClose(window) == 0); glfwSetWindowShouldClose(window, 1); assert(glfwWindowShouldClose(window) == 1); glfwSetWindowTitle(window, "test"); glfwSetWindowTitle(window, "glfw3.c"); // XXX: not implemented // glfwSetWindowPos(window, 1, 1); glfwGetWindowPos(window, &x, &y); // stub glfwGetWindowSize(window, &w, &h); assert(w == 640 && h == 480); glfwSetWindowSize(window, 1, 1); glfwGetWindowSize(window, &w, &h); assert(w == 1 && h == 1); glfwSetWindowSize(window, 640, 480); glfwGetFramebufferSize(window, &w, &h); // XXX: not implemented // glfwIconifyWindow(window); // glfwRestoreWindow(window); // glfwShowWindow(window); // glfwHideWindow(window); assert(glfwGetWindowMonitor(window) == NULL); glfwDestroyWindow(window); window = glfwCreateWindow(640, 480, "glfw3.c", glfwGetPrimaryMonitor(), NULL); assert(window != NULL); assert(glfwGetWindowMonitor(window) == glfwGetPrimaryMonitor()); glfwDestroyWindow(window); window = glfwCreateWindow(640, 480, "glfw3.c", NULL, NULL); assert(window != NULL); assert(glfwGetWindowAttrib(window, GLFW_CLIENT_API) == GLFW_OPENGL_ES_API); assert(glfwGetWindowUserPointer(window) == NULL); glfwSetWindowUserPointer(window, userptr); assert(glfwGetWindowUserPointer(window) == userptr); } { double x, y; glfwSetKeyCallback(window, wkeypcb); glfwSetCharCallback(window, wcharcb); glfwSetMouseButtonCallback(window, wmbutcb); glfwSetCursorPosCallback(window, wcurpcb); glfwSetCursorEnterCallback(window, wcurecb); glfwSetScrollCallback(window, wscrocb); // XXX: stub, events come immediatly // glfwPollEvents(); // glfwWaitEvents(); assert(glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_NORMAL); // XXX: not implemented // glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); glfwGetKey(window, GLFW_KEY_A); glfwGetMouseButton(window, 0); glfwGetCursorPos(window, &x, &y); // XXX: not implemented // glfwSetCursorPos(window, 0, 0); } { // XXX: not implemented // glfwJoystickPresent(joy); // glfwGetJoystickAxes(joy, &count); // glfwGetJoystickButtons(joy, &count); // glfwGetJoystickName(joy); } { // XXX: not implemented // glfwSetClipboardString(window, "string"); // glfwGetClipboardString(window); } { glfwGetTime(); glfwSetTime(0); } { glfwMakeContextCurrent(window); // stub assert(glfwGetCurrentContext() == window); glfwSwapBuffers(window); // stub glfwSwapInterval(0); // stub } { assert(glfwExtensionSupported("nonexistant") == 0); assert(glfwGetProcAddress("nonexistant") == NULL); } glfwTerminate(); #ifdef REPORT_RESULT REPORT_RESULT(1); #endif return 0; }
int main(int argc, char** argv) { int ch, api = 0, profile = 0, strategy = 0, major = 1, minor = 0, revision; GLboolean debug = GL_FALSE, forward = GL_FALSE, list = GL_FALSE; GLint flags, mask; GLFWwindow* window; if (!valid_version()) exit(EXIT_FAILURE); while ((ch = getopt(argc, argv, "a:dfhlm:n:p:r:")) != -1) { switch (ch) { case 'a': if (strcasecmp(optarg, API_OPENGL) == 0) api = GLFW_OPENGL_API; else if (strcasecmp(optarg, API_OPENGL_ES) == 0) api = GLFW_OPENGL_ES_API; else { usage(); exit(EXIT_FAILURE); } case 'd': debug = GL_TRUE; break; case 'f': forward = GL_TRUE; break; case 'h': usage(); exit(EXIT_SUCCESS); case 'l': list = GL_TRUE; break; case 'm': major = atoi(optarg); break; case 'n': minor = atoi(optarg); break; case 'p': if (strcasecmp(optarg, PROFILE_NAME_CORE) == 0) profile = GLFW_OPENGL_CORE_PROFILE; else if (strcasecmp(optarg, PROFILE_NAME_COMPAT) == 0) profile = GLFW_OPENGL_COMPAT_PROFILE; else { usage(); exit(EXIT_FAILURE); } break; case 'r': if (strcasecmp(optarg, STRATEGY_NAME_NONE) == 0) strategy = GLFW_NO_RESET_NOTIFICATION; else if (strcasecmp(optarg, STRATEGY_NAME_LOSE) == 0) strategy = GLFW_LOSE_CONTEXT_ON_RESET; else { usage(); exit(EXIT_FAILURE); } break; default: usage(); exit(EXIT_FAILURE); } } argc -= optind; argv += optind; // Initialize GLFW and create window glfwSetErrorCallback(error_callback, NULL); if (!glfwInit()) exit(EXIT_FAILURE); if (major != 1 || minor != 0) { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, major); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor); } if (api != 0) glfwWindowHint(GLFW_CLIENT_API, api); if (debug) glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); if (forward) glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); if (profile != 0) glfwWindowHint(GLFW_OPENGL_PROFILE, profile); if (strategy) glfwWindowHint(GLFW_CONTEXT_ROBUSTNESS, strategy); glfwWindowHint(GLFW_VISIBLE, GL_FALSE); window = glfwCreateWindow(200, 200, "Version", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } glfwMakeContextCurrent(window); // Report client API version api = glfwGetWindowAttrib(window, GLFW_CLIENT_API); major = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR); minor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR); revision = glfwGetWindowAttrib(window, GLFW_CONTEXT_REVISION); printf("%s context version string: \"%s\"\n", get_client_api_name(api), glGetString(GL_VERSION)); printf("%s context version parsed by GLFW: %u.%u.%u\n", get_client_api_name(api), major, minor, revision); // Report client API context properties if (api == GLFW_OPENGL_API) { if (major >= 3) { glGetIntegerv(GL_CONTEXT_FLAGS, &flags); printf("%s context flags (0x%08x):", get_client_api_name(api), flags); if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) printf(" forward-compatible"); if (flags & GL_CONTEXT_FLAG_DEBUG_BIT) printf(" debug"); if (flags & GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB) printf(" robustness"); putchar('\n'); printf("%s context flags parsed by GLFW:", get_client_api_name(api)); if (glfwGetWindowAttrib(window, GLFW_OPENGL_FORWARD_COMPAT)) printf(" forward-compatible"); if (glfwGetWindowAttrib(window, GLFW_OPENGL_DEBUG_CONTEXT)) printf(" debug"); if (glfwGetWindowAttrib(window, GLFW_CONTEXT_ROBUSTNESS) != GLFW_NO_ROBUSTNESS) printf(" robustness"); putchar('\n'); } if (major > 3 || (major == 3 && minor >= 2)) { int profile = glfwGetWindowAttrib(window, GLFW_OPENGL_PROFILE); glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask); printf("%s profile mask (0x%08x): %s\n", get_client_api_name(api), mask, get_profile_name_gl(mask)); printf("%s profile mask parsed by GLFW: %s\n", get_client_api_name(api), get_profile_name_glfw(profile)); } if (glfwExtensionSupported("GL_ARB_robustness")) { int robustness; GLint strategy; glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &strategy); printf("%s robustness strategy (0x%08x): %s\n", get_client_api_name(api), strategy, get_strategy_name_gl(strategy)); robustness = glfwGetWindowAttrib(window, GLFW_CONTEXT_ROBUSTNESS); printf("%s robustness strategy parsed by GLFW: %s\n", get_client_api_name(api), get_strategy_name_glfw(robustness)); } } printf("%s context renderer string: \"%s\"\n", get_client_api_name(api), glGetString(GL_RENDERER)); printf("%s context vendor string: \"%s\"\n", get_client_api_name(api), glGetString(GL_VENDOR)); if (major > 1) { printf("%s context shading language version: \"%s\"\n", get_client_api_name(api), glGetString(GL_SHADING_LANGUAGE_VERSION)); } // Report client API extensions if (list) list_extensions(api, major, minor); glfwTerminate(); exit(EXIT_SUCCESS); }
bool Screen::isFocused() { glfwPollEvents(); return glfwGetWindowAttrib(_winHandle, GLFW_FOCUSED) != 0; }
bool Window::has_focus() const { return glfwGetWindowAttrib(this->_window, GLFW_FOCUSED) == 1; }
void ImGui_ImplGlfwGL3_NewFrame() { if (!g_FontTexture) ImGui_ImplGlfwGL3_CreateDeviceObjects(); ImGuiIO& io = ImGui::GetIO(); // Setup display size (every frame to accommodate for window resizing) int w, h; int display_w, display_h; glfwGetWindowSize(g_Window, &w, &h); glfwGetFramebufferSize(g_Window, &display_w, &display_h); io.DisplaySize = ImVec2((float)w, (float)h); io.DisplayFramebufferScale = ImVec2(w > 0 ? ((float)display_w / w) : 0, h > 0 ? ((float)display_h / h) : 0); // Setup time step double current_time = glfwGetTime(); io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f); g_Time = current_time; // Setup inputs // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents()) if (glfwGetWindowAttrib(g_Window, GLFW_FOCUSED)) { // Set OS mouse position if requested (only used when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user) if (io.WantSetMousePos) { glfwSetCursorPos(g_Window, (double)io.MousePos.x, (double)io.MousePos.y); } else { double mouse_x, mouse_y; glfwGetCursorPos(g_Window, &mouse_x, &mouse_y); io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); } } else { io.MousePos = ImVec2(-FLT_MAX,-FLT_MAX); } for (int i = 0; i < 3; i++) { // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. io.MouseDown[i] = g_MouseJustPressed[i] || glfwGetMouseButton(g_Window, i) != 0; g_MouseJustPressed[i] = false; } // Update OS/hardware mouse cursor if imgui isn't drawing a software cursor if ((io.ConfigFlags & ImGuiConfigFlags_NoSetMouseCursor) == 0 && glfwGetInputMode(g_Window, GLFW_CURSOR) != GLFW_CURSOR_DISABLED) { ImGuiMouseCursor cursor = ImGui::GetMouseCursor(); if (io.MouseDrawCursor || cursor == ImGuiMouseCursor_None) { glfwSetInputMode(g_Window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); } else { glfwSetCursor(g_Window, g_MouseCursors[cursor] ? g_MouseCursors[cursor] : g_MouseCursors[ImGuiMouseCursor_Arrow]); glfwSetInputMode(g_Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); } } // Gamepad navigation mapping [BETA] memset(io.NavInputs, 0, sizeof(io.NavInputs)); if (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) { // Update gamepad inputs #define MAP_BUTTON(NAV_NO, BUTTON_NO) { if (buttons_count > BUTTON_NO && buttons[BUTTON_NO] == GLFW_PRESS) io.NavInputs[NAV_NO] = 1.0f; } #define MAP_ANALOG(NAV_NO, AXIS_NO, V0, V1) { float v = (axes_count > AXIS_NO) ? axes[AXIS_NO] : V0; v = (v - V0) / (V1 - V0); if (v > 1.0f) v = 1.0f; if (io.NavInputs[NAV_NO] < v) io.NavInputs[NAV_NO] = v; } int axes_count = 0, buttons_count = 0; const float* axes = glfwGetJoystickAxes(GLFW_JOYSTICK_1, &axes_count); const unsigned char* buttons = glfwGetJoystickButtons(GLFW_JOYSTICK_1, &buttons_count); MAP_BUTTON(ImGuiNavInput_Activate, 0); // Cross / A MAP_BUTTON(ImGuiNavInput_Cancel, 1); // Circle / B MAP_BUTTON(ImGuiNavInput_Menu, 2); // Square / X MAP_BUTTON(ImGuiNavInput_Input, 3); // Triangle / Y MAP_BUTTON(ImGuiNavInput_DpadLeft, 13); // D-Pad Left MAP_BUTTON(ImGuiNavInput_DpadRight, 11); // D-Pad Right MAP_BUTTON(ImGuiNavInput_DpadUp, 10); // D-Pad Up MAP_BUTTON(ImGuiNavInput_DpadDown, 12); // D-Pad Down MAP_BUTTON(ImGuiNavInput_FocusPrev, 4); // L1 / LB MAP_BUTTON(ImGuiNavInput_FocusNext, 5); // R1 / RB MAP_BUTTON(ImGuiNavInput_TweakSlow, 4); // L1 / LB MAP_BUTTON(ImGuiNavInput_TweakFast, 5); // R1 / RB MAP_ANALOG(ImGuiNavInput_LStickLeft, 0, -0.3f, -0.9f); MAP_ANALOG(ImGuiNavInput_LStickRight,0, +0.3f, +0.9f); MAP_ANALOG(ImGuiNavInput_LStickUp, 1, +0.3f, +0.9f); MAP_ANALOG(ImGuiNavInput_LStickDown, 1, -0.3f, -0.9f); #undef MAP_BUTTON #undef MAP_ANALOG if (axes_count > 0 && buttons_count > 0) io.BackendFlags |= ImGuiBackendFlags_HasGamepad; else io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad; } // Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application. ImGui::NewFrame(); }
void CanvasGLFW::hide() { if (glfwGetWindowAttrib(glWindow_, GLFW_VISIBLE)) { glfwWindowCount_--; glfwHideWindow(glWindow_); } }
Engine::Engine( uint major, uint minor ) : width(1024), height(768) { /////////////////////////////////////////////////////////////////////////// // Initiate the opengl context and try to get an opengl context. Then // // initialise the scene. // /////////////////////////////////////////////////////////////////////////// if ( !glfwInit() ) exit( EXIT_FAILURE ); glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, major ); glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, minor ); glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE ); glfwWindowHint( GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE ); glfwWindowHint( GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE ); window = glfwCreateWindow( width, height, "GLFW Application", nullptr, nullptr ); if ( !window ) { glfwTerminate(); std::cerr << "Could not create window"; exit( EXIT_FAILURE ); } glfwMakeContextCurrent( window ); std::cout << "\nOpenGL Version: " << glfwGetWindowAttrib( window, GLFW_CONTEXT_VERSION_MAJOR ) << "." << glfwGetWindowAttrib( window, GLFW_CONTEXT_VERSION_MINOR ) << "." << glfwGetWindowAttrib( window, GLFW_CONTEXT_REVISION ) << "\n"; // start GLEW extension handler glewExperimental = GL_TRUE; GLenum err = glewInit(); glGetError(); // flush an non existent error if ( GLEW_OK | err ) { std::cerr << "Error: " << glewGetErrorString( err ) << std::endl; } else { if ( glewIsSupported( "GL_VERSION_4_5" ) ) { std::cout << "Driver supports OpenGL 4.5\nDetails:" << std::endl; } else if ( glewIsSupported( "GL_VERSION_4_3" ) ) { std::cout << "Driver supports OpenGL 4.3\nDetails:" << std::endl; } else if ( glewIsSupported( "GL_VERSION_4_0" ) ) { std::cout << "Driver supports OpenGL 4.0\nDetails:" << std::endl; } else if ( glewIsSupported( "GL_VERSION_3_3" ) ) { std::cout << "Driver supports OpenGL 3.3\nDetails:" << std::endl; } else if ( glewIsSupported( "GL_VERSION_3_2" ) ) { std::cout << "Driver supports OpenGL 3.2\nDetails:" << std::endl; } else if ( glewIsSupported( "GL_VERSION_3_1" ) ) { std::cout << "Driver supports OpenGL 3.1\nDetails:" << std::endl; } } std::cout << "\tUsing glew " << glewGetString( GLEW_VERSION ) << std::endl; std::cout << "\tVendor: " << glGetString( GL_VENDOR ) << std::endl; std::cout << "\tRenderer: " << glGetString( GL_RENDERER ) << std::endl; std::cout << "\tVersion: " << glGetString( GL_VERSION ) << std::endl; std::cout << "\tGLSL: " << glGetString( GL_SHADING_LANGUAGE_VERSION ) << std::endl; glfwSwapInterval( 2 ); glfwSetErrorCallback( errorCallback ); glfwSetKeyCallback( window, key_callback ); glfwSetScrollCallback( window, scroll_callback ); glfwSetMouseButtonCallback( window, mousebutton_callback ); glfwSetCursorPosCallback( window, mousemotion_callback ); glfwSetFramebufferSizeCallback( window, resizeCallback ); mouseLook = false; geo = Geometry::getInstance(); txt = Texture::getInstance(); cam = new Camera( glm::vec3( 0.0f, 2.0f, 10.0f ), width, height ); lights = Lights::getInstance(); eng = this; }
bool Application::GetWindowFocusStatus() { return glfwGetWindowAttrib(m_window, GLFW_FOCUSED); }
Runner::Runner(float windowWidth, float windowHeight, int frameRate,const char* title,BaseCore* c){ Runner::windowWidth = windowWidth; Runner::windowHeight = windowHeight; //assign the core to the pointer this->c = c; //sets the event call back method in basecore //set the error method in basecore glfwSetErrorCallback(errorCallback); //if it fails then exit if (!glfwInit()){ exit(EXIT_FAILURE); } //stop the window from being resizeable glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); //create the window using the height and stuff c->getWindow() = glfwCreateWindow(windowWidth, windowHeight, title, NULL, NULL); GLFWwindow* window = c->getWindow(); //set a userpointer for the window to this version of Runner glfwSetWindowUserPointer(window, this); //set the key_callback method glfwSetKeyCallback(window, keyCallback); //set mousepressed callback glfwSetMouseButtonCallback(window, mouseCallback); //set cursor call back glfwSetCursorPosCallback(window, cursorCallback); //if the window is dead, stop the program if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } //sets the context to the window glfwMakeContextCurrent(window); //sets the intervals of buffer swaps glfwSwapInterval(1); //call setup for first time run c->setup(); //the game loop while (!glfwWindowShouldClose(window)) { int iconified = glfwGetWindowAttrib(window, GLFW_ICONIFIED); int focused = glfwGetWindowAttrib(window, GLFW_FOCUSED); if(iconified || !focused){ glfwWaitEvents(); } if(fps(frameRate)){ continue; } glClearColor(r, g, b, a); int width, height; //this allows GLtransparancy glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //set view port, allows pixeltopixel things glfwGetFramebufferSize(window, &width, &height); glViewport(0, 0, width, height); //clear the buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); //set the ortho to pixels so it can be used like processing glOrtho(0.f, windowWidth, windowHeight, 0.f, -1.f, 1.f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //call update and then draw if the window isn't iconified if(!iconified && focused){ //draw c->draw(); } //swap the buffers glfwSwapBuffers(window); if(!iconified && focused){ c->update(); } glfwPollEvents(); } glfwDestroyWindow(window); glfwTerminate(); exit(EXIT_SUCCESS); }
bool Engine::init(int width, int height, bool fullscreen) { glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); //int fs = fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW; window = glfwCreateWindow(width, height, "Facial", NULL, NULL); windowSize = ivec2(width, height); /* if(!glfwOpenWindow( width, height, R_BPP, G_BPP, B_BPP, A_BPP, DEPTH_BPP, STENCIL_BPP, fs)) */ if(!window) { logError("could not create GLFW-window"); return false; } /* Make the window's context current */ glfwMakeContextCurrent(window); glfwSetKeyCallback(window, Engine::keyCallback); glfwSetMouseButtonCallback(window, Engine::mouseButtonCallback); glfwSetCursorPosCallback(window, Engine::cursorPosCallback); glfwSetScrollCallback(window, scrollCallback); logErrorsGL(); //#ifndef __APPLE__ glewExperimental = GL_TRUE; if (GLEW_OK != glewInit()) { logError("GLEW init error"); return false; } //#endif logErrorsGL(); logNote("Successfully created OpenGL-window, version %i.%i", glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR), glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR)); logNote("GLSL-version: %s",glGetString(GL_SHADING_LANGUAGE_VERSION)); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glfwSwapInterval(0); return true; }
// program entry int32_t main(int32_t argc, char *argv[]) { GLFWwindow* window; int32_t width, height; NvAssetLoaderInit(NULL); sWindowIsFocused = true; sForcedRenderCount = 0; if( !glfwInit() ) { fprintf( stderr, "Failed to initialize GLFW\n" ); exit( EXIT_FAILURE ); } glfwSetErrorCallback(glfwError); NvLinuxPlatformContext* platform = new NvLinuxPlatformContext; // add command line arguments for (int i = 1; i < argc; i++) { platform->m_commandLine.push_back(argv[i]); } sApp = NvAppFactory(platform); NvEGLConfiguration config(NvGfxAPIVersionGL4(), 8, 8, 8, 8, 16, 0); sApp->configurationCallback(config); // Does not seem to work... /* if (config.api == GLAppContext::Configuration::API_ES) glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, config.majVer); //glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); */ NvGLLinuxAppContext* context = new NvGLLinuxAppContext(config); window = glfwCreateWindow( 1280, 720, "Linux SDK Application", NULL, NULL ); if (!window) { fprintf( stderr, "Failed to open GLFW window\n" ); glfwTerminate(); exit( EXIT_FAILURE ); } platform->setWindow(window); context->setWindow(window); sApp->setGLContext(context); // Set callback functions glfwSetFramebufferSizeCallback(window, reshape); glfwSetWindowFocusCallback(window, focus); setInputCallbacksGLFW(window); context->bindContext(); glfwSwapInterval( 1 ); glfwGetFramebufferSize(window, &width, &height); int32_t major = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR); int32_t minor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR); config.apiVer = NvGfxAPIVersion(NvGfxAPI::GL, major, minor); glGetIntegerv(GL_RED_BITS, (GLint*)&config.redBits); glGetIntegerv(GL_GREEN_BITS, (GLint*)&config.greenBits); glGetIntegerv(GL_BLUE_BITS, (GLint*)&config.blueBits); glGetIntegerv(GL_ALPHA_BITS, (GLint*)&config.alphaBits); glGetIntegerv(GL_DEPTH_BITS, (GLint*)&config.depthBits); glGetIntegerv(GL_STENCIL_BITS, (GLint*)&config.stencilBits); context->setConfiguration(config); #if 1 // get extensions (need for ES2.0) GLenum err = glewInit(); if (GLEW_OK != err) { /* Problem: glewInit failed, something is seriously wrong. */ fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); exit(-1); } fprintf(stdout, "Using GLEW %s\n", glewGetString(GLEW_VERSION)); #endif // Parse command-line options initGL(argc, argv); reshape(window, width, height); sApp->mainLoop(); // Shut down the app before shutting down GL delete sApp; // Terminate GLFW glfwTerminate(); NvAssetLoaderShutdown(); // Exit program exit( EXIT_SUCCESS ); }
bool Graphics::GetMaximized() { if (!window2_) return false; return glfwGetWindowAttrib(window2_,GLFW_MAXIMIZED)==GLFW_TRUE; }
int main(int argc, char** argv) { if(argc != 2) { std::cout << "Usage:\n\t" << argv[0] << " IMAGE" << std::endl; return 1; } // Setup window glfwSetErrorCallback(error_callback); if (!glfwInit()) return 1; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); #if __APPLE__ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); #endif GLFWwindow* window = glfwCreateWindow(1280, 720, "HBVisionGraphEditor", NULL, NULL); glfwMakeContextCurrent(window); gl3wInit(); // Setup ImGui binding ImGui_ImplGlfwGL3_Init(window, true); ImVec4 clear_color = ImColor(39, 40, 34); cv::Mat image = cv::imread(argv[1]); Solution solution(image); AlgSimple simple; Preview preview{solution}; Preview preview2{solution}; while (!glfwWindowShouldClose(window)) { if(!glfwGetWindowAttrib(window, GLFW_ICONIFIED) && glfwGetWindowAttrib(window, GLFW_VISIBLE)) { glfwPollEvents(); ImGui_ImplGlfwGL3_NewFrame(); // Settings ImGui::BeginMainMenuBar(); int menuHeight = ImGui::GetTextLineHeightWithSpacing(); if(ImGui::BeginMenu("File")) { if(ImGui::MenuItem("Quit")) { glfwSetWindowShouldClose(window, GL_TRUE); } ImGui::EndMenu(); } ImGui::EndMainMenuBar(); bool open = false; ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0); ImGui::SetNextWindowPos(ImVec2(0, menuHeight)); ImGui::SetNextWindowSize(ImVec2(400, ImGui::GetIO().DisplaySize.y - menuHeight)); if (ImGui::Begin("###main", &open, ImVec2(0, 0), 0.5f, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoSavedSettings)) { if (ImGui::TreeNodeEx("Solution", ImGuiTreeNodeFlags_DefaultOpen)) { solution.draw(); ImGui::TreePop(); } if (ImGui::TreeNodeEx("Algorithm", ImGuiTreeNodeFlags_DefaultOpen)) { static int currentAlgorithm = 0; ImGui::Combo("###AlgorithmCombo", ¤tAlgorithm, "simple\0empty\0\0"); simple.draw(); ImGui::TreePop(); } ImGui::Spacing(); ImGui::Separator(); ImGui::Spacing(); if (ImGui::Button("Calculate Pattern", ImVec2(ImGui::GetContentRegionAvailWidth(), 20))) { simple.calculate(solution); } } ImGui::End(); ImGui::PopStyleVar(); // Preview preview.draw(solution); preview2.draw(solution); // Rendering int display_w, display_h; glfwGetFramebufferSize(window, &display_w, &display_h); glViewport(0, 0, display_w, display_h); glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w); glClear(GL_COLOR_BUFFER_BIT); ImGui::Render(); glfwSwapBuffers(window); } else { glfwWaitEvents(); } } // Cleanup ImGui_ImplGlfwGL3_Shutdown(); glfwTerminate(); return 0; }
void ImGui_ImplGlfwGL2_NewFrame() { if (!g_FontTexture) ImGui_ImplGlfwGL2_CreateDeviceObjects(); ImGuiIO& io = ImGui::GetIO(); // Setup display size (every frame to accommodate for window resizing) int w, h; int display_w, display_h; glfwGetWindowSize(g_Window, &w, &h); glfwGetFramebufferSize(g_Window, &display_w, &display_h); io.DisplaySize = ImVec2((float)w, (float)h); io.DisplayFramebufferScale = ImVec2(w > 0 ? ((float)display_w / w) : 0, h > 0 ? ((float)display_h / h) : 0); // Setup time step double current_time = glfwGetTime(); io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f); g_Time = current_time; // Setup inputs // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents()) if (glfwGetWindowAttrib(g_Window, GLFW_FOCUSED)) { // Set OS mouse position if requested (only used when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user) if (io.WantSetMousePos) { glfwSetCursorPos(g_Window, (double)io.MousePos.x, (double)io.MousePos.y); } else { double mouse_x, mouse_y; glfwGetCursorPos(g_Window, &mouse_x, &mouse_y); io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); } } else { io.MousePos = ImVec2(-FLT_MAX,-FLT_MAX); } for (int i = 0; i < 3; i++) { // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. io.MouseDown[i] = g_MouseJustPressed[i] || glfwGetMouseButton(g_Window, i) != 0; g_MouseJustPressed[i] = false; } // Update OS/hardware mouse cursor if imgui isn't drawing a software cursor if ((io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) == 0 && glfwGetInputMode(g_Window, GLFW_CURSOR) != GLFW_CURSOR_DISABLED) { ImGuiMouseCursor cursor = ImGui::GetMouseCursor(); if (io.MouseDrawCursor || cursor == ImGuiMouseCursor_None) { glfwSetInputMode(g_Window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); } else { glfwSetCursor(g_Window, g_MouseCursors[cursor] ? g_MouseCursors[cursor] : g_MouseCursors[ImGuiMouseCursor_Arrow]); glfwSetInputMode(g_Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); } } // Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application. ImGui::NewFrame(); }
bool Window::IsDecorated() const { return glfwGetWindowAttrib(window, GLFW_DECORATED) == GL_TRUE; }
int main(int argc, char** argv) { int ch, client, major, minor, revision, profile; GLint redbits, greenbits, bluebits, alphabits, depthbits, stencilbits; int list_extensions = GLFW_FALSE, list_layers = GLFW_FALSE; GLenum error; GLFWwindow* window; enum { CLIENT, CONTEXT, BEHAVIOR, DEBUG, FORWARD, HELP, EXTENSIONS, LAYERS, MAJOR, MINOR, PROFILE, ROBUSTNESS, VERSION, REDBITS, GREENBITS, BLUEBITS, ALPHABITS, DEPTHBITS, STENCILBITS, ACCUMREDBITS, ACCUMGREENBITS, ACCUMBLUEBITS, ACCUMALPHABITS, AUXBUFFERS, SAMPLES, STEREO, SRGB, SINGLEBUFFER, NOERROR_SRSLY }; const struct option options[] = { { "behavior", 1, NULL, BEHAVIOR }, { "client-api", 1, NULL, CLIENT }, { "context-api", 1, NULL, CONTEXT }, { "debug", 0, NULL, DEBUG }, { "forward", 0, NULL, FORWARD }, { "help", 0, NULL, HELP }, { "list-extensions", 0, NULL, EXTENSIONS }, { "list-layers", 0, NULL, LAYERS }, { "major", 1, NULL, MAJOR }, { "minor", 1, NULL, MINOR }, { "profile", 1, NULL, PROFILE }, { "robustness", 1, NULL, ROBUSTNESS }, { "version", 0, NULL, VERSION }, { "red-bits", 1, NULL, REDBITS }, { "green-bits", 1, NULL, GREENBITS }, { "blue-bits", 1, NULL, BLUEBITS }, { "alpha-bits", 1, NULL, ALPHABITS }, { "depth-bits", 1, NULL, DEPTHBITS }, { "stencil-bits", 1, NULL, STENCILBITS }, { "accum-red-bits", 1, NULL, ACCUMREDBITS }, { "accum-green-bits", 1, NULL, ACCUMGREENBITS }, { "accum-blue-bits", 1, NULL, ACCUMBLUEBITS }, { "accum-alpha-bits", 1, NULL, ACCUMALPHABITS }, { "aux-buffers", 1, NULL, AUXBUFFERS }, { "samples", 1, NULL, SAMPLES }, { "stereo", 0, NULL, STEREO }, { "srgb", 0, NULL, SRGB }, { "singlebuffer", 0, NULL, SINGLEBUFFER }, { "no-error", 0, NULL, NOERROR_SRSLY }, { NULL, 0, NULL, 0 } }; // Initialize GLFW and create window if (!valid_version()) exit(EXIT_FAILURE); glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); while ((ch = getopt_long(argc, argv, "a:b:c:dfhlm:n:p:s:v", options, NULL)) != -1) { switch (ch) { case 'a': case CLIENT: if (strcasecmp(optarg, API_NAME_OPENGL) == 0) glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); else if (strcasecmp(optarg, API_NAME_OPENGL_ES) == 0) glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); else { usage(); exit(EXIT_FAILURE); } break; case 'b': case BEHAVIOR: if (strcasecmp(optarg, BEHAVIOR_NAME_NONE) == 0) { glfwWindowHint(GLFW_CONTEXT_RELEASE_BEHAVIOR, GLFW_RELEASE_BEHAVIOR_NONE); } else if (strcasecmp(optarg, BEHAVIOR_NAME_FLUSH) == 0) { glfwWindowHint(GLFW_CONTEXT_RELEASE_BEHAVIOR, GLFW_RELEASE_BEHAVIOR_FLUSH); } else { usage(); exit(EXIT_FAILURE); } break; case 'c': case CONTEXT: if (strcasecmp(optarg, API_NAME_NATIVE) == 0) glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_NATIVE_CONTEXT_API); else if (strcasecmp(optarg, API_NAME_EGL) == 0) glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API); else { usage(); exit(EXIT_FAILURE); } break; case 'd': case DEBUG: glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); break; case 'f': case FORWARD: glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); break; case 'h': case HELP: usage(); exit(EXIT_SUCCESS); case 'l': case EXTENSIONS: list_extensions = GLFW_TRUE; break; case LAYERS: list_layers = GLFW_TRUE; break; case 'm': case MAJOR: glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, atoi(optarg)); break; case 'n': case MINOR: glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, atoi(optarg)); break; case 'p': case PROFILE: if (strcasecmp(optarg, PROFILE_NAME_CORE) == 0) { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); } else if (strcasecmp(optarg, PROFILE_NAME_COMPAT) == 0) { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); } else { usage(); exit(EXIT_FAILURE); } break; case 's': case ROBUSTNESS: if (strcasecmp(optarg, STRATEGY_NAME_NONE) == 0) { glfwWindowHint(GLFW_CONTEXT_ROBUSTNESS, GLFW_NO_RESET_NOTIFICATION); } else if (strcasecmp(optarg, STRATEGY_NAME_LOSE) == 0) { glfwWindowHint(GLFW_CONTEXT_ROBUSTNESS, GLFW_LOSE_CONTEXT_ON_RESET); } else { usage(); exit(EXIT_FAILURE); } break; case 'v': case VERSION: print_version(); exit(EXIT_SUCCESS); case REDBITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_RED_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_RED_BITS, atoi(optarg)); break; case GREENBITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_GREEN_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_GREEN_BITS, atoi(optarg)); break; case BLUEBITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_BLUE_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_BLUE_BITS, atoi(optarg)); break; case ALPHABITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_ALPHA_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_ALPHA_BITS, atoi(optarg)); break; case DEPTHBITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_DEPTH_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_DEPTH_BITS, atoi(optarg)); break; case STENCILBITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_STENCIL_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_STENCIL_BITS, atoi(optarg)); break; case ACCUMREDBITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_ACCUM_RED_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_ACCUM_RED_BITS, atoi(optarg)); break; case ACCUMGREENBITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_ACCUM_GREEN_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_ACCUM_GREEN_BITS, atoi(optarg)); break; case ACCUMBLUEBITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_ACCUM_BLUE_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_ACCUM_BLUE_BITS, atoi(optarg)); break; case ACCUMALPHABITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_ACCUM_ALPHA_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_ACCUM_ALPHA_BITS, atoi(optarg)); break; case AUXBUFFERS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_AUX_BUFFERS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_AUX_BUFFERS, atoi(optarg)); break; case SAMPLES: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_SAMPLES, GLFW_DONT_CARE); else glfwWindowHint(GLFW_SAMPLES, atoi(optarg)); break; case STEREO: glfwWindowHint(GLFW_STEREO, GLFW_TRUE); break; case SRGB: glfwWindowHint(GLFW_SRGB_CAPABLE, GLFW_TRUE); break; case SINGLEBUFFER: glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_FALSE); break; case NOERROR_SRSLY: glfwWindowHint(GLFW_CONTEXT_NO_ERROR, GLFW_TRUE); break; default: usage(); exit(EXIT_FAILURE); } } print_version(); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); window = glfwCreateWindow(200, 200, "Version", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } glfwMakeContextCurrent(window); gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); error = glGetError(); if (error != GL_NO_ERROR) printf("*** OpenGL error after make current: 0x%08x ***\n", error); // Report client API version client = glfwGetWindowAttrib(window, GLFW_CLIENT_API); major = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR); minor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR); revision = glfwGetWindowAttrib(window, GLFW_CONTEXT_REVISION); profile = glfwGetWindowAttrib(window, GLFW_OPENGL_PROFILE); printf("%s context version string: \"%s\"\n", get_api_name(client), glGetString(GL_VERSION)); printf("%s context version parsed by GLFW: %u.%u.%u\n", get_api_name(client), major, minor, revision); // Report client API context properties if (client == GLFW_OPENGL_API) { if (major >= 3) { GLint flags; glGetIntegerv(GL_CONTEXT_FLAGS, &flags); printf("%s context flags (0x%08x):", get_api_name(client), flags); if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) printf(" forward-compatible"); if (flags & 2/*GL_CONTEXT_FLAG_DEBUG_BIT*/) printf(" debug"); if (flags & GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB) printf(" robustness"); if (flags & 8/*GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR*/) printf(" no-error"); putchar('\n'); printf("%s context flags parsed by GLFW:", get_api_name(client)); if (glfwGetWindowAttrib(window, GLFW_OPENGL_FORWARD_COMPAT)) printf(" forward-compatible"); if (glfwGetWindowAttrib(window, GLFW_OPENGL_DEBUG_CONTEXT)) printf(" debug"); if (glfwGetWindowAttrib(window, GLFW_CONTEXT_ROBUSTNESS) == GLFW_LOSE_CONTEXT_ON_RESET) printf(" robustness"); if (glfwGetWindowAttrib(window, GLFW_CONTEXT_NO_ERROR)) printf(" no-error"); putchar('\n'); } if (major >= 4 || (major == 3 && minor >= 2)) { GLint mask; glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask); printf("%s profile mask (0x%08x): %s\n", get_api_name(client), mask, get_profile_name_gl(mask)); printf("%s profile mask parsed by GLFW: %s\n", get_api_name(client), get_profile_name_glfw(profile)); } if (GLAD_GL_ARB_robustness) { const int robustness = glfwGetWindowAttrib(window, GLFW_CONTEXT_ROBUSTNESS); GLint strategy; glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &strategy); printf("%s robustness strategy (0x%08x): %s\n", get_api_name(client), strategy, get_strategy_name_gl(strategy)); printf("%s robustness strategy parsed by GLFW: %s\n", get_api_name(client), get_strategy_name_glfw(robustness)); } } printf("%s context renderer string: \"%s\"\n", get_api_name(client), glGetString(GL_RENDERER)); printf("%s context vendor string: \"%s\"\n", get_api_name(client), glGetString(GL_VENDOR)); if (major >= 2) { printf("%s context shading language version: \"%s\"\n", get_api_name(client), glGetString(GL_SHADING_LANGUAGE_VERSION)); } printf("%s framebuffer:\n", get_api_name(client)); if (client == GLFW_OPENGL_API && profile == GLFW_OPENGL_CORE_PROFILE) { glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_BACK_LEFT, GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, &redbits); glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_BACK_LEFT, GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE, &greenbits); glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_BACK_LEFT, GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE, &bluebits); glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_BACK_LEFT, GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE, &alphabits); glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH, GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE, &depthbits); glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE, &stencilbits); } else { glGetIntegerv(GL_RED_BITS, &redbits); glGetIntegerv(GL_GREEN_BITS, &greenbits); glGetIntegerv(GL_BLUE_BITS, &bluebits); glGetIntegerv(GL_ALPHA_BITS, &alphabits); glGetIntegerv(GL_DEPTH_BITS, &depthbits); glGetIntegerv(GL_STENCIL_BITS, &stencilbits); } printf(" red: %u green: %u blue: %u alpha: %u depth: %u stencil: %u\n", redbits, greenbits, bluebits, alphabits, depthbits, stencilbits); if (client == GLFW_OPENGL_ES_API || GLAD_GL_ARB_multisample || major > 1 || minor >= 3) { GLint samples, samplebuffers; glGetIntegerv(GL_SAMPLES, &samples); glGetIntegerv(GL_SAMPLE_BUFFERS, &samplebuffers); printf(" samples: %u sample buffers: %u\n", samples, samplebuffers); } if (client == GLFW_OPENGL_API && profile != GLFW_OPENGL_CORE_PROFILE) { GLint accumredbits, accumgreenbits, accumbluebits, accumalphabits; GLint auxbuffers; glGetIntegerv(GL_ACCUM_RED_BITS, &accumredbits); glGetIntegerv(GL_ACCUM_GREEN_BITS, &accumgreenbits); glGetIntegerv(GL_ACCUM_BLUE_BITS, &accumbluebits); glGetIntegerv(GL_ACCUM_ALPHA_BITS, &accumalphabits); glGetIntegerv(GL_AUX_BUFFERS, &auxbuffers); printf(" accum red: %u accum green: %u accum blue: %u accum alpha: %u aux buffers: %u\n", accumredbits, accumgreenbits, accumbluebits, accumalphabits, auxbuffers); } if (list_extensions) list_context_extensions(client, major, minor); printf("Vulkan loader: %s\n", glfwVulkanSupported() ? "available" : "missing"); if (glfwVulkanSupported()) { uint32_t i, re_count, pd_count; const char** re; VkApplicationInfo ai = {0}; VkInstanceCreateInfo ici = {0}; VkInstance instance; VkPhysicalDevice* pd; PFN_vkCreateInstance vkCreateInstance = (PFN_vkCreateInstance) glfwGetInstanceProcAddress(NULL, "vkCreateInstance"); PFN_vkDestroyInstance vkDestroyInstance; PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices; PFN_vkGetPhysicalDeviceProperties vkGetPhysicalDeviceProperties; re = glfwGetRequiredInstanceExtensions(&re_count); printf("Vulkan required instance extensions:"); for (i = 0; i < re_count; i++) printf(" %s", re[i]); putchar('\n'); if (list_extensions) list_vulkan_instance_extensions(); if (list_layers) list_vulkan_instance_layers(); ai.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; ai.pApplicationName = "glfwinfo"; ai.applicationVersion = GLFW_VERSION_MAJOR; ai.pEngineName = "GLFW"; ai.engineVersion = GLFW_VERSION_MAJOR; ai.apiVersion = VK_API_VERSION_1_0; ici.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; ici.pApplicationInfo = &ai; ici.enabledExtensionCount = re_count; ici.ppEnabledExtensionNames = re; if (vkCreateInstance(&ici, NULL, &instance) != VK_SUCCESS) { glfwTerminate(); exit(EXIT_FAILURE); } vkDestroyInstance = (PFN_vkDestroyInstance) glfwGetInstanceProcAddress(instance, "vkDestroyInstance"); vkEnumeratePhysicalDevices = (PFN_vkEnumeratePhysicalDevices) glfwGetInstanceProcAddress(instance, "vkEnumeratePhysicalDevices"); vkGetPhysicalDeviceProperties = (PFN_vkGetPhysicalDeviceProperties) glfwGetInstanceProcAddress(instance, "vkGetPhysicalDeviceProperties"); if (vkEnumeratePhysicalDevices(instance, &pd_count, NULL) != VK_SUCCESS) { vkDestroyInstance(instance, NULL); glfwTerminate(); exit(EXIT_FAILURE); } pd = calloc(pd_count, sizeof(VkPhysicalDevice)); if (vkEnumeratePhysicalDevices(instance, &pd_count, pd) != VK_SUCCESS) { free(pd); vkDestroyInstance(instance, NULL); glfwTerminate(); exit(EXIT_FAILURE); } for (i = 0; i < pd_count; i++) { VkPhysicalDeviceProperties pdp; vkGetPhysicalDeviceProperties(pd[i], &pdp); printf("Vulkan %s device: \"%s\"\n", get_device_type_name(pdp.deviceType), pdp.deviceName); if (list_extensions) list_vulkan_device_extensions(instance, pd[i]); if (list_layers) list_vulkan_device_layers(instance, pd[i]); } free(pd); vkDestroyInstance(instance, NULL); } glfwTerminate(); exit(EXIT_SUCCESS); }
bool Window::IsMinimised() const { return glfwGetWindowAttrib(window, GLFW_ICONIFIED) == GL_TRUE; }
GameEngine::GameEngine(const std::string& application_name, WindowMode windowMode) { glfwSetErrorCallback(ErrorCallback); if (!glfwInit()) { std::terminate(); } // Window creation GLFWmonitor *monitor = glfwGetPrimaryMonitor(); const GLFWvidmode *vidmode = glfwGetVideoMode(monitor); #ifdef USE_DEBUG_CONTEXT glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5); glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); #else glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5); #endif glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true); glfwWindowHint(GLFW_DEPTH_BITS, 24); glfwWindowHint(GLFW_STENCIL_BITS, 8); if (windowMode == WindowMode::kFullScreen) { window_ = glfwCreateWindow(vidmode->width, vidmode->height, application_name.c_str(), monitor, nullptr); } else { window_ = glfwCreateWindow(vidmode->width, vidmode->height, application_name.c_str(), nullptr, nullptr); } if (!window_) { std::cerr << "FATAL: Couldn't create a glfw window. Aborting now." << std::endl; glfwTerminate(); std::terminate(); } // Check the created OpenGL context's version int ogl_major_version = glfwGetWindowAttrib(window_, GLFW_CONTEXT_VERSION_MAJOR); int ogl_minor_version = glfwGetWindowAttrib(window_, GLFW_CONTEXT_VERSION_MINOR); std::cout << "OpenGL version: " << ogl_major_version << '.' << ogl_minor_version << std::endl; int width, height; glfwGetFramebufferSize(window_, &width, &height); std::cout << "Resolution: " << width << " x " << height << std::endl; if (ogl_major_version < 4 || (ogl_major_version == 4 && ogl_minor_version < 5)) { std::cerr << "At least OpenGL version 4.5 is required to run this program\n"; std::terminate(); } glfwMakeContextCurrent(window_); // No V-sync needed. glfwSwapInterval(0); bool success = gladLoadGL(); if (!success) { std::cerr << "gladLoadGL failed" << std::endl; std::terminate(); } #ifdef USE_DEBUG_CONTEXT glDebugMessageCallback(&DebugCallback, nullptr); #endif success = Label::InitializeTextRendering(); if (!success) { std::cerr << "Label::InitializeTextRendering failed" << std::endl; std::terminate(); } MeshRenderer::InitializeMeshDataStorage(); // Only initialize after the OpenGL context has been created shader_manager_ = make_unique<ShaderManager>(); // OpenGL initialization gl::Enable(gl::kDepthTest); glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE); // GLFW callbacks glfwSetWindowUserPointer(window_, this); glfwSetKeyCallback(window_, KeyCallback); glfwSetCharCallback(window_, CharCallback); glfwSetFramebufferSizeCallback(window_, ScreenResizeCallback); glfwSetScrollCallback(window_, MouseScrolledCallback); glfwSetMouseButtonCallback(window_, MouseButtonPressed); glfwSetCursorPosCallback(window_, MouseMoved); }