bool Init(GLFWwindow* window, bool install_callbacks) { g_Window = window; 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 = RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer. io.SetClipboardTextFn = SetClipboardText; io.GetClipboardTextFn = GetClipboardText; #ifdef _WIN32 io.ImeWindowHandle = glfwGetWin32Window(g_Window); #endif if (install_callbacks) { glfwSetMouseButtonCallback(window, MouseButtonCallback); glfwSetScrollCallback(window, ScrollCallback); glfwSetKeyCallback(window, KeyCallback); glfwSetCharCallback(window, CharCallback); } return true; }
bool Window::Init() { if (!glfwInit()) { std::cout << "Could not initialize GLFW!" << std::endl; return false; } glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); m_Window = glfwCreateWindow(m_Width, m_Height, m_Title, nullptr, nullptr); if (!m_Window) { std::cout << "Could not initialize GLFW Window!" << std::endl; return false; } glfwMakeContextCurrent(m_Window); glClearColor(0.2f, 0.3f, 0.8f, 1.0f); glfwSetWindowUserPointer(m_Window, this); glfwSetFramebufferSizeCallback(m_Window, WindowResize); glfwSetKeyCallback(m_Window, KeyCallback); glfwSetMouseButtonCallback(m_Window, MouseButtonCallback); glfwSetCursorPosCallback(m_Window, MouseMovementCallback); if (glewInit() != GLEW_OK) { std::cout << "Could not initialize GLEW!" << std::endl; return false; } glfwSwapInterval(0); glEnable(GL_DEPTH_TEST); return true; }
void Application::run(Application* the_app) { bool running = true; app = the_app; if( !glfwInit()) { fprintf(stderr, "Failed to initialize GLFW!\n"); exit(-1); } GLFWwindow* window; glfwWindowHint(GLFW_SAMPLES, 8); window = glfwCreateWindow(800, 600, "OpenGL Demo", NULL, NULL); glfwMakeContextCurrent(window); glewExperimental = true; if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initalize GLEW!\n"); exit(-1); } glfwSetMouseButtonCallback(window, glfw_onMouseButton); glfwSetCursorPosCallback(window, glfw_onMouseMove); glfwSetScrollCallback(window, glfw_onMouseWheel); glfwSetKeyCallback(window, glfw_onKey); glfwSetWindowSizeCallback(window, glfw_onResize); startup(); do { render(glfwGetTime()); running &= (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_RELEASE); glfwPollEvents(); glfwSwapBuffers(window); } while(running); shutdown(); glfwTerminate(); }
void setupAntTweakBar() { TwInit(TW_OPENGL_CORE, NULL); #if 0 barWindow = glfwCreateWindow(400, 400, "Param", NULL, NULL); TwSetCurrentWindow(barWindow); #endif bar = TwNewBar("Param"); WindowSizeCB(window, width, height); glfwSetWindowSizeCallback(window, WindowSizeCB); glfwSetMouseButtonCallback(window, TwEventMouseButtonGLFW); glfwSetCursorPosCallback(window, TwEvenCursorPosGLFW); glfwSetScrollCallback(window, TwEventScrollGLFW); glfwSetKeyCallback(window, TwEventKeyGLFW); glfwSetCharCallback(window, TwEventCharGLFW); TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLFW and OpenGL.' "); // Message added to the help bar. }
void veViewerDesktop::create() { if (_hwnd) return; _hwnd = glfwCreateWindow(_width, _height, _title.c_str(), nullptr, _sharedViewer? _sharedViewer->_hwnd: nullptr); glfwSetWindowUserPointer(_hwnd, this); glfwSetKeyCallback(_hwnd, collectKeyEvent); glfwSetCharCallback(_hwnd, collectCharEvent); glfwSetMouseButtonCallback(_hwnd, collectMouseEvent); glfwSetCursorPosCallback(_hwnd, collectMouseMoveEvent); glfwSetScrollCallback(_hwnd, collectScrollEvent); glfwSetWindowSizeCallback(_hwnd, collectWindowSizeEvent); glfwSetWindowFocusCallback(_hwnd, collectWindowFocusEvent); glfwSetWindowCloseCallback(_hwnd, collectWindowClose); _currentEvent.setEventType(veEvent::VE_WIN_INIT); _currentEvent.setWindowWidth(_width); _currentEvent.setWindowHeight(_height); _eventList.push_back(_currentEvent); }
void create(APPLICATION * app, int w, int h, const char * name="demo"){ interface.app = app; mWidth = w; mHeight = h; window = glfwCreateWindow(w,h,name,NULL ,NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } glfwMakeContextCurrent(window); glfwSwapInterval(1); //<-- force interval (not guaranteed to work with all graphics drivers) //register callbacks for keyboard and mouse glfwSetKeyCallback(window, Interface::OnKeyDown<APPLICATION>); glfwSetCursorPosCallback(window, Interface::OnMouseMove<APPLICATION> ); glfwSetMouseButtonCallback(window, Interface::OnMouseDown<APPLICATION> ); }
void OpenGLRenderer::Initialize(int argc, char* argv[]) { OpenGLRenderer::MainCamera = Camera(); OpenGLRenderer::Depth = 10.0f; OpenGLRenderer::MainCamera.setPosition(glm::vec3(0.0f, 0.0f, OpenGLRenderer::Depth)); OpenGLRenderer::MainCamera.lookAt(glm::vec3(0.0f, 0.0f, 0.0f)); OpenGLRenderer::MainCamera.setViewportAspectRatio(OpenGLRenderer::windowWidth / OpenGLRenderer::windowHeight); OpenGLRenderer::CameraSpeed = 10.0f; OpenGLRenderer::CameraSensitivity = 0.5f; glfwInit(); OpenGLRenderer::window = glfwCreateWindow(OpenGLRenderer::windowWidth, OpenGLRenderer::windowHeight, "Sound Analyzer", NULL, NULL); glfwMakeContextCurrent(OpenGLRenderer::window); glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); glfwSetKeyCallback(window, KeyboardFunc); glfwSetMouseButtonCallback(window, MouseFunc); glfwSetCursorPosCallback(window, MotionFunc); }
void shovelerInputFree(ShovelerInput *input) { glfwSetInputMode(input->game->window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); glfwSetInputMode(input->game->window, GLFW_STICKY_KEYS, GL_FALSE); glfwSetInputMode(input->game->window, GLFW_STICKY_MOUSE_BUTTONS, GL_FALSE); glfwSetKeyCallback(input->game->window, NULL); glfwSetMouseButtonCallback(input->game->window, NULL); glfwSetCursorPosCallback(input->game->window, NULL); glfwSetScrollCallback(input->game->window, NULL); glfwSetWindowSizeCallback(input->game->window, NULL); glfwSetWindowFocusCallback(input->game->window, NULL); g_hash_table_destroy(input->keyCallbacks); g_hash_table_destroy(input->mouseButtonCallbacks); g_hash_table_destroy(input->cursorPositionCallbacks); g_hash_table_destroy(input->scrollCallbacks); g_hash_table_destroy(input->windowSizeCallbacks); free(input); }
void hw2_terminate(void) { //Remove callbacks. glfwSetMouseButtonCallback(NULL); glfwSetMousePosCallback(NULL); glfwSetKeyCallback(NULL); //Restore OpenGL settings. glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); if(init_done) { //unload_shaders(phong); unload_shaders(simple_color); glUseProgram(0); } //Delete the VBO. glDeleteBuffers(1, &voxel_vbo); }
bool Game::init() { m_pPipe = new Pipeline(); m_pPipe->setCamera(m_windowWidth, m_windowHeight); m_pPipe->init(); m_pGameCamera = m_pPipe->getCamera(); m_pShadowMap = new ShadowMap(); if(!m_pShadowMap->initShadow(m_windowWidth, m_windowHeight)) return false; m_pLightingEffect = new LightingTechnique(); if(!m_pLightingEffect->init()) return false; m_pLightingEffect->enable(); m_pLightingEffect->setSpotLights(1, m_pSpotLight); m_pLightingEffect->setTextureUnit(0); m_pLightingEffect->setShadowMapTextureUnit(1); m_pShadowMapEffect = new ShadowMapTechnique(); if(!m_pShadowMapEffect->init()) return false; if(!initModels()) std::cout << "LOG: Models error" << std::endl; if(!initSkybox()) std::cout << "LOG: Skybox initialization error!" << std::endl; /* if(!initHeightmap()) std::cout << "LOG: Heightmap initialization error!" << std::endl; */ cam = m_pGameCamera; glfwSetMouseButtonCallback(m_pWindow, Game::mouseButtonWrapper); glfwSetCharCallback(m_pWindow, Game::keyboardCharactersWrapper); glfwSetCursorPosCallback(m_pWindow, Game::mousePosWrapper); glfwSetKeyCallback(m_pWindow, Game::keyboardWrapper); return true; }
void GLFWDisplay::run(PathTracer &pt) { ptr = &pt; sn = &ptr->getScene(); cam = sn->getCam(); if (!shared_buffer) { cout << "need to set buffer before running" << endl; return; } RTsize buffer_width_rts, buffer_height_rts; shared_buffer->getSize( buffer_width_rts, buffer_height_rts ); width = static_cast<int>(buffer_width_rts); height = static_cast<int>(buffer_height_rts); arcball = new Arcball(width, height); // complete window setup glfwSetWindowTitle(window, "path_tracer"); glfwSetWindowSize(window, width, height); glfwSetKeyCallback(window, keyFunc); glfwSetMouseButtonCallback(window, mouseFunc); glfwSetCursorPosCallback(window, posFunc); glfwSetScrollCallback(window, scrollFunc); GLrenderer renderer( shared_buffer->getGLBOId(), width, height ); glViewport(0, 0, width, height); glClear(GL_COLOR_BUFFER_BIT); pt.trace(); renderer.draw(); glFlush(); glfwSwapBuffers(window); glfwShowWindow(window); // start render loop while (!glfwWindowShouldClose(window)) { pt.trace(); renderer.draw(); glFlush(); glfwSwapBuffers(window); glfwPollEvents(); if (int error = glGetError()) cout << "error " << error << endl; } }
int openWindow(bool fullscreen) { unsigned long windowFlag = (fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW); // load GLFW if (glfwInit() != GL_TRUE) { fprintf(stderr, "ERROR: Could not initialize GLFW\n"); return EXIT_FAILURE; } // set core profile OpenGL 3.3+ //glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); // Set OpenGL version to 3.3+ //glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3); //glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Request core profile //glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Disable legacy // Initialize the window & create if (glfwOpenWindow(RESOLUTION_X, RESOLUTION_Y, 8, 8, 8, 8, // RGBA bits 16, 0, // depth, stencil bits windowFlag) != GL_TRUE) { fprintf(stderr, "ERROR: Could not open window\n"); glfwTerminate(); return EXIT_FAILURE; } glfwSetWindowTitle(APP_TITLE); // Set up callbacks glfwSetKeyCallback(glfwKeyboard); glfwSetMousePosCallback(glfwMouseMove); glfwSetMouseButtonCallback(glfwMouseInput); glfwSetMouseWheelCallback(glfwMouseWheel); glfwSetWindowSizeCallback(glfwResize); glfwSetWindowCloseCallback(glfwWindowClosed); return 0; }
bool NX::Application::Init(const char* vCmdLine[], const int iCmdCount, const int iWidth, const int iHeight){ g_pThis = this; NX::InitNXMath(); if (!glfwInit()) { fprintf(stderr, "Failed initialize GLFW."); exit(EXIT_FAILURE); return false; } { glfwSetErrorCallback(error_callback); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); } { GLFWwindow* window = glfwCreateWindow(iWidth, iHeight, "OpenGL", NULL, NULL); if(!window) { std::fprintf(stderr, "Failed to create GLFW window."); glfwTerminate(); exit(EXIT_FAILURE); return false; } g_window = window; glfwMakeContextCurrent(window); } {//call backs glfwSetKeyCallback(g_window, key_callback); glfwSetMouseButtonCallback(g_window, mousebutton_callback); glfwSetWindowPosCallback(g_window, windowposition_callback); glfwSetWindowSizeCallback(g_window, windowsize_callback); glfwSetCursorPosCallback(g_window, cursorposition_callback); } glb_GetLog().logToConsole("OpenGL version supported by this platform (%s)", glGetString(GL_VERSION)); glb_GetLog().log("OpenGL version supported by this platform (%s)", glGetString(GL_VENDOR)); glewExperimental = GL_TRUE; glewInit(); return true; }
// uiloop void ui_loop(int nimgs, view_img* imgs) { // view params view_params* view = init_view_params(nimgs, imgs); // window if (!glfwInit()) exit(EXIT_FAILURE); GLFWwindow* window = glfwCreateWindow(view->w, view->h, "imview", 0, 0); glfwMakeContextCurrent(window); glfwSetWindowUserPointer(window, view); // callbacks glfwSetCharCallback(window, text_callback); glfwSetWindowSizeCallback(window, window_size_callback); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetMouseButtonCallback(window, mouse_button_callback); glfwSetCursorPosCallback(window, mouse_pos_callback); glfwSetWindowRefreshCallback(window, window_refresh_callback); // init gl extensions #ifdef YG_USING_GLEW if (glewInit() != GLEW_OK) exit(EXIT_FAILURE); #endif // load textures for (int i = 0; i < nimgs; i++) { imgs[i].tex_glid = yg_make_texture(imgs[i].pixels, imgs[i].w, imgs[i].h, imgs[i].nc, true, false); } // ui loop while (!glfwWindowShouldClose(window)) { window_refresh_callback(window); glfwWaitEvents(); } glfwDestroyWindow(window); glfwTerminate(); free(view); }
Window::Window(glm::ivec2 const& windowsize) : m_window(nullptr), m_size(windowsize), m_title("Fensterchen"), m_mousePosition(), m_mouseButtonFlags(0), m_keypressed() { std::fill(std::begin(m_keypressed), std::end(m_keypressed), 0); glfwInit(); glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); glfwWindowHint(GLFW_RESIZABLE, 0); m_window = glfwCreateWindow(windowsize.x, windowsize.y, m_title.c_str(), nullptr, nullptr); if (m_window != nullptr) { glfwSetWindowUserPointer(m_window, this); assert(m_window != nullptr); glfwSetMouseButtonCallback(m_window, Window::mouseButtonCallback); glfwSetCursorPosCallback(m_window, Window::cursorPositionCallback); glfwSetKeyCallback(m_window, Window::keyCallback); glfwMakeContextCurrent(m_window); // glewExperimental = GL_TRUE; glewInit(); // glGetError(); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_NOTEQUAL, 0); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_POINT_SMOOTH); glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); glPointSize(5.0f); glEnable(GL_POINT_SMOOTH); glLineWidth(2.0f); glEnable(GL_LINE_SMOOTH); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); } }
void Game::Start() { if (!glfwInit()) std::cout << "Failed to initialize glfw."; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); window = glfwCreateWindow(screenWidthC, screenHeightC, "Rubiks Cube", nullptr, nullptr); glfwMakeContextCurrent(window); glfwSetKeyCallback(window, (GLFWkeyfun) InputHandler::KeyCallBack); glfwSetMouseButtonCallback(window, (GLFWmousebuttonfun) InputHandler::MouseButtonCallBack); InputHandler::SetGame(this); renderer = std::make_shared<Renderer>(cube, camera); while (Tick_()); Stop(); }
void Root::setFullscreen(bool fullscr) { if( fullscreen == fullscr ) return; //no difference fullscreen = fullscr; glfwCloseWindow(); if(!glfwOpenWindow(windowWidth, windowHeight, 0, 0, 0, 0, 32, 0, (fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW))) { LOG_ERROR("Could not re-create window. Closing now."); stopRendering(); return; } glfwSetWindowTitle("Arya"); glfwEnable(GLFW_MOUSE_CURSOR); glfwSetKeyCallback(keyCallback); glfwSetMouseButtonCallback(mouseButtonCallback); glfwSetMousePosCallback(mousePosCallback); glfwSetMouseWheelCallback(mouseWheelCallback); }
int main(int arg, char* argv[]) { glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); // windowとそのcontextの作成 GLFWwindow* window = glfwCreateWindow(320, 240, "Title", NULL, NULL); glfwSetWindowPos(window, 100, 100); glfwSetWindowSize(window, 320, 240); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } glfwMakeContextCurrent(window); glfwSwapInterval(1); glfwSetKeyCallback(window, key_callback); glfwSetMouseButtonCallback(window, mouse); init(); glfwSetWindowSizeCallback(window, resize); int width, height; glfwGetWindowSize(window, &width, &height); resize(window, width, height); while(!glfwWindowShouldClose(window)) { draw(); glfwSwapBuffers(window); glfwPollEvents(); } glfwDestroyWindow(window); glfwTerminate(); return 0; }
bool Window::init() { if(!glfwInit()) { std::cout<<"Failed to initialized glfw"<<std::endl; return false; } else { std::cout<<"openGL initialized succesfully"<<std::endl; } glfwWindowHint(GLFW_SAMPLES, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); window = glfwCreateWindow(width, height, title, NULL, NULL); if(!window) { glfwTerminate(); std::cout<<"Failed to create GLFW window"<<std::endl; return false; } glfwMakeContextCurrent(window); glfwSetWindowUserPointer(window, this); glfwSetWindowSizeCallback(window, window_resize_callback); glfwSetKeyCallback(window, key_callback); glfwSetMouseButtonCallback(window, mouse_button_callback); glfwSetCursorPosCallback(window, cursor_position_callback); glfwSetScrollCallback(window, scroll_callback); glfwSetCursorPos(window, mouse.x, mouse.y); glewExperimental = GL_TRUE; if(glewInit() != GLEW_OK) { std::cout<<"i cri evri tiem"<<std::endl; std::cout<<"gleu not ok"<<std::endl; return false; } std::cout<<"OpenGL "<<glGetString(GL_VERSION)<<std::endl; return true; }
bool init(int argc, char* argv[]) { glfwSetErrorCallback(errorCallback); if (!glfwInit()) { return false; } width = 800; height = 800; window = glfwCreateWindow(width, height, "CIS 565 Rasterizer", NULL, NULL); if (!window){ glfwTerminate(); return false; } glfwMakeContextCurrent(window); glfwSetKeyCallback(window, keyCallback); glfwSetMouseButtonCallback(window,MouseClickCallback); glfwSetCursorEnterCallback(window,CursorEnterCallback); glfwSetCursorPosCallback(window,CursorCallback); // Set up GL context glewExperimental = GL_TRUE; if(glewInit()!=GLEW_OK){ return false; } // Initialize other stuff initVAO(); initTextures(); initCuda(); initPBO(); GLuint passthroughProgram; passthroughProgram = initShader(); glUseProgram(passthroughProgram); glActiveTexture(GL_TEXTURE0); return true; }
CanvasGLFW::CanvasGLFW(std::string windowTitle, uvec2 dimensions) : CanvasGL(dimensions) , windowTitle_(windowTitle) , glWindow_(nullptr) , mouseButton_(MouseEvent::MOUSE_BUTTON_NONE) , mouseState_(MouseEvent::MOUSE_STATE_NONE) , mouseModifiers_(InteractionEvent::MODIFIER_NONE) { glfwWindowHint(GLFW_FLOATING, alwaysOnTop_ ? GL_TRUE : GL_FALSE); glfwWindowHint(GLFW_VISIBLE, GL_FALSE); #ifdef __APPLE__ if (!sharedContext_ && OpenGLCapabilities::getPreferredProfile() == "core") { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); } #endif glWindow_ = glfwCreateWindow(getScreenDimensions().x, getScreenDimensions().y, windowTitle_.c_str(), nullptr, sharedContext_); if (!glWindow_) { glfwTerminate(); throw Exception("Could not create GLFW window.", IvwContext); } if (!sharedContext_) sharedContext_ = glWindow_; // register callbacks glfwSetKeyCallback(glWindow_, keyboard); glfwSetMouseButtonCallback(glWindow_, mouseButton); glfwSetCursorPosCallback(glWindow_, mouseMotion); glfwSetScrollCallback(glWindow_, scroll); glfwSetWindowCloseCallback(glWindow_, closeWindow); glfwSetWindowUserPointer(glWindow_, this); glfwSetWindowSizeCallback(glWindow_, reshape); glfwSetWindowPosCallback(glWindow_, move); }
void Application::init(const unsigned int& width, const unsigned int& height) { m_width = width; m_height = height; glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); m_window = glfwCreateWindow(width, height, "Simple GL App", NULL, NULL); if (!m_window) { glfwTerminate(); exit(EXIT_FAILURE); } glfwMakeContextCurrent(m_window); glfwSetKeyCallback(m_window, key_callback); glfwSetWindowSizeCallback(m_window, WindowSizeCB); glfwSetCursorPosCallback(m_window, EventMousePos); glfwSetScrollCallback(m_window, EventMouseWheel); glfwSetMouseButtonCallback(m_window, (GLFWmousebuttonfun)EventMouseButton); glfwSetKeyCallback(m_window, (GLFWkeyfun)EventKey); // - Directly redirect GLFW char events to AntTweakBar glfwSetCharCallback(m_window, (GLFWcharfun)EventChar); if (glewInit() != GLEW_OK){ std::cout << "cannot intialize the glew.\n"; exit(EXIT_FAILURE); } init(); GLenum e = glGetError(); //glEnable(GL_DEPTH); e = glGetError(); glEnable(GL_DEPTH_TEST); e = glGetError(); }
Input::Input() { auto KeyPressCallback = [](GLFWwindow *pWindow, int key, int scancode, int action, int mods) { if( action == GLFW_PRESS ) Input::GetSingleton()->OnKeyPressed( key ); if( action == GLFW_RELEASE ) Input::GetSingleton()->OnKeyReleased( key ); if( action == GLFW_REPEAT ) Input::GetSingleton()->OnKeyRepeate(key); }; auto CharacterInputCallback = [](GLFWwindow *pWindow, unsigned int character) { Input::GetSingleton()->OnCharInput(character); }; auto MouseInputCallback = [](GLFWwindow *pWindow, int button, int action, int mods) { if( action == GLFW_PRESS) Input::GetSingleton()->OnMousePressed( button ); if( action == GLFW_RELEASE) Input::GetSingleton()->OnMouseReleased( button ); }; auto MouseMoveCallback = [](GLFWwindow *pWindow, double mx, double my) { Input::GetSingleton()->OnMouseMove( mx, my ); }; GLFWwindow *pWindow = glfwGetCurrentContext(); glfwSetKeyCallback(pWindow, KeyPressCallback); glfwSetCharCallback(pWindow, CharacterInputCallback); glfwSetMouseButtonCallback(pWindow, MouseInputCallback); glfwSetCursorPosCallback(pWindow, MouseMoveCallback ); m_mouseX = 0; m_mouseY = 0; }
bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks) { g_Window = window; 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_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_ImplGlfwGL3_RenderDrawLists; io.SetClipboardTextFn = ImGui_ImplGlfwGL3_SetClipboardText; io.GetClipboardTextFn = ImGui_ImplGlfwGL3_GetClipboardText; #ifdef _MSC_VER io.ImeWindowHandle = glfwGetWin32Window(g_Window); #endif if (install_callbacks) { glfwSetMouseButtonCallback(window, ImGui_ImplGlfwGL3_MouseButtonCallback); glfwSetScrollCallback(window, ImGui_ImplGlfwGL3_ScrollCallback); glfwSetKeyCallback(window, ImGui_ImplGlfwGL3_KeyCallback); glfwSetCharCallback(window, ImGui_ImplGlfwGL3_CharCallback); } return true; }
int main(){ try{ Controller* PolyFun = Controller::getInstance(); // register events glfwSetMouseButtonCallback(MouseButtonCallback); glfwSetKeyCallback(KeyCallback); glfwSetMousePosCallback(MousePosCallback); } catch (const eFileNotFoundException &e){ std::cerr << "ERROR: Database not found!" << std::endl; std::cin.ignore(); } // endless loop until window is closed while(true) { glfwWaitEvents(); // do nothing until user presses mouse button if(!glfwGetWindowParam(GLFW_OPENED)) { break; } } Controller::resetInstance(); //delete pointers and quit return 0; }
void setup() { // Initialize AntTweakBar TwInit(TW_OPENGL_CORE, NULL); bgColor = color(100, 100, 100); rectColor = colorA(255, 0, 0, 200); // Create a tweak bar bar = TwNewBar("TweakBar"); WindowSizeCB(window, width, height); glfwSetWindowSizeCallback(window, WindowSizeCB); glfwSetMouseButtonCallback(window, TwEventMouseButtonGLFW); glfwSetCursorPosCallback(window, TwEvenCursorPosGLFW); glfwSetScrollCallback(window, TwEventScrollGLFW); glfwSetKeyCallback(window, TwEventKeyGLFW); glfwSetCharCallback(window, TwEventCharGLFW); TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLFW and OpenGL.' "); // Message added to the help bar. // Add 'speed' to 'bar': it is a modifable (RW) variable of type TW_TYPE_DOUBLE. Its key shortcuts are [s] and [S]. TwAddVarRW(bar, "speed", TW_TYPE_DOUBLE, &speed, " label='Rot speed' min=0 max=2 step=0.01 keyIncr=s keyDecr=S help='Rotation speed (turns/second)' "); // Add 'wire' to 'bar': it is a modifable variable of type TW_TYPE_BOOL32 (32 bits boolean). Its key shortcut is [w]. TwAddVarRW(bar, "wire", TW_TYPE_BOOL32, &wire, " label='Wireframe mode' key=w help='Toggle wireframe display mode.' "); // Add 'time' to 'bar': it is a read-only (RO) variable of type TW_TYPE_DOUBLE, with 1 precision digit TwAddVarRO(bar, "time", TW_TYPE_DOUBLE, &time, " label='Time' precision=1 help='Time (in seconds).' "); // Add 'bgColor' to 'bar': it is a modifable variable of type TW_TYPE_COLOR3F (3 floats color) TwAddVarRW(bar, "bgColor", TW_TYPE_COLOR3F, bgColor.rgba, " label='Background color' "); // Add 'rectColor' to 'bar': it is a modifable variable of type TW_TYPE_COLOR32 (32 bits color) with alpha TwAddVarRW(bar, "rectColor", TW_TYPE_COLOR4F, rectColor.rgba, " label='Rect color' alpha help='Color and transparency of the rect.' "); }
bool setupWindow( int width, int height, bool fullscreen ) { // Create OpenGL window if( !glfwOpenWindow( width, height, 8, 8, 8, 8, 24, 8, fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW ) ) { glfwTerminate(); return false; } if( !fullscreen ) glfwSetWindowTitle( caption.c_str() ); // Disable vertical synchronization glfwSwapInterval( 0 ); // Set listeners glfwSetWindowCloseCallback( windowCloseListener ); glfwSetKeyCallback( keyPressListener ); glfwSetMousePosCallback( mouseMoveListener ); glfwSetMouseButtonCallback( mouseButtonListener ); return true; }
bool GLFWWindow::open(const std::string& title, uint width, uint height) { if(opened) return true; this->title = title; this->width = width; this->height = height; if(glfwInit() == GL_FALSE) { logError("cannot initialize GLFW"); return false; } glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3); glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); if(!glfwOpenWindow(width, height, 8, 8, 8, 8, 24, 8, GLFW_WINDOW)) { logError("cannot open the GLFW window"); return false; } if(!glxwInit()) return false; glfwSetWindowTitle(title.c_str()); glfwSetMouseButtonCallback(&mouseButtonCallback); glfwSetMousePosCallback(&mousePosCallback); glfwSetMouseWheelCallback(&mouseWheelCallback); glfwSetKeyCallback(&keyCallback); this->opened = true; return true; }
Window::Window(const char* title, int width, int height) : width(width), height(height) { if (!glfwInit()) { printf("glfw init failed!\n"); throw std::exception(); } glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_SAMPLES, 4); window = glfwCreateWindow(width, height, title, nullptr, nullptr); if (!window) { glfwTerminate(); printf("glfw failed to create a window!\n"); throw std::exception(); } glfwMakeContextCurrent(window); glfwSetWindowSizeCallback(window, onWindowResize); glfwSetScrollCallback(window, onWindowMouseWheel); glfwSetMouseButtonCallback(window, onWindowMouseButton); glfwSetCursorPosCallback(window, onWindowMouseMove); glfwSetKeyCallback(window, onWindowKeyboard); glfwSetWindowFocusCallback(window, onWindowFocus); if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { printf("glad faild to init!\n"); throw std::exception(); } instance = this; }
void Init() { const int window_width = 800, window_height = 600; if (glfwInit() != GL_TRUE) Shut_Down(1); glfwEnable(GLFW_KEY_REPEAT); // test for issue #3059 int red_bits = glfwGetWindowParam(GLFW_RED_BITS); glfwOpenWindowHint(GLFW_RED_BITS, 8); assert(glfwGetWindowParam(GLFW_RED_BITS) == 8); glfwOpenWindowHint(GLFW_RED_BITS, red_bits); // 800 x 600, 16 bit color, no depth, alpha or stencil buffers, windowed if (glfwOpenWindow(window_width, window_height, 5, 6, 5, 0, 0, 0, GLFW_WINDOW) != GL_TRUE) Shut_Down(1); glfwSetWindowTitle("The GLFW Window"); glfwSetKeyCallback( OnKeyPressed ); glfwSetCharCallback( OnCharPressed ); glfwSetWindowCloseCallback(OnClose); glfwSetWindowSizeCallback(OnResize); glfwSetWindowRefreshCallback(OnRefresh); glfwSetMouseWheelCallback(OnMouseWheel); glfwSetMousePosCallback(OnMouseMove); glfwSetMouseButtonCallback(OnMouseClick); // set the projection matrix to a normal frustum with a max depth of 50 glMatrixMode(GL_PROJECTION); glLoadIdentity(); float aspect_ratio = ((float)window_height) / window_width; glFrustum(.5, -.5, -.5 * aspect_ratio, .5 * aspect_ratio, 1, 50); glMatrixMode(GL_MODELVIEW); PullInfo(); }