void EditBoxImplWin::openKeyboard() { if (_delegate != NULL) { _delegate->editBoxEditingDidBegin(_editBox); } EditBox* pEditBox = this->getEditBox(); if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) { CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox); ScriptEvent event(kCommonEvent,(void*)&data); ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); } std::string placeHolder = _labelPlaceHolder->getString(); if (placeHolder.length() == 0) placeHolder = "Enter value"; char pText[100]= {0}; std::string text = getText(); if (text.length()) strncpy(pText, text.c_str(), 100); GLView *glView = Director::getInstance()->getOpenGLView(); GLFWwindow *glfwWindow = glView->getWindow(); HWND hwnd = glfwGetWin32Window(glfwWindow); bool didChange = CWin32InputBox::InputBox("Input", placeHolder.c_str(), pText, 100, false, hwnd) == IDOK; if (didChange) setText(pText); if (_delegate != NULL) { if (didChange) _delegate->editBoxTextChanged(_editBox, getText()); _delegate->editBoxEditingDidEnd(_editBox); _delegate->editBoxReturn(_editBox); } }
bool ImGui_ImplGlfw_Init() { #if 0 ImGuiIO& io = ImGui::GetIO(); io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP; io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN; io.KeyMap[ImGuiKey_PageUp] = GLFW_KEY_PAGE_UP; io.KeyMap[ImGuiKey_PageDown] = GLFW_KEY_PAGE_DOWN; io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME; io.KeyMap[ImGuiKey_End] = GLFW_KEY_END; io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE; io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE; io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER; io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE; io.KeyMap[ImGuiKey_A] = GLFW_KEY_A; io.KeyMap[ImGuiKey_C] = GLFW_KEY_C; io.KeyMap[ImGuiKey_V] = GLFW_KEY_V; io.KeyMap[ImGuiKey_X] = GLFW_KEY_X; io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y; io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z; io.RenderDrawListsFn = ImGui_ImplGlfw_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer. io.SetClipboardTextFn = ImGui_ImplGlfw_SetClipboardText; io.GetClipboardTextFn = ImGui_ImplGlfw_GetClipboardText; io.ClipboardUserData = g_Window; #ifdef _WIN32 io.ImeWindowHandle = glfwGetWin32Window(g_Window); #endif #endif return true; }
//---------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------- void* Window_Imp_Win::GetWindowHandle() const { return glfwGetWin32Window(m_window); }
static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, GlfwClientApi client_api) { g_Window = window; g_Time = 0.0; // Setup back-end capabilities flags ImGuiIO& io = ImGui::GetIO(); io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional) io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used) io.BackendPlatformName = "imgui_impl_glfw"; // Keyboard mapping. ImGui will use those indices to peek into the io.KeysDown[] array. io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP; io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN; io.KeyMap[ImGuiKey_PageUp] = GLFW_KEY_PAGE_UP; io.KeyMap[ImGuiKey_PageDown] = GLFW_KEY_PAGE_DOWN; io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME; io.KeyMap[ImGuiKey_End] = GLFW_KEY_END; io.KeyMap[ImGuiKey_Insert] = GLFW_KEY_INSERT; io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE; io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE; io.KeyMap[ImGuiKey_Space] = GLFW_KEY_SPACE; io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER; io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE; io.KeyMap[ImGuiKey_A] = GLFW_KEY_A; io.KeyMap[ImGuiKey_C] = GLFW_KEY_C; io.KeyMap[ImGuiKey_V] = GLFW_KEY_V; io.KeyMap[ImGuiKey_X] = GLFW_KEY_X; io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y; io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z; io.SetClipboardTextFn = ImGui_ImplGlfw_SetClipboardText; io.GetClipboardTextFn = ImGui_ImplGlfw_GetClipboardText; io.ClipboardUserData = g_Window; #if defined(_WIN32) io.ImeWindowHandle = (void*)glfwGetWin32Window(g_Window); #endif g_MouseCursors[ImGuiMouseCursor_Arrow] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); g_MouseCursors[ImGuiMouseCursor_TextInput] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR); g_MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); // FIXME: GLFW doesn't have this. g_MouseCursors[ImGuiMouseCursor_ResizeNS] = glfwCreateStandardCursor(GLFW_VRESIZE_CURSOR); g_MouseCursors[ImGuiMouseCursor_ResizeEW] = glfwCreateStandardCursor(GLFW_HRESIZE_CURSOR); g_MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); // FIXME: GLFW doesn't have this. g_MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); // FIXME: GLFW doesn't have this. g_MouseCursors[ImGuiMouseCursor_Hand] = glfwCreateStandardCursor(GLFW_HAND_CURSOR); // Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any. g_PrevUserCallbackMousebutton = NULL; g_PrevUserCallbackScroll = NULL; g_PrevUserCallbackKey = NULL; g_PrevUserCallbackChar = NULL; if (install_callbacks) { g_PrevUserCallbackMousebutton = glfwSetMouseButtonCallback(window, ImGui_ImplGlfw_MouseButtonCallback); g_PrevUserCallbackScroll = glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback); g_PrevUserCallbackKey = glfwSetKeyCallback(window, ImGui_ImplGlfw_KeyCallback); g_PrevUserCallbackChar = glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback); } g_ClientApi = client_api; return true; }
bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float frameZoomFactor, bool resizable) { setViewName(viewName); _frameZoomFactor = frameZoomFactor; glfwWindowHint(GLFW_RESIZABLE,resizable?GL_TRUE:GL_FALSE); glfwWindowHint(GLFW_RED_BITS,_glContextAttrs.redBits); glfwWindowHint(GLFW_GREEN_BITS,_glContextAttrs.greenBits); glfwWindowHint(GLFW_BLUE_BITS,_glContextAttrs.blueBits); glfwWindowHint(GLFW_ALPHA_BITS,_glContextAttrs.alphaBits); glfwWindowHint(GLFW_DEPTH_BITS,_glContextAttrs.depthBits); glfwWindowHint(GLFW_STENCIL_BITS,_glContextAttrs.stencilBits); // Modified by Locke. glfwWindowHint(GLFW_VISIBLE, GL_FALSE); int needWidth = rect.size.width * _frameZoomFactor; int neeHeight = rect.size.height * _frameZoomFactor; _mainWindow = glfwCreateWindow(needWidth, neeHeight, _viewName.c_str(), _monitor, nullptr); if (_mainWindow == nullptr) { std::string message = "Can't create window"; if (!_glfwError.empty()) { message.append("\nMore info: \n"); message.append(_glfwError); } MessageBox(message.c_str(), "Error launch application"); return false; } /* * Note that the created window and context may differ from what you requested, * as not all parameters and hints are * [hard constraints](@ref window_hints_hard). This includes the size of the * window, especially for full screen windows. To retrieve the actual * attributes of the created window and context, use queries like @ref * glfwGetWindowAttrib and @ref glfwGetWindowSize. * * see declaration glfwCreateWindow */ int realW = 0, realH = 0; glfwGetWindowSize(_mainWindow, &realW, &realH); if (realW != needWidth) { rect.size.width = realW / _frameZoomFactor; } if (realH != neeHeight) { rect.size.height = realH / _frameZoomFactor; } glfwMakeContextCurrent(_mainWindow); glfwSetMouseButtonCallback(_mainWindow, GLFWEventHandler::onGLFWMouseCallBack); glfwSetCursorPosCallback(_mainWindow, GLFWEventHandler::onGLFWMouseMoveCallBack); glfwSetScrollCallback(_mainWindow, GLFWEventHandler::onGLFWMouseScrollCallback); glfwSetCharCallback(_mainWindow, GLFWEventHandler::onGLFWCharCallback); glfwSetKeyCallback(_mainWindow, GLFWEventHandler::onGLFWKeyCallback); glfwSetWindowPosCallback(_mainWindow, GLFWEventHandler::onGLFWWindowPosCallback); glfwSetFramebufferSizeCallback(_mainWindow, GLFWEventHandler::onGLFWframebuffersize); glfwSetWindowSizeCallback(_mainWindow, GLFWEventHandler::onGLFWWindowSizeFunCallback); glfwSetWindowIconifyCallback(_mainWindow, GLFWEventHandler::onGLFWWindowIconifyCallback); setFrameSize(rect.size.width, rect.size.height); // check OpenGL version at first const GLubyte* glVersion = glGetString(GL_VERSION); if ( utils::atof((const char*)glVersion) < 1.5 ) { char strComplain[256] = {0}; sprintf(strComplain, "OpenGL 1.5 or higher is required (your version is %s). Please upgrade the driver of your video card.", glVersion); MessageBox(strComplain, "OpenGL version too old"); return false; } initGlew(); // Enable point size by default. glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); //Locke m_hwnd = glfwGetWin32Window(_mainWindow); return true; }
io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE; io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE; io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER; io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE; io.KeyMap[ImGuiKey_A] = GLFW_KEY_A; io.KeyMap[ImGuiKey_C] = GLFW_KEY_C; io.KeyMap[ImGuiKey_V] = GLFW_KEY_V; io.KeyMap[ImGuiKey_X] = GLFW_KEY_X; io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y; io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z; io.RenderDrawListsFn = InterfaceRenderDrawList; io.SetClipboardTextFn = InterfaceSetClipboardText; io.GetClipboardTextFn = InterfaceGetClipboardText; #ifdef _WIN32 io.ImeWindowHandle = glfwGetWin32Window(GlobalWindow); #endif } void InterfaceShutdown(void) { InterfaceInvalidateDeviceObjects(); ImGui::Shutdown(); } void InterfaceUpdate(void) { if(!FontTexture) InterfaceCreateDeviceObjects(); ImGuiIO& io = ImGui::GetIO();
bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks, const char* glsl_version) { g_Window = window; // Store GL version string so we can refer to it later in case we recreate shaders. if (glsl_version == NULL) glsl_version = "#version 150"; IM_ASSERT((int)strlen(glsl_version) + 2 < IM_ARRAYSIZE(g_GlslVersion)); strcpy(g_GlslVersion, glsl_version); strcat(g_GlslVersion, "\n"); // Setup back-end capabilities flags ImGuiIO& io = ImGui::GetIO(); io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional) io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used) // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP; io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN; io.KeyMap[ImGuiKey_PageUp] = GLFW_KEY_PAGE_UP; io.KeyMap[ImGuiKey_PageDown] = GLFW_KEY_PAGE_DOWN; io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME; io.KeyMap[ImGuiKey_End] = GLFW_KEY_END; io.KeyMap[ImGuiKey_Insert] = GLFW_KEY_INSERT; io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE; io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE; io.KeyMap[ImGuiKey_Space] = GLFW_KEY_SPACE; io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER; io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE; io.KeyMap[ImGuiKey_A] = GLFW_KEY_A; io.KeyMap[ImGuiKey_C] = GLFW_KEY_C; io.KeyMap[ImGuiKey_V] = GLFW_KEY_V; io.KeyMap[ImGuiKey_X] = GLFW_KEY_X; io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y; io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z; io.SetClipboardTextFn = ImGui_ImplGlfwGL3_SetClipboardText; io.GetClipboardTextFn = ImGui_ImplGlfwGL3_GetClipboardText; io.ClipboardUserData = g_Window; #ifdef _WIN32 io.ImeWindowHandle = glfwGetWin32Window(g_Window); #endif // Load cursors // FIXME: GLFW doesn't expose suitable cursors for ResizeAll, ResizeNESW, ResizeNWSE. We revert to arrow cursor for those. g_MouseCursors[ImGuiMouseCursor_Arrow] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); g_MouseCursors[ImGuiMouseCursor_TextInput] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR); g_MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); g_MouseCursors[ImGuiMouseCursor_ResizeNS] = glfwCreateStandardCursor(GLFW_VRESIZE_CURSOR); g_MouseCursors[ImGuiMouseCursor_ResizeEW] = glfwCreateStandardCursor(GLFW_HRESIZE_CURSOR); g_MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); g_MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); if (install_callbacks) ImGui_ImplGlfw_InstallCallbacks(window); return true; }
int main(int argc, char** argv) { LOG_INFO("RiftRay version %s", pRiftRayVersion); #if defined(_WIN32) LOG_INFO("Windows build."); #elif defined(_LINUX) LOG_INFO("Linux build."); #elif defined(_MACOS) LOG_INFO("MacOS build."); #endif bool useOpenGLCoreContext = false; g_renderMode.outputType = RenderingMode::OVR_SDK; #ifdef USE_CORE_CONTEXT useOpenGLCoreContext = true; #endif #ifdef _LINUX // Linux driver seems to be lagging a bit useOpenGLCoreContext = false; #endif LOG_INFO("Using GLFW3 backend."); LOG_INFO("Compiled against GLFW %i.%i.%i", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR, GLFW_VERSION_REVISION); int major, minor, revision; glfwGetVersion(&major, &minor, &revision); LOG_INFO("Running against GLFW %i.%i.%i", major, minor, revision); LOG_INFO("glfwGetVersionString: %s", glfwGetVersionString()); // Command line options for (int i=0; i<argc; ++i) { const std::string a = argv[i]; LOG_INFO("argv[%d]: %s", i, a.c_str()); if (!a.compare("-sdk")) { g_renderMode.outputType = RenderingMode::OVR_SDK; } else if (!a.compare("-client")) { g_renderMode.outputType = RenderingMode::OVR_Client; } else if (!a.compare("-core")) { useOpenGLCoreContext = true; } else if (!a.compare("-compat")) { useOpenGLCoreContext = false; } } LoadConfigFile(); g_app.initHMD(); GLFWwindow* l_Window = NULL; glfwSetErrorCallback(ErrorCallback); if (!glfwInit()) { exit(EXIT_FAILURE); } #ifdef __APPLE__ // Set the working directory to the Resources dir of the .app bundle CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); char path[PATH_MAX]; CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX); CFRelease(resourcesURL); strcat( path, "/shaders" ); struct stat sb; if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) chdir(path); #endif #ifndef _LINUX glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); # if defined(_MACOS) glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); # else glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); # endif #endif //ndef _LINUX if (useOpenGLCoreContext) { LOG_INFO("Using OpenGL core context."); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); } else { #ifndef _LINUX glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); #endif } glfwWindowHint(GLFW_SAMPLES, 0); #ifdef _DEBUG glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); #endif std::string windowTitle = "RiftRay-v" + std::string(pRiftRayVersion); #ifdef USE_OCULUSSDK const ovrSizei sz = g_app.getHmdResolution(); const ovrVector2i pos = g_app.getHmdWindowPos(); if (g_app.UsingDebugHmd() == true) { // Create a normal, decorated application window LOG_INFO("Using Debug HMD mode."); windowTitle += "-GLFW-DebugHMD"; l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL); g_app.m_dashScene.m_bDraw = false; g_renderMode.outputType = RenderingMode::Mono_Buffered; } else if (g_app.UsingDirectMode()) { LOG_INFO("Using Direct to Rift mode."); windowTitle += "-GLFW-Direct"; l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL); #if defined(_WIN32) g_app.AttachToWindow((void*)glfwGetWin32Window(l_Window)); #endif } else { LOG_INFO("Using Extended desktop mode."); windowTitle += "-GLFW-Extended"; glfwWindowHint(GLFW_DECORATED, 0); l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL); glfwWindowHint(GLFW_DECORATED, 1); glfwSetWindowPos(l_Window, pos.x, pos.y); } resize(l_Window, sz.w, sz.h); // inform AppSkeleton of window size #else const glm::vec2 sz(800, 600); // Create a normal, decorated application window LOG_INFO("Using No VR SDK."); windowTitle += "-GLFW-NoVRSDK"; g_renderMode.outputType = RenderingMode::Mono_Buffered; l_Window = glfwCreateWindow(sz.x, sz.y, windowTitle.c_str(), NULL, NULL); resize(l_Window, sz.x, sz.y); // inform AppSkeleton of window size #endif //USE_OSVR|USE_OCULUSSDK if (!l_Window) { LOG_INFO("Glfw failed to create a window. Exiting."); glfwTerminate(); exit(EXIT_FAILURE); } #ifdef USE_OCULUSSDK // Required for SDK rendering (to do the buffer swap on its own) # if defined(_WIN32) g_app.setWindow(glfwGetWin32Window(l_Window)); # elif defined(__linux__) g_app.setWindow(glfwGetX11Display()); # endif #endif glfwMakeContextCurrent(l_Window); glfwSetWindowSizeCallback(l_Window, resize); glfwSetMouseButtonCallback(l_Window, mouseDown); glfwSetCursorPosCallback(l_Window, mouseMove); glfwSetScrollCallback(l_Window, mouseWheel); glfwSetKeyCallback(l_Window, keyboard); memset(m_keyStates, 0, GLFW_KEY_LAST*sizeof(int)); FindPreferredJoystick(); // Log system monitor information const GLFWmonitor* pPrimary = glfwGetPrimaryMonitor(); int monitorCount = 0; GLFWmonitor** ppMonitors = glfwGetMonitors(&monitorCount); for (int i=0; i<monitorCount; ++i) { GLFWmonitor* pCur = ppMonitors[i]; const GLFWvidmode* mode = glfwGetVideoMode(pCur); if (mode != NULL) { LOG_INFO("Monitor #%d: %dx%d @ %dHz %s", i, mode->width, mode->height, mode->refreshRate, pCur==pPrimary ? "Primary":""); } } printGLContextInfo(l_Window); glfwMakeContextCurrent(l_Window); g_pHMDWindow = l_Window; // Don't forget to initialize Glew, turn glewExperimental on to // avoid problems fetching function pointers... glewExperimental = GL_TRUE; const GLenum l_Result = glewInit(); if (l_Result != GLEW_OK) { LOG_INFO("glewInit() error."); exit(EXIT_FAILURE); } #ifdef _DEBUG // Debug callback initialization // Must be done *after* glew initialization. glDebugMessageCallback(myCallback, NULL); glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0, GL_DEBUG_SEVERITY_NOTIFICATION, -1, "Start debugging"); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); #endif #ifdef USE_ANTTWEAKBAR LOG_INFO("Using AntTweakbar."); TwInit(useOpenGLCoreContext ? TW_OPENGL_CORE : TW_OPENGL, NULL); InitializeBar(); #endif LOG_INFO("Calling initGL..."); g_app.initGL(); LOG_INFO("Calling initVR..."); g_app.initVR(); LOG_INFO("initVR complete."); SetVsync(1); // default to vsync on StartShaderLoad(); while (!glfwWindowShouldClose(l_Window)) { const bool tapped = g_app.CheckForTapOnHmd(); if (tapped && (g_receivedFirstTap == false)) { g_app.RecenterPose(); g_receivedFirstTap = true; } glfwPollEvents(); joystick(); timestep(); g_fps.OnFrame(); if (g_dynamicallyScaleFBO) { DynamicallyScaleFBO(); } #ifdef USE_ANTTWEAKBAR TwRefreshBar(g_pTweakbar); TwRefreshBar(g_pShaderTweakbar); #endif displayToHMD(); #ifndef _LINUX // Indicate FPS in window title // This is absolute death for performance in Ubuntu Linux 12.04 { std::ostringstream oss; oss << windowTitle << " " << static_cast<int>(g_fps.GetFPS()) << " fps"; glfwSetWindowTitle(l_Window, oss.str().c_str()); if (g_AuxWindow != NULL) glfwSetWindowTitle(g_AuxWindow, oss.str().c_str()); } #endif const float dumpInterval = 1.f; if (g_logDumpTimer.seconds() > dumpInterval) { LOG_INFO("Frame rate: %d fps", static_cast<int>(g_fps.GetFPS())); g_logDumpTimer.reset(); } // Optionally display to auxiliary mono view if (g_AuxWindow != NULL) { glfwMakeContextCurrent(g_AuxWindow); glClearColor(0.f, 0.f, 0.f, 0.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ///@note VAOs *cannot* be shared between contexts. ///@note GLFW windows are inextricably tied to their own unique context. /// For these two reasons, calling draw a third time for the auxiliary window /// is not possible. Furthermore, it is not strictly desirable for the extra /// rendering cost. /// Instead, we share the render target texture from the stereo render and present /// just the left eye to the aux window. if (g_drawToAuxWindow) { presentSharedFboTexture(); } #ifdef USE_ANTTWEAKBAR TwDraw(); ///@todo Should this go first? Will it write to a depth buffer? #endif glfwSwapBuffers(g_AuxWindow); if (glfwWindowShouldClose(g_AuxWindow)) { destroyAuxiliaryWindow(g_AuxWindow); } // Set context to Rift window when done glfwMakeContextCurrent(l_Window); } } g_app.exitVR(); glfwDestroyWindow(l_Window); glfwTerminate(); exit(EXIT_SUCCESS); }
bool is_gui_aligned(GLFWwindow *win) { #ifdef _WIN32 try { auto hwn = glfwGetWin32Window(win); if (hwn == nullptr) return true; auto flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBringToFrontOnFocus; ImGui::SetNextWindowPos({ 0, 0 }); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); ImGui::Begin("is_gui_aligned", nullptr, flags); auto DrawList = ImGui::GetWindowDrawList(); if (DrawList == nullptr) return true; DrawList->AddRectFilled({ 0,0 }, { 1,1 }, ImColor(MAGIC / 255.f, 0.f, 0.f, 1.f)); ImGui::End(); ImGui::PopStyleVar(); ImGui::Render(); glfwSwapBuffers(win); ImGui_ImplGlfw_NewFrame(1.f); SetFocus(hwn); int width = 1; int height = 1; HDC hdc = GetDC(hwn); if (hdc == nullptr) return true; std::shared_ptr<HDC> shared_hdc(&hdc, [&](HDC* hdc) {ReleaseDC(hwn, *hdc); DeleteDC(*hdc);}); HDC hCaptureDC = CreateCompatibleDC(hdc); if (hCaptureDC == nullptr) return true; std::shared_ptr<HDC> shared_capture_hdc(&hCaptureDC, [&](HDC* hdc) {ReleaseDC(hwn, *hdc); DeleteDC(*hdc);}); HBITMAP hCaptureBitmap = CreateCompatibleBitmap(hdc, width, height); if (hCaptureBitmap == nullptr) return true; std::shared_ptr<HBITMAP> shared_bmp(&hCaptureBitmap, [&](HBITMAP* bmp) {DeleteObject(bmp);}); auto original = SelectObject(hCaptureDC, hCaptureBitmap); if (original == nullptr) return true; if (!BitBlt(hCaptureDC, 0, 0, width, height, hdc, 0, 0, SRCCOPY | CAPTUREBLT)) return true; BITMAPINFO bmi = { 0 }; bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); bmi.bmiHeader.biWidth = width; bmi.bmiHeader.biHeight = height; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; std::vector<RGBQUAD> pPixels(width * height); auto res = GetDIBits( hCaptureDC, hCaptureBitmap, 0, height, pPixels.data(), &bmi, DIB_RGB_COLORS ); if (res <= 0 || res == ERROR_INVALID_PARAMETER) return true; auto ret = pPixels[0].rgbRed == MAGIC; return ret; } catch (...) { return true; } #else return true; #endif }
int main(int argc, char** argv) { #if defined(_WIN32) LOG_INFO("Windows build."); #elif defined(_LINUX) LOG_INFO("Linux build."); LOG_INFO("DISPLAY=%s", getenv("DISPLAY")); #elif defined(_MACOS) LOG_INFO("MacOS build."); #endif bool useOpenGLCoreContext = false; #ifdef USE_CORE_CONTEXT useOpenGLCoreContext = true; #endif g_renderMode.outputType = RenderingMode::OVR_SDK; LOG_INFO("Using GLFW3 backend."); LOG_INFO("Compiled against GLFW %i.%i.%i", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR, GLFW_VERSION_REVISION); int major, minor, revision; glfwGetVersion(&major, &minor, &revision); LOG_INFO("Running against GLFW %i.%i.%i", major, minor, revision); LOG_INFO("glfwGetVersionString: %s", glfwGetVersionString()); // Command line options for (int i=0; i<argc; ++i) { const std::string a = argv[i]; LOG_INFO("argv[%d]: %s", i, a.c_str()); if (!a.compare("-sdk")) { g_renderMode.outputType = RenderingMode::OVR_SDK; } else if (!a.compare("-client")) { g_renderMode.outputType = RenderingMode::OVR_Client; } else if (!a.compare("-core")) { useOpenGLCoreContext = true; } else if (!a.compare("-compat")) { useOpenGLCoreContext = false; } } #ifdef USE_OCULUSSDK g_app.initHMD(); #else g_renderMode.outputType = RenderingMode::Mono_Buffered; #endif GLFWwindow* l_Window = NULL; glfwSetErrorCallback(ErrorCallback); if (!glfwInit()) { exit(EXIT_FAILURE); } // Log system monitor information const GLFWmonitor* pPrimary = glfwGetPrimaryMonitor(); int monitorCount = 0; GLFWmonitor** ppMonitors = glfwGetMonitors(&monitorCount); for (int i=0; i<monitorCount; ++i) { GLFWmonitor* pCur = ppMonitors[i]; const GLFWvidmode* mode = glfwGetVideoMode(pCur); if (mode != NULL) { (void)pPrimary; LOG_INFO("Monitor #%d: %dx%d @ %dHz %s", i, mode->width, mode->height, mode->refreshRate, pCur==pPrimary ? "Primary":""); } } bool swapBackBufferDims = false; // Context setup - before window creation glfwWindowHint(GLFW_DEPTH_BITS, 16); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, useOpenGLCoreContext ? GLFW_OPENGL_CORE_PROFILE : GLFW_OPENGL_COMPAT_PROFILE); //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); #ifdef _DEBUG glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); #endif #if defined(USE_OSVR) LOG_INFO("USE_OSVR=1"); std::string windowTitle = ""; windowTitle = PROJECT_NAME "-GLFW-Osvr"; if (g_app.UsingDebugHmd()) { const hmdRes sz = { 800, 600 }; // Create a normal, decorated application window LOG_INFO("Using Debug HMD mode."); windowTitle = PROJECT_NAME "-GLFW-DebugHMD"; g_renderMode.outputType = RenderingMode::Mono_Buffered; l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL); } else { const hmdRes sz = { g_app.getHmdResolution().h, g_app.getHmdResolution().w }; const winPos pos = g_app.getHmdWindowPos(); g_renderMode.outputType = RenderingMode::SideBySide_Undistorted; LOG_INFO("Using Extended desktop mode."); windowTitle = PROJECT_NAME "-GLFW-Extended"; LOG_INFO("Creating GLFW_DECORATED window %dx%d@%d,%d", sz.w, sz.h, pos.x, pos.y); glfwWindowHint(GLFW_DECORATED, 0); l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL); glfwWindowHint(GLFW_DECORATED, 1); glfwSetInputMode(l_Window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSetWindowPos(l_Window, pos.x, pos.y); } #elif defined(USE_OCULUSSDK) LOG_INFO("USE_OCULUSSDK=1"); ovrSizei sz = g_app.getHmdResolution(); const ovrVector2i pos = g_app.getHmdWindowPos(); std::string windowTitle = ""; if (g_app.UsingDebugHmd() == true) { // Create a normal, decorated application window LOG_INFO("Using Debug HMD mode."); windowTitle = PROJECT_NAME "-GLFW-DebugHMD"; g_renderMode.outputType = RenderingMode::Mono_Buffered; l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL); } else if (g_app.UsingDirectMode()) { // HMD active - position undecorated window to fill HMD viewport LOG_INFO("Using Direct to Rift mode."); windowTitle = PROJECT_NAME "-GLFW-Direct"; GLFWmonitor* monitor = glfwGetPrimaryMonitor(); const GLFWvidmode* mode = glfwGetVideoMode(monitor); sz.w = mode->width; sz.h = mode->height; LOG_INFO("Creating window %dx%d@%d,%d", sz.w, sz.h, pos.x, pos.y); l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), monitor, NULL); glfwSetInputMode(l_Window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); #ifdef _LINUX swapBackBufferDims = true; #endif #if defined(_WIN32) g_app.AttachToWindow((void*)glfwGetWin32Window(l_Window)); #endif } else { LOG_INFO("Using Extended desktop mode."); windowTitle = PROJECT_NAME "-GLFW-Extended"; LOG_INFO("Creating GLFW_DECORATED window %dx%d@%d,%d", sz.w, sz.h, pos.x, pos.y); glfwWindowHint(GLFW_DECORATED, 0); l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL); glfwWindowHint(GLFW_DECORATED, 1); glfwSetInputMode(l_Window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSetWindowPos(l_Window, pos.x, pos.y); } resize(l_Window, sz.w, sz.h); // inform AppSkeleton of window size #else const glm::vec2 sz(800, 600); // Create a normal, decorated application window LOG_INFO("Using No VR SDK."); const std::string windowTitle = PROJECT_NAME "-GLFW-NoVRSDK"; g_renderMode.outputType = RenderingMode::Mono_Buffered; l_Window = glfwCreateWindow(sz.x, sz.y, windowTitle.c_str(), NULL, NULL); #endif //USE_OSVR|USE_OCULUSSDK if (!l_Window) { LOG_INFO("Glfw failed to create a window. Exiting."); glfwTerminate(); exit(EXIT_FAILURE); } // Required for SDK rendering (to do the buffer swap on its own) #ifdef OVRSDK05 #if defined(_WIN32) g_app.setWindow(glfwGetWin32Window(l_Window)); #elif defined(__linux__) g_app.setWindow(NULL);//glfwGetX11Display()); #endif #endif //USE_OCULUSSDK glfwMakeContextCurrent(l_Window); glfwSetWindowSizeCallback(l_Window, resize); glfwSetMouseButtonCallback(l_Window, mouseDown); glfwSetCursorPosCallback(l_Window, mouseMove); glfwSetScrollCallback(l_Window, mouseWheel); glfwSetKeyCallback(l_Window, keyboard); memset(m_keyStates, 0, GLFW_KEY_LAST*sizeof(int)); // joysticks for (int i = GLFW_JOYSTICK_1; i <= GLFW_JOYSTICK_LAST; ++i) { if (GL_FALSE == glfwJoystickPresent(i)) continue; const char* pJoyName = glfwGetJoystickName(i); if (pJoyName == NULL) continue; int numAxes = 0; int numButtons = 0; glfwGetJoystickAxes(i, &numAxes); glfwGetJoystickButtons(i, &numButtons); LOG_INFO("Glfw opened Joystick #%d: %s w/ %d axes, %d buttons", i, pJoyName, numAxes, numButtons); if (g_joystickIdx == -1) g_joystickIdx = i; } printGLContextInfo(l_Window); glfwMakeContextCurrent(l_Window); g_pHMDWindow = l_Window; // Don't forget to initialize Glew, turn glewExperimental on to // avoid problems fetching function pointers... glewExperimental = GL_TRUE; const GLenum l_Result = glewInit(); if (l_Result != GLEW_OK) { LOG_INFO("glewInit() error."); exit(EXIT_FAILURE); } #ifdef _DEBUG // Debug callback initialization // Must be done *after* glew initialization. glDebugMessageCallback(myCallback, NULL); glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0, GL_DEBUG_SEVERITY_NOTIFICATION, -1 , "Start debugging"); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); #endif #ifdef USE_ANTTWEAKBAR LOG_INFO("Using AntTweakbar."); TwInit(useOpenGLCoreContext ? TW_OPENGL_CORE : TW_OPENGL, NULL); InitializeBar(); #endif LOG_INFO("Calling initGL..."); g_app.initGL(); LOG_INFO("Calling initVR..."); g_app.initVR(swapBackBufferDims); LOG_INFO("initVR(%d) complete.", swapBackBufferDims); while (!glfwWindowShouldClose(l_Window)) { g_app.CheckForTapToDismissHealthAndSafetyWarning(); glfwPollEvents(); joystick(); timestep(); g_fps.OnFrame(); if (g_dynamicallyScaleFBO) { DynamicallyScaleFBO(); } #ifdef USE_ANTTWEAKBAR TwRefreshBar(g_pTweakbar); #endif displayToHMD(); #ifndef _LINUX // Indicate FPS in window title // This is absolute death for performance in Ubuntu Linux 12.04 { std::ostringstream oss; oss << windowTitle << " " << static_cast<int>(g_fps.GetFPS()) << " fps"; glfwSetWindowTitle(l_Window, oss.str().c_str()); if (g_AuxWindow != NULL) glfwSetWindowTitle(g_AuxWindow, oss.str().c_str()); } #endif const float dumpInterval = 1.f; if (g_logDumpTimer.seconds() > dumpInterval) { LOG_INFO("Frame rate: %d fps", static_cast<int>(g_fps.GetFPS())); g_logDumpTimer.reset(); } // Optionally display to auxiliary mono view if (g_AuxWindow != NULL) { glfwMakeContextCurrent(g_AuxWindow); glClearColor(0.f, 0.f, 0.f, 0.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ///@note VAOs *cannot* be shared between contexts. ///@note GLFW windows are inextricably tied to their own unique context. /// For these two reasons, calling draw a third time for the auxiliary window /// is not possible. Furthermore, it is not strictly desirable for the extra /// rendering cost. /// Instead, we share the render target texture from the stereo render and present /// just the left eye to the aux window. if (g_drawToAuxWindow) { presentSharedFboTexture(); } #ifdef USE_ANTTWEAKBAR TwDraw(); ///@todo Should this go first? Will it write to a depth buffer? #endif glfwSwapBuffers(g_AuxWindow); if (glfwWindowShouldClose(g_AuxWindow)) { destroyAuxiliaryWindow(g_AuxWindow); } // Set context to Rift window when done glfwMakeContextCurrent(l_Window); } } g_app.exitVR(); glfwDestroyWindow(l_Window); glfwTerminate(); exit(EXIT_SUCCESS); }
OculusManager& OculusManager::getOculusManager() { static OculusManager* oculusManager = NULL; if (oculusManager == NULL) { oculusManager = new OculusManager(); if (!ovr_Initialize()) { fprintf(stderr, "Failed to initialize the Oculus SDK"); } //= *OculusManager::getHmd(); g_Hmd = ovrHmd_Create(0); if (!g_Hmd) { printf("No Oculus Rift device attached, using virtual version...\n"); g_Hmd = ovrHmd_CreateDebug(ovrHmd_DK2); } printf("initialized HMD: %s - %s\n", g_Hmd->Manufacturer, g_Hmd->ProductName); if (!glfwInit()) exit(EXIT_FAILURE); if (l_MultiSampling) glfwWindowHint(GLFW_SAMPLES, 4); else glfwWindowHint(GLFW_SAMPLES, 0); bool l_DirectMode = ((g_Hmd->HmdCaps & ovrHmdCap_ExtendDesktop) == 0); GLFWmonitor* l_Monitor; ovrSizei l_ClientSize; if (l_DirectMode) { printf("Running in \"Direct\" mode...\n"); l_Monitor = NULL; l_ClientSize.w = g_Hmd->Resolution.w / 2; // Something reasonable, smaller, but maintain aspect ratio... l_ClientSize.h = g_Hmd->Resolution.h / 2; // Something reasonable, smaller, but maintain aspect ratio... } else // Extended Desktop mode... { printf("Running in \"Extended Desktop\" mode...\n"); int l_Count; GLFWmonitor** l_Monitors = glfwGetMonitors(&l_Count); switch (l_Count) { case 0: printf("No monitors found, exiting...\n"); exit(EXIT_FAILURE); break; case 1: printf("Two monitors expected, found only one, using primary...\n"); l_Monitor = glfwGetPrimaryMonitor(); break; case 2: printf("Two monitors found, using second monitor...\n"); l_Monitor = l_Monitors[1]; break; default: printf("More than two monitors found, using second monitor...\n"); l_Monitor = l_Monitors[1]; } l_ClientSize.w = g_Hmd->Resolution.w; // 1920 for DK2... l_ClientSize.h = g_Hmd->Resolution.h; // 1080 for DK2... } l_Window = glfwCreateWindow(l_ClientSize.w, l_ClientSize.h, "GLFW Oculus Rift Test", l_Monitor, NULL); if (!l_Window) { glfwTerminate(); exit(EXIT_FAILURE); } #if defined(_WIN32) if (l_DirectMode) { ovrBool l_AttachResult = ovrHmd_AttachToWindow(g_Hmd, glfwGetWin32Window(l_Window), NULL, NULL); if (!l_AttachResult) { printf("Could not attach to window..."); exit(EXIT_FAILURE); } } #endif glfwMakeContextCurrent(l_Window); glewExperimental = GL_TRUE; GLenum l_GlewResult = glewInit(); if (l_GlewResult != GLEW_OK) { printf("glewInit() error.\n"); exit(EXIT_FAILURE); } int l_Major = glfwGetWindowAttrib(l_Window, GLFW_CONTEXT_VERSION_MAJOR); int l_Minor = glfwGetWindowAttrib(l_Window, GLFW_CONTEXT_VERSION_MINOR); int l_Profile = glfwGetWindowAttrib(l_Window, GLFW_OPENGL_PROFILE); printf("OpenGL: %d.%d ", l_Major, l_Minor); if (l_Major >= 3) // Profiles introduced in OpenGL 3.0... { if (l_Profile == GLFW_OPENGL_COMPAT_PROFILE) printf("GLFW_OPENGL_COMPAT_PROFILE\n"); else printf("GLFW_OPENGL_CORE_PROFILE\n"); } printf("Vendor: %s\n", (char*)glGetString(GL_VENDOR)); printf("Renderer: %s\n", (char*)glGetString(GL_RENDERER)); ovrSizei l_EyeTextureSizes[2]; l_EyeTextureSizes[ovrEye_Left] = ovrHmd_GetFovTextureSize(g_Hmd, ovrEye_Left, g_Hmd->MaxEyeFov[ovrEye_Left], 1.0f); l_EyeTextureSizes[ovrEye_Right] = ovrHmd_GetFovTextureSize(g_Hmd, ovrEye_Right, g_Hmd->MaxEyeFov[ovrEye_Right], 1.0f); // Combine for one texture for both eyes... g_RenderTargetSize.w = l_EyeTextureSizes[ovrEye_Left].w + l_EyeTextureSizes[ovrEye_Right].w; g_RenderTargetSize.h = (l_EyeTextureSizes[ovrEye_Left].h > l_EyeTextureSizes[ovrEye_Right].h ? l_EyeTextureSizes[ovrEye_Left].h : l_EyeTextureSizes[ovrEye_Right].h); // Create the FBO being a single one for both eyes (this is open for debate)... glGenFramebuffers(1, &l_FBOId); glBindFramebuffer(GL_FRAMEBUFFER, l_FBOId); // The texture we're going to render to... glGenTextures(1, &l_TextureId); // "Bind" the newly created texture : all future texture functions will modify this texture... glBindTexture(GL_TEXTURE_2D, l_TextureId); // Give an empty image to OpenGL (the last "0") glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, g_RenderTargetSize.w, g_RenderTargetSize.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); // Linear filtering... glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Create Depth Buffer... glGenRenderbuffers(1, &l_DepthBufferId); glBindRenderbuffer(GL_RENDERBUFFER, l_DepthBufferId); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, g_RenderTargetSize.w, g_RenderTargetSize.h); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, l_DepthBufferId); // Set the texture as our colour attachment #0... glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, l_TextureId, 0); // Set the list of draw buffers... GLenum l_GLDrawBuffers[1] = { GL_COLOR_ATTACHMENT0 }; glDrawBuffers(1, l_GLDrawBuffers); // "1" is the size of DrawBuffers // Check if everything is OK... GLenum l_Check = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); if (l_Check != GL_FRAMEBUFFER_COMPLETE) { printf("There is a problem with the FBO.\n"); exit(EXIT_FAILURE); } // Unbind... glBindRenderbuffer(GL_RENDERBUFFER, 0); glBindTexture(GL_TEXTURE_2D, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0); // Setup textures for each eye... // Left eye... g_EyeTextures[ovrEye_Left].Header.API = ovrRenderAPI_OpenGL; g_EyeTextures[ovrEye_Left].Header.TextureSize = g_RenderTargetSize; g_EyeTextures[ovrEye_Left].Header.RenderViewport.Pos.x = 0; g_EyeTextures[ovrEye_Left].Header.RenderViewport.Pos.y = 0; g_EyeTextures[ovrEye_Left].Header.RenderViewport.Size = l_EyeTextureSizes[ovrEye_Left]; ((ovrGLTexture&)(g_EyeTextures[ovrEye_Left])).OGL.TexId = l_TextureId; // Right eye (mostly the same as left but with the viewport on the right side of the texture)... g_EyeTextures[ovrEye_Right] = g_EyeTextures[ovrEye_Left]; g_EyeTextures[ovrEye_Right].Header.RenderViewport.Pos.x = (g_RenderTargetSize.w + 1) / 2; g_EyeTextures[ovrEye_Right].Header.RenderViewport.Pos.y = 0; // Oculus Rift eye configurations... g_Cfg.OGL.Header.API = ovrRenderAPI_OpenGL; g_Cfg.OGL.Header.RTSize.w = l_ClientSize.w; g_Cfg.OGL.Header.RTSize.h = l_ClientSize.h; g_Cfg.OGL.Header.Multisample = (l_MultiSampling ? 1 : 0); #if defined(_WIN32) g_Cfg.OGL.Window = glfwGetWin32Window(l_Window); g_Cfg.OGL.DC = GetDC(g_Cfg.OGL.Window); #elif defined(__linux__) l_Cfg.OGL.Win = glfwGetX11Window(l_Window); l_Cfg.OGL.Disp = glfwGetX11Display(); #endif // Enable capabilities... // ovrHmd_SetEnabledCaps(g_Hmd, ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction); ovrBool l_ConfigureResult = ovrHmd_ConfigureRendering(g_Hmd, &g_Cfg.Config, g_DistortionCaps, g_Hmd->MaxEyeFov, g_EyeRenderDesc); glUseProgram(0); // Avoid OpenGL state leak in ovrHmd_ConfigureRendering... if (!l_ConfigureResult) { printf("Configure failed.\n"); exit(EXIT_FAILURE); } // Start the sensor which provides the Rift’s pose and motion... uint32_t l_SupportedSensorCaps = ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position; uint32_t l_RequiredTrackingCaps = 0; ovrBool l_TrackingResult = ovrHmd_ConfigureTracking(g_Hmd, l_SupportedSensorCaps, l_RequiredTrackingCaps); if (!l_TrackingResult) { printf("Could not start tracking..."); exit(EXIT_FAILURE); } // Projection matrici for each eye will not change at runtime, we can set them here... g_ProjectionMatrici[ovrEye_Left] = ovrMatrix4f_Projection(g_EyeRenderDesc[ovrEye_Left].Fov, 0.3f, 100.0f, true); g_ProjectionMatrici[ovrEye_Right] = ovrMatrix4f_Projection(g_EyeRenderDesc[ovrEye_Right].Fov, 0.3f, 100.0f, true); // IPD offset values will not change at runtime, we can set them here... g_EyeOffsets[ovrEye_Left] = g_EyeRenderDesc[ovrEye_Left].HmdToEyeViewOffset; g_EyeOffsets[ovrEye_Right] = g_EyeRenderDesc[ovrEye_Right].HmdToEyeViewOffset; ovrHmd_RecenterPose(g_Hmd); return *oculusManager; } }