static inline jlong wrapped_Java_com_badlogic_jglfw_Glfw_glfwCreateWindowJni (JNIEnv* env, jclass clazz, jint width, jint height, jstring obj_title, jlong monitor, jlong share, char* title) { //@line:704 GLFWwindow* window = glfwCreateWindow(width, height, title, (GLFWmonitor*)monitor, (GLFWwindow*)share); if (window) { glfwSetWindowPosCallback(window, windowPos); glfwSetWindowSizeCallback(window, windowSize); glfwSetWindowCloseCallback(window, windowClose); glfwSetWindowRefreshCallback(window, windowRefresh); glfwSetWindowFocusCallback(window, windowFocus); glfwSetWindowIconifyCallback(window, windowIconify); glfwSetKeyCallback(window, key); glfwSetCharCallback(window, character); glfwSetMouseButtonCallback(window, mouseButton); glfwSetCursorPosCallback(window, cursorPos); glfwSetCursorEnterCallback(window, cursorEnter); glfwSetScrollCallback(window, scroll); glfwSetDropCallback(window, drop); } return (jlong)window; }
void WindowEventDispatcher::deregisterWindow(Window* window) { assert(window != nullptr); GLFWwindow* glfwWindow = window->internalWindow(); if (!glfwWindow) return; glfwSetWindowRefreshCallback(glfwWindow, nullptr); glfwSetKeyCallback(glfwWindow, nullptr); glfwSetCharCallback(glfwWindow, nullptr); glfwSetMouseButtonCallback(glfwWindow, nullptr); glfwSetCursorPosCallback(glfwWindow, nullptr); glfwSetCursorEnterCallback(glfwWindow, nullptr); glfwSetScrollCallback(glfwWindow, nullptr); glfwSetWindowSizeCallback(glfwWindow, nullptr); glfwSetFramebufferSizeCallback(glfwWindow, nullptr); glfwSetWindowFocusCallback(glfwWindow, nullptr); glfwSetWindowPosCallback(glfwWindow, nullptr); glfwSetWindowIconifyCallback(glfwWindow, nullptr); glfwSetWindowCloseCallback(glfwWindow, nullptr); removeTimers(window); }
void WindowEventDispatcher::registerWindow(Window* window) { assert(window != nullptr); GLFWwindow * glfwWindow = window->internalWindow(); if (!glfwWindow) return; glfwSetWindowUserPointer(glfwWindow, window); glfwSetWindowRefreshCallback(glfwWindow, handleRefresh); glfwSetKeyCallback(glfwWindow, handleKey); glfwSetCharCallback(glfwWindow, handleChar); glfwSetMouseButtonCallback(glfwWindow, handleMouse); glfwSetCursorPosCallback(glfwWindow, handleCursorPos); glfwSetCursorEnterCallback(glfwWindow, handleCursorEnter); glfwSetScrollCallback(glfwWindow, handleScroll); glfwSetWindowSizeCallback(glfwWindow, handleResize); glfwSetFramebufferSizeCallback(glfwWindow, handleFramebufferResize); glfwSetWindowFocusCallback(glfwWindow, handleFocus); glfwSetWindowPosCallback(glfwWindow, handleMove); glfwSetWindowIconifyCallback(glfwWindow, handleIconify); glfwSetWindowCloseCallback(glfwWindow, handleClose); }
bool WindowGL33::removeCursorEnterCallback(CursorEnterEventType::DelegatePtr const& callback) { bool ret = m_cursorEnterCallbacks.removeListener(callback); if (!m_cursorEnterCallbacks.hasListener()) glfwSetCursorEnterCallback(m_pWndHandle, NULL); return ret; }
Window::~Window() { if(window) { // remove glfw event callbacks { std::lock_guard<std::mutex> windowsLock(windowStaticLock); windows.erase(window); } glfwSetKeyCallback(window, nullptr); glfwSetCharCallback(window, nullptr); glfwSetCursorEnterCallback(window, nullptr); glfwSetCursorPosCallback(window, nullptr); glfwSetMouseButtonCallback(window, nullptr); glfwSetScrollCallback(window, nullptr); glfwSetWindowPosCallback(window, nullptr); glfwSetWindowSizeCallback(window, nullptr); glfwSetWindowCloseCallback(window, nullptr); glfwDestroyWindow(window); } { std::lock_guard<std::mutex> windowsLock(windowStaticLock); --numOfWindows; } if(glfwInitialized && !numOfWindows) glfwTerminate(); }
void InputSystem::HandleMessage(Message* msg) { switch(msg->GetType()) { #if USE_GRAPHICS case Message::MSG_WINDOW: { LOG("InputSystem handling new window message"); s32 width = *msg->GetFormatedData<s32>(); s32 height = *msg->GetFormatedData<s32>(); m_window = *msg->GetFormatedData<GraphicsWindow*>(); glfwGetCursorPos(m_window, &m_mouseX, &m_mouseY); m_mousePX = m_mouseX; m_mousePY = m_mouseY; glfwSetKeyCallback(m_window, &KeyCallback); glfwSetCharCallback(m_window, &CharCallback); glfwSetMouseButtonCallback(m_window, &MouseButtonCallback); glfwSetCursorPosCallback(m_window, &CursorPosCallback); glfwSetCursorEnterCallback(m_window, &CursorEnterCallback); glfwSetScrollCallback(m_window, &ScrollCallback); glfwSetWindowSizeCallback(m_window, &ResizeCallback); break; } #endif default: break; } }
Window::Window(const std::string& title, const glm::vec2& size) : mBackgroundColor(0.f, 0.f, 0.f, 1.f), mCursorMode(Normal) { if(!glfwInit()) { std::cout << "GLFW Error on initialization" << std::endl; } GL_CHECK(); mWindow = glfwCreateWindow(size.x, size.y, title.c_str(), NULL, NULL); glfwMakeContextCurrent(mWindow); if (glewInit() != GLEW_OK) { std::cout << "GLEW Error on initialization" << std::endl; } makeCurrentContext(); glfwSetKeyCallback(mWindow, window_glfw_key); glfwSetCharCallback(mWindow, window_glfw_character); glfwSetMouseButtonCallback(mWindow, window_glfw_mouse_button); glfwSetCursorPosCallback(mWindow, window_glfw_mouse_move); glfwSetCursorEnterCallback(mWindow, window_glfw_mouse_enter); glfwSetScrollCallback(mWindow, window_glfw_scroll); glfwSetWindowSizeCallback(mWindow, window_glfw_window_resize); instances.push_back(this); }
int main(void) { GLFWwindow* window; int width, height; setlocale(LC_ALL, ""); glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); printf("Library initialized\n"); window = glfwCreateWindow(640, 480, "Event Linter", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } printf("Window opened\n"); glfwSetMonitorCallback(monitor_callback); glfwSetWindowPosCallback(window, window_pos_callback); glfwSetWindowSizeCallback(window, window_size_callback); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetWindowCloseCallback(window, window_close_callback); glfwSetWindowRefreshCallback(window, window_refresh_callback); glfwSetWindowFocusCallback(window, window_focus_callback); glfwSetWindowIconifyCallback(window, window_iconify_callback); glfwSetMouseButtonCallback(window, mouse_button_callback); glfwSetCursorPosCallback(window, cursor_position_callback); glfwSetCursorEnterCallback(window, cursor_enter_callback); glfwSetScrollCallback(window, scroll_callback); glfwSetKeyCallback(window, key_callback); glfwSetCharCallback(window, char_callback); glfwMakeContextCurrent(window); glfwSwapInterval(1); glfwGetWindowSize(window, &width, &height); printf("Window size should be %ix%i\n", width, height); printf("Main loop starting\n"); while (!glfwWindowShouldClose(window)) { glfwWaitEvents(); // Workaround for an issue with msvcrt and mintty fflush(stdout); } glfwTerminate(); exit(EXIT_SUCCESS); }
void GLWindow::run() { // Open a window and create a context _window = glfwCreateWindow(_width, _height, _windowTitle, NULL, NULL); if(_window == NULL) { glfwTerminate(); throw std::exception("Failed to open GLFW window"); } glfwMakeContextCurrent(_window); // Initialize glew glewExperimental = true; if(glewInit() != GLEW_OK) { throw std::exception("Failed to initialize GLEW"); } glfwSetInputMode(_window, GLFW_STICKY_KEYS, GL_TRUE); // Set callbacks glfwSetWindowUserPointer(_window, this); glfwSetErrorCallback(errorCallback); glfwSetWindowSizeCallback(_window, resizeCallback); glfwSetFramebufferSizeCallback(_window, framebufferCallback); glfwSetKeyCallback(_window, keyCallback); glfwSetMouseButtonCallback(_window, mouseButtonCallback); glfwSetCursorPosCallback(_window, mouseMoveCallback); glfwSetCursorEnterCallback(_window, cursorEnterCallback); glfwSetCharCallback(_window, characterCallback); glfwSetScrollCallback(_window, scrollCallback); init(); double lastTime = glfwGetTime(); while(glfwGetKey(_window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(_window) == 0) { glfwPollEvents(); // Calculate ms/frame double currentTime = glfwGetTime(); ++_frame; if(currentTime - lastTime >= 2.0f) { printf("%0.2f ms/frame (fps: %0.2f)\n", 1000.0 / double(_frame), double(_frame) / (currentTime - lastTime)); _frame = 0; lastTime += 2.0f; } // Render scene glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); update(); render(); // Swap buffers glfwSwapBuffers(_window); } }
int main(void) { GLFWwindow window; int width, height; setlocale(LC_ALL, ""); if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); } printf("Library initialized\n"); glfwSetWindowSizeCallback(window_size_callback); glfwSetWindowCloseCallback(window_close_callback); glfwSetWindowRefreshCallback(window_refresh_callback); glfwSetWindowFocusCallback(window_focus_callback); glfwSetWindowIconifyCallback(window_iconify_callback); glfwSetMouseButtonCallback(mouse_button_callback); glfwSetCursorPosCallback(cursor_position_callback); glfwSetCursorEnterCallback(cursor_enter_callback); glfwSetScrollCallback(scroll_callback); glfwSetKeyCallback(key_callback); glfwSetCharCallback(char_callback); window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Event Linter", NULL); if (!window) { glfwTerminate(); fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); } printf("Window opened\n"); glfwMakeContextCurrent(window); glfwSwapInterval(1); glfwGetWindowSize(window, &width, &height); printf("Window size should be %ix%i\n", width, height); printf("Key repeat should be %s\n", keyrepeat ? "enabled" : "disabled"); printf("System keys should be %s\n", systemkeys ? "enabled" : "disabled"); printf("Main loop starting\n"); while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED)) glfwWaitEvents(); glfwTerminate(); exit(EXIT_SUCCESS); }
void MGLInput::AttatchInputToWindow(MGLWindow* windo) { window = windo; glfwSetWindowUserPointer(window->GetGLFWWindow(), this); glfwSetKeyCallback(window->GetGLFWWindow(), reinterpret_cast<GLFWkeyfun>(this->KeyInputCallBack)); glfwSetCursorEnterCallback(window->GetGLFWWindow(), reinterpret_cast<GLFWcursorenterfun>(this->MouseFocusCallBack)); glfwSetMouseButtonCallback(window->GetGLFWWindow(), reinterpret_cast<GLFWmousebuttonfun>(this->MouseButtonCallBack)); glfwSetCursorPosCallback(window->GetGLFWWindow(), reinterpret_cast<GLFWcursorposfun>(this->MousePositionCallBack)); glfwSetScrollCallback(window->GetGLFWWindow(), reinterpret_cast<GLFWscrollfun>(this->MouseScrollCallBack)); }
void Window::initialize() { // set ALL the callbacks glfwSetWindowPosCallback(m_handle, callbackWindowPos); glfwSetWindowSizeCallback(m_handle, callbackWindowSize); glfwSetWindowCloseCallback(m_handle, callbackWindowClose); glfwSetWindowRefreshCallback(m_handle, callbackWindowRefresh); glfwSetWindowFocusCallback(m_handle, callbackWindowFocus); glfwSetWindowIconifyCallback(m_handle, callbackWindowIconify); glfwSetFramebufferSizeCallback(m_handle, callbackFramebufferSize); glfwSetMouseButtonCallback(m_handle, callbackMouseButton); glfwSetCursorPosCallback(m_handle, callbackCursorPos); glfwSetCursorEnterCallback(m_handle, callbackCursorEnter); glfwSetScrollCallback(m_handle, callbackScroll); glfwSetKeyCallback(m_handle, callbackKey); glfwSetCharCallback(m_handle, callbackChar); // create a windowdata object glfwSetWindowUserPointer(m_handle, new WindowData(this)); }
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; }
void Window::create(const Vector<uint, 2>& res, const std::string& t, const Monitor& mon, bool fs) { title = t; isFullscreen = fs; window = glfwCreateWindow(res[0], res[1], title.c_str(), fs ? mon.monitor : nullptr, nullptr); if(!window) throw std::runtime_error("Could not create the window."); glfwMakeContextCurrent(window); if(!numOfWindows) { // setup GLEW if this is the first Window glewExperimental = GL_TRUE; GLenum err = glewInit(); if(err != GLEW_OK) throw std::runtime_error("glewInit failed!"); } { std::lock_guard<std::mutex> windowsLock(windowStaticLock); ++numOfWindows; windows.emplace(window, this); } glfwSetKeyCallback(window, &keyboardCallback); glfwSetCharCallback(window, &unicodeCallback); glfwSetCursorEnterCallback(window, &mouseEnteredCallback); glfwSetCursorPosCallback(window, &mouseMovedCallback); glfwSetMouseButtonCallback(window, &mouseButtonCallback); glfwSetScrollCallback(window, &scrollCallback); glfwSetWindowPosCallback(window, &positionCallback); glfwSetWindowSizeCallback(window, &sizeCallback); glfwSetWindowCloseCallback(window, &closeCallback); }
Window::Window(int width, int height, std::string title, bool fullScreen) : _inputManagerUPtr(std::unique_ptr<InputManager>(new InputManager())) { glfwSetErrorCallback(OnError); glfwInit(); 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); if (!fullScreen) _glfwWindowPtr = glfwCreateWindow(width, height, title.c_str(), NULL, NULL); else _glfwWindowPtr = glfwCreateWindow(width, height, title.c_str(), glfwGetPrimaryMonitor(), NULL); glfwMakeContextCurrent(_glfwWindowPtr); glewExperimental = GL_TRUE; glewInit(); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glfwSetWindowUserPointer(_glfwWindowPtr, this); glfwSetWindowCloseCallback(_glfwWindowPtr, _inputManagerUPtr->OnWindowClosed); glfwSetWindowFocusCallback(_glfwWindowPtr, _inputManagerUPtr->OnWindowFocused); glfwSetWindowSizeCallback(_glfwWindowPtr, _inputManagerUPtr->OnWindowResized); glfwSetWindowIconifyCallback(_glfwWindowPtr, _inputManagerUPtr->OnWindowIconify); glfwSetWindowPosCallback(_glfwWindowPtr, _inputManagerUPtr->OnWindowPositionChanged); glfwSetFramebufferSizeCallback(_glfwWindowPtr, _inputManagerUPtr->OnWindowFramebufferResized); glfwSetWindowRefreshCallback(_glfwWindowPtr, _inputManagerUPtr->OnWindowRefreshed); glfwSetKeyCallback(_glfwWindowPtr, _inputManagerUPtr->OnKeyPressed); glfwSetMouseButtonCallback(_glfwWindowPtr, _inputManagerUPtr->OnMouseButton); glfwSetScrollCallback(_glfwWindowPtr, _inputManagerUPtr->OnScroll); glfwSetCursorEnterCallback(_glfwWindowPtr, _inputManagerUPtr->OnCursorEnter); glfwSetCursorPosCallback(_glfwWindowPtr, _inputManagerUPtr->OnCursorPositionChanged); _inputManagerUPtr->OnWindowResized(_glfwWindowPtr, width, height); }
int main(int argc, char** argv) { Slot* slots; GLFWmonitor* monitor = NULL; int ch, i, width, height, count = 1; setlocale(LC_ALL, ""); glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); printf("Library initialized\n"); glfwSetMonitorCallback(monitor_callback); while ((ch = getopt(argc, argv, "hfn:")) != -1) { switch (ch) { case 'h': usage(); exit(EXIT_SUCCESS); case 'f': monitor = glfwGetPrimaryMonitor(); break; case 'n': count = (int) strtol(optarg, NULL, 10); break; default: usage(); exit(EXIT_FAILURE); } } if (monitor) { const GLFWvidmode* mode = glfwGetVideoMode(monitor); glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); glfwWindowHint(GLFW_RED_BITS, mode->redBits); glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); width = mode->width; height = mode->height; } else { width = 640; height = 480; } if (!count) { fprintf(stderr, "Invalid user\n"); exit(EXIT_FAILURE); } slots = calloc(count, sizeof(Slot)); for (i = 0; i < count; i++) { char title[128]; slots[i].closeable = GL_TRUE; slots[i].number = i + 1; sprintf(title, "Event Linter (Window %i)", slots[i].number); if (monitor) { printf("Creating full screen window %i (%ix%i on %s)\n", slots[i].number, width, height, glfwGetMonitorName(monitor)); } else { printf("Creating windowed mode window %i (%ix%i)\n", slots[i].number, width, height); } slots[i].window = glfwCreateWindow(width, height, title, monitor, NULL); if (!slots[i].window) { free(slots); glfwTerminate(); exit(EXIT_FAILURE); } glfwSetWindowUserPointer(slots[i].window, slots + i); glfwSetWindowPosCallback(slots[i].window, window_pos_callback); glfwSetWindowSizeCallback(slots[i].window, window_size_callback); glfwSetFramebufferSizeCallback(slots[i].window, framebuffer_size_callback); glfwSetWindowCloseCallback(slots[i].window, window_close_callback); glfwSetWindowRefreshCallback(slots[i].window, window_refresh_callback); glfwSetWindowFocusCallback(slots[i].window, window_focus_callback); glfwSetWindowIconifyCallback(slots[i].window, window_iconify_callback); glfwSetMouseButtonCallback(slots[i].window, mouse_button_callback); glfwSetCursorPosCallback(slots[i].window, cursor_position_callback); glfwSetCursorEnterCallback(slots[i].window, cursor_enter_callback); glfwSetScrollCallback(slots[i].window, scroll_callback); glfwSetKeyCallback(slots[i].window, key_callback); glfwSetCharCallback(slots[i].window, char_callback); glfwSetCharModsCallback(slots[i].window, char_mods_callback); glfwSetDropCallback(slots[i].window, drop_callback); glfwMakeContextCurrent(slots[i].window); glfwSwapInterval(1); } printf("Main loop starting\n"); for (;;) { for (i = 0; i < count; i++) { if (glfwWindowShouldClose(slots[i].window)) break; } if (i < count) break; glfwWaitEvents(); // Workaround for an issue with msvcrt and mintty fflush(stdout); } free(slots); glfwTerminate(); exit(EXIT_SUCCESS); }
int main( void ) { GLFWwindow *window; // Initialize the library if ( !glfwInit( ) ) { return -1; } // Create a windowed mode window and its OpenGL context window = glfwCreateWindow( SCREEN_WIDTH, SCREEN_HEIGHT, "Hello World", NULL, NULL ); glfwSetCursorPosCallback( window, cursorPositionCallback ); glfwSetInputMode( window, GLFW_CURSOR, GLFW_CURSOR_NORMAL ); glfwSetCursorEnterCallback( window, cursorEnterCallback ); glfwSetMouseButtonCallback( window, mouseButtonCallback ); glfwSetInputMode( window, GLFW_STICKY_MOUSE_BUTTONS, 1 ); glfwSetScrollCallback( window, scrollCallback ); unsigned char pixels[16 * 16 * 4]; memset( pixels, 0xff, sizeof( pixels ) ); GLFWimage image; image.width = 16; image.height = 16; image.pixels = pixels; GLFWcursor *cursor = glfwCreateCursor( &image, 0, 0 ); glfwSetCursor( window, cursor ); // set to null to reset cursor int screenWidth, screenHeight; glfwGetFramebufferSize( window, &screenWidth, &screenHeight ); if ( !window ) { glfwTerminate( ); return -1; } // Make the window's context current glfwMakeContextCurrent( window ); glViewport( 0.0f, 0.0f, screenWidth, screenHeight ); // specifies the part of the window to which OpenGL will draw (in pixels), convert from normalised to pixels glMatrixMode( GL_PROJECTION ); // projection matrix defines the properties of the camera that views the objects in the world coordinate frame. Here you typically set the zoom factor, aspect ratio and the near and far clipping planes glLoadIdentity( ); // replace the current matrix with the identity matrix and starts us a fresh because matrix transforms such as glOrpho and glRotate cumulate, basically puts us at (0, 0, 0) glOrtho( 0, SCREEN_WIDTH, 0, SCREEN_HEIGHT, 0, 1 ); // essentially set coordinate system glMatrixMode( GL_MODELVIEW ); // (default matrix mode) modelview matrix defines how your objects are transformed (meaning translation, rotation and scaling) in your world glLoadIdentity( ); // same as above comment // Loop until the user closes the window while ( !glfwWindowShouldClose( window ) ) { glClear( GL_COLOR_BUFFER_BIT ); // Render OpenGL here double xpos, ypos; glfwGetCursorPos( window, &xpos, &ypos ); // Swap front and back buffers glfwSwapBuffers( window ); // Poll for and process events glfwPollEvents( ); } glfwTerminate( ); return 0; }
// called when mouse enters or leaves the specified window GLFWcursorenterfun InputManager::addMouseEnterCallback( GLFWwindow* window ) { return glfwSetCursorEnterCallback(window, mouseEnter_callback); }
kit::Window::Window(kit::Window::Args const & windowArgs) { kit::Window::m_instanceCount++; this->m_glfwHandle = nullptr; this->m_isFocused = true; this->m_isMinimized = false; this->m_virtualMouse = false; // Get the GLFW handle from the window to share resources with GLFWwindow * glfwSharedWindow = nullptr; if(windowArgs.sharedWindow != nullptr) { glfwSharedWindow = windowArgs.sharedWindow->getGLFWHandle(); } // Get the GLFW handle for the fullscreen monitor to use GLFWmonitor* glfwFullscreenMonitor = windowArgs.fullscreenMonitor->getGLFWHandle(); // Set OpenGL context hints. kit::Window::prepareGLFWHints(GLFW_CONTEXT_VERSION_MAJOR, 4); kit::Window::prepareGLFWHints(GLFW_CONTEXT_VERSION_MINOR, 3); kit::Window::prepareGLFWHints(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Set window-specific hints and create window according to our window-arguments switch(windowArgs.mode) { case kit::Window::Mode::Windowed: if(!windowArgs.resizable) { kit::Window::prepareGLFWHints(GLFW_RESIZABLE, GL_FALSE); } this->m_glfwHandle = glfwCreateWindow(windowArgs.resolution.x, windowArgs.resolution.y, windowArgs.title.c_str(), nullptr, glfwSharedWindow); break; case kit::Window::Mode::Fullscreen: this->m_glfwHandle = glfwCreateWindow(windowArgs.resolution.x, windowArgs.resolution.y, windowArgs.title.c_str(), glfwFullscreenMonitor, glfwSharedWindow); break; case kit::Window::Mode::Borderless: kit::Window::prepareGLFWHints(GLFW_DECORATED, GL_FALSE); kit::Window::prepareGLFWHints(GLFW_RESIZABLE, GL_FALSE); this->m_glfwHandle = glfwCreateWindow(windowArgs.resolution.x, windowArgs.resolution.y, windowArgs.title.c_str(), nullptr, glfwSharedWindow); break; default: KIT_THROW("Invalid window mode"); break; } // Reset the GLFW hints after creation kit::Window::restoreGLFWHints(); // Assert that we have a GLFW window if(!this->m_glfwHandle) { KIT_THROW("Failed to create GLFW window"); } // Register the window to the static list of windows, to keep track of events/callbacks kit::Window::m_windows.push_back(this); // Register GLFW callbacks for this window glfwSetWindowPosCallback(this->m_glfwHandle, kit::Window::__winfunc_position); glfwSetWindowSizeCallback(this->m_glfwHandle, kit::Window::__winfunc_size); glfwSetWindowCloseCallback(this->m_glfwHandle, kit::Window::__winfunc_close); glfwSetWindowFocusCallback(this->m_glfwHandle, kit::Window::__winfunc_focus); glfwSetWindowIconifyCallback(this->m_glfwHandle, kit::Window::__winfunc_minimize); glfwSetFramebufferSizeCallback(this->m_glfwHandle, kit::Window::__winfunc_framebuffersize); glfwSetMouseButtonCallback(this->m_glfwHandle, kit::Window::__infunc_mousebutton); glfwSetCursorPosCallback(this->m_glfwHandle, kit::Window::__infunc_cursorpos); glfwSetCursorEnterCallback(this->m_glfwHandle, kit::Window::__infunc_cursorenter); glfwSetScrollCallback(this->m_glfwHandle, kit::Window::__infunc_scroll); glfwSetKeyCallback(this->m_glfwHandle, kit::Window::__infunc_key); glfwSetCharCallback(this->m_glfwHandle, kit::Window::__infunc_char); // Activate the current windows context this->activateContext(); // Enable V-sync glfwSwapInterval(1); // Make sure GL3W is initialized, and set the viewport kit::initializeGL3W(); KIT_GL(glViewport(0, 0, this->getFramebufferSize().x , this->getFramebufferSize().y)); }
int main(int argc, char* argv[]) { if(argc>1) { mainScript=argv[1]; } //glfw if(!glfwInit()) { std::cout << "GLFW init error.\n"; return 1; } window = glfwCreateWindow(1280, 600, "Demo", 0, 0); if(!window) { glfwTerminate(); std::cout << "GLFW window creation error.\n"; return 2; } glfwMakeContextCurrent(window); glfwSwapInterval(1); //glfw callbacks glfwSetKeyCallback(window, onKey); glfwSetMouseButtonCallback(window, onMouseButton); glfwSetCursorPosCallback(window, onCursor); glfwSetScrollCallback(window, onScroll); glfwSetWindowIconifyCallback(window,onIconify); glfwSetWindowFocusCallback(window,onFocus); glfwSetCursorEnterCallback(window, onCursorEnter); glfwSetCharCallback(window, onChar); //glew GLenum glewErr = glewInit(); if(GLEW_OK != glewErr) { std::cout << "GLEW Error " << glewGetErrorString(glewErr) << std::endl; glfwTerminate(); return 3; } // printVers(); // int majorVer,minorVer; glGetIntegerv(GL_MAJOR_VERSION,&majorVer); glGetIntegerv(GL_MINOR_VERSION,&minorVer); //std::cout << majorVer<<" "<<minorVer << std::endl; // programManager=new ProgramManager(); // if(majorVer>3 || minorVer>=3) { geometryShaderSupport=true; programManager->setGeometryShaderSupport(true); glPrimitiveRestartIndex(-1); } // initDeferred(); //inits textureManager=new TextureManager(); geometryVaoManager=new GeometryVaoManager(); scene=new Scene(mainScript); // UpdateListener *fileListener=new UpdateListener(); FW::FileWatcher fileWatcher; fileWatcher.addWatch("data/shader/geometry", fileListener); fileWatcher.addWatch("data/shader/deferred", fileListener); fileWatcher.addWatch("data/shader", fileListener); fileWatcher.addWatch("data/texture", fileListener); fileWatcher.addWatch("data/geometry", fileListener); fileWatcher.addWatch("data", fileListener); // int lastClientWidth=0,lastClientHeight=0; // while(!glfwWindowShouldClose(window)) { fileWatcher.update(); double time = glfwGetTime(); int clientWidth,clientHeight; glfwGetWindowSize(window, &clientWidth, &clientHeight); scene->run(time,clientWidth,clientHeight); glfwSetInputMode(window,GLFW_CURSOR, scene->isLockCursor()?GLFW_CURSOR_DISABLED:GLFW_CURSOR_NORMAL); if(lastClientWidth != clientWidth || lastClientHeight != clientHeight) { setupDeferred(clientWidth?clientWidth:128, clientHeight?clientHeight:128); } render(clientWidth,clientHeight); glfwSwapBuffers(window); glfwPollEvents(); // lastClientWidth=clientWidth; lastClientHeight=clientHeight; } //uninits delete programManager; delete textureManager; delete geometryVaoManager; delete scene; uninitDeferred(); // glfwTerminate(); return 0; }
int main(int argc, const char * argv[]) { GLFWwindow *window = NULL; const GLubyte *renderer; const GLubyte *version; if (!glfwInit()) { fprintf(stderr, "ERROR: could not start GLFW3\n"); return 1; } glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Assignment 4", NULL, NULL); if (!window) { fprintf (stderr, "ERROR: opening OS window\n"); return 1; } glfwMakeContextCurrent(window); glfwSetCursorEnterCallback(window, handleCursorEnter); glfwSetCursorPosCallback(window, handleCursorPosition); glewExperimental = GL_TRUE; glewInit(); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glClearColor(0.0, 0.0, 0.0, 1.0); renderer = glGetString(GL_RENDERER); version = glGetString(GL_VERSION); std::cout << "Renderer: " << renderer << std::endl; std::cout << "OpenGL version supported " << version << std::endl; std::cout << std::endl; GLVertexArray ground_vao = GLVertexArray("/Users/mattdonnelly/Documents/College/Computer Graphics/Assignment 4/obj/ground.obj"); GLVertexArray cube_vao = GLVertexArray("/Users/mattdonnelly/Documents/College/Computer Graphics/Assignment 4/obj/cube.obj"); GLTexture ground_texture = GLTexture::GLTexture("/Users/mattdonnelly/Documents/College/Computer Graphics/Assignment 4/tex/ground.png"); GLTexture cube_texture = GLTexture::GLTexture("/Users/mattdonnelly/Documents/College/Computer Graphics/Assignment 4/tex/cube.png"); GLProgram shader_program = GLProgram("/Users/mattdonnelly/Documents/College/Computer Graphics/Assignment 4/Assignment 4/vertex_shader.glsl", "/Users/mattdonnelly/Documents/College/Computer Graphics/Assignment 4/Assignment 4/fragment_shader.glsl"); GLint texture_location = shader_program.uniform("tex"); assert(texture_location > -1); camera = GLCamera(); camera.position = glm::vec3(0.0f, 3.0f, 10.0f); camera.speed = 10.0f; glm::mat4 projection = glm::perspective(45.0f, (float)GL_WIDTH / (float)GL_HEIGHT, 0.1f, 100.0f); shader_program.use(); const int proj_mat_location = shader_program.uniform("projection"); const int view_mat_location = shader_program.uniform("view"); const int model_mat_location = shader_program.uniform("model"); while (!glfwWindowShouldClose(window)) { static double previous_seconds = glfwGetTime(); double current_seconds = glfwGetTime(); double elapsed_seconds = current_seconds - previous_seconds; previous_seconds = current_seconds; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, GL_WIDTH, GL_HEIGHT); glfwPollEvents(); shader_program.use(); glm::mat4 model = glm::mat4(1.0f); glm::mat4 view = camera.getViewMatrix(); shader_program.setUniform(proj_mat_location, projection); shader_program.setUniform(view_mat_location, view); shader_program.setUniform(model_mat_location, model); ///////// GROUND ///////// ground_texture.bindTexture(GL_TEXTURE0); shader_program.setUniform(texture_location, 0); ground_vao.draw(); ///////// BOTTOM CUBE ///////// cube_texture.bindTexture(GL_TEXTURE0); shader_program.setUniform(texture_location, 0); model = glm::translate(glm::mat4(1.0f), glm::vec3(sinf(glfwGetTime()) * 6.0f, 2.1f, 0.0f)); shader_program.setUniform(model_mat_location, model); cube_vao.draw(); ///////// TOP CUBE ///////// model = glm::translate(model, glm::vec3(0.0f, 2.01f, 0.0f)); model = glm::rotate(model, (float)glfwGetTime(), glm::vec3(0.0f, 1.0f, 0.0f)); shader_program.setUniform(model_mat_location, model); cube_vao.draw(); if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_ESCAPE)) { glfwSetWindowShouldClose(window, 1); } if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_W)) { camera.moveForward(elapsed_seconds); } else if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_S)) { camera.moveBackward(elapsed_seconds); } if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_A)) { camera.moveLeft(elapsed_seconds); } else if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_D)) { camera.moveRight(elapsed_seconds); } if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_E)) { camera.moveUp(elapsed_seconds); } else if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_Q)) { camera.moveDown(elapsed_seconds); } glfwSwapBuffers(window); } glfwTerminate(); return 0; }
static void WIN_Show( DaoProcess *proc, DaoValue *p[], int N ) { DaoxWindow *self = (DaoxWindow*) p[0]; DaoxCanvas *canvas = (DaoxCanvas*) DaoValue_CastCstruct( p[1], daox_type_canvas ); DaoxScene *scene = (DaoxScene*) DaoValue_CastCstruct( p[1], daox_type_scene ); DaoxFont *font = DaoxFont_GetDefault(); int fpsLimit = p[2]->xInteger.value; int fpsTest = p[3]->xBoolean.value; double fpsTestTime = 0.0; double timeInterval = 0.0; double lastFrameStart = 0.0; float currentFPS = 0.0; size_t fpsCount = 0; char chars[32]; if( fpsTest && self->widget == NULL ){ char *fpsText = "FPS: "; DaoxColor bgcolor = {0.0,0.0,0.0,0.0}; DaoxBrush *brush; self->widget = DaoxCanvas_New( NULL ); self->widget->viewport.right = self->width; self->widget->viewport.top = self->height; DaoGC_IncRC( (DaoValue*) self->widget ); DaoxCanvas_SetBackground( self->widget, bgcolor ); brush = DaoxCanvas_PushBrush( self->widget, 0 ); brush->strokeColor.blue = 1.0; brush->fillColor.blue = 1.0; brush->fillColor.alpha = 1.0; brush->fontSize = 20; self->fpsLabel = DaoxCanvas_AddText( self->widget, fpsText, 10, self->height - 20, 0 ); } if( self->painter == NULL && (canvas != NULL || self->widget != NULL) ){ self->painter = DaoxPainter_New( self->context ); DaoGC_IncRC( (DaoValue*) self->painter ); } if( self->renderer == NULL && scene != NULL ){ self->renderer = DaoxRenderer_New( self->context ); DaoGC_IncRC( (DaoValue*) self->renderer ); } if( canvas != NULL ){ float dm = sqrt(self->width*self->width + self->height*self->height ); float cx = 0.5*(canvas->viewport.left + canvas->viewport.right); float cy = 0.5*(canvas->viewport.top + canvas->viewport.bottom); float w = canvas->viewport.right - canvas->viewport.left; float h = canvas->viewport.top - canvas->viewport.bottom; float d = sqrt(w*w + h*h); w = 0.5 * self->width * d / dm; h = 0.5 * self->height * d / dm; canvas->viewport.left = cx - w; canvas->viewport.right = cx + w; canvas->viewport.bottom = cy - h; canvas->viewport.top = cy + h; } GC_Assign( & self->model, p[1] ); self->visible = 1; glfwShowWindow( self->handle ); glfwMakeContextCurrent( self->handle ); glfwSetKeyCallback( self->handle, DaoxWindow_KeyCallback ); glfwSetCursorPosCallback( self->handle, DaoxWindow_CursorMoveCallback ); glfwSetCursorEnterCallback( self->handle, DaoxWindow_CursorEnterCallback ); glfwSetWindowFocusCallback( self->handle, DaoxWindow_FocusCallback ); #ifdef SAVE_RENDERED_SCENE char name[50]; int frame = 1; DaoxImage *image = DaoxImage_New(); image->depth = DAOX_IMAGE_BIT32; DaoxImage_Resize( image, self->width, self->height ); #endif while( self->visible && ! glfwWindowShouldClose( self->handle ) ){ double frameStartTime = 0.0; double frameEndTime = 0.0; frameStartTime = glfwGetTime(); if( canvas ) DaoxPainter_Paint( self->painter, canvas, canvas->viewport ); if( scene ){ #ifdef SAVE_RENDERED_SCENE DaoxScene_Update( scene, 1.0/30.0 ); glReadBuffer( GL_BACK ); glPixelStorei( GL_UNPACK_ALIGNMENT, 4 ); glPixelStorei( GL_PACK_ROW_LENGTH, image->width ); DaoxRenderer_Render( self->renderer, scene, scene->camera ); glReadPixels( 0, 0, self->width, self->height, GL_RGBA, GL_UNSIGNED_BYTE, image->imageData ); sprintf( name, "rama_attack_frame_%03i.png", frame ); DaoxImage_SavePNG( image, name ); frame += 1; if( frame > 155 ) break; #else DaoxScene_Update( scene, frameStartTime - lastFrameStart ); DaoxRenderer_Render( self->renderer, scene, scene->camera ); #endif } lastFrameStart = frameStartTime; if( fpsTest ){ if( fpsCount % 10 == 0 ){ int i, n = sprintf( chars, "%.1f", currentFPS ); for(i=0; i<n; ++i){ DaoxGlyph *glyph = DaoxFont_GetGlyph( font, chars[i] ); DaoxCanvasNode *chnode = self->fpsLabel->children->items.pCanvasNode[i+5]; DaoxPath *path = DaoxPathCache_FindPath( self->widget->pathCache, glyph->shape ); GC_Assign( & chnode->path, path ); DaoxCanvasNode_MarkDataChanged( chnode ); } } DaoxPainter_Paint( self->painter, self->widget, self->widget->viewport ); } glfwSwapBuffers( self->handle ); glfwPollEvents(); if( fpsTest == 0 ) continue; frameEndTime = glfwGetTime(); timeInterval = frameEndTime - frameStartTime; if( timeInterval < 1.0/fpsLimit ) usleep( 1000000 * (1.0/fpsLimit - timeInterval) ); fpsCount += 1; currentFPS = fpsCount / (frameEndTime - fpsTestTime); if( frameEndTime > (fpsTestTime + 3) ){ fpsTestTime = frameEndTime - 1.0; fpsCount = currentFPS; /* Frame count estimation in the past second; */ } } glfwHideWindow( self->handle ); }
bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float frameZoomFactor) { setViewName(viewName); _frameZoomFactor = frameZoomFactor; glfwWindowHint(GLFW_DECORATED,GL_FALSE); glfwWindowHint(GLFW_RESIZABLE,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); int needWidth = rect.size.width * _frameZoomFactor; int neeHeight = rect.size.height * _frameZoomFactor; _mainWindow = glfwCreateWindow(needWidth, neeHeight, _viewName.c_str(), _monitor, nullptr); if (!_mainWindow) { MessageBox("Window creation will fail if the Microsoft GDI software OpenGL implementation is the only one available.", "Create Window failed"); 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); glfwSetWindowCloseCallback(_mainWindow, GLFWEventHandler::onGLFWWindowCloseCallback); glfwSetCursorEnterCallback(_mainWindow, GLFWEventHandler::onGLFWCursorEnterCallBack); 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); return true; }
int main(int argc, char *argv[]){ glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); glfwWindowHint(GLFW_SAMPLES, 4); GLFWwindow *window = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Solar", nullptr, nullptr); glfwMakeContextCurrent(window); glfwSetKeyCallback(window, key_callback); glfwSetCursorPosCallback(window, mouse_callback); glfwSetScrollCallback(window, scroll_callback); glfwSetCursorEnterCallback(window, cursor_enter_callback); glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glewExperimental = GL_TRUE; glewInit(); glGetError(); glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); glEnable(GL_DEPTH_TEST); glEnable(GL_MULTISAMPLE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_PROGRAM_POINT_SIZE); //---------------------------test code---------------------------- //---------------------------------------------------------------- solar.Init(); GLfloat deltaTime = 0.0f; GLfloat lastFrame = 0.0f; while (!glfwWindowShouldClose(window)) { GLfloat currentFrame = glfwGetTime(); deltaTime = currentFrame - lastFrame; lastFrame = currentFrame; glfwPollEvents(); glClearColor(0.05f, 0.05f, 0.068f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); solar.ProcessInput(deltaTime); solar.Update(deltaTime); solar.Render(); //-------------------------test code------------------------------- //------------------------------------------------------------------ InputManager::ClearMouseMovement(); InputManager::ClearMouseScroll(); glfwSwapBuffers(window); } ResourceManager::Clear(); glfwTerminate(); return 0; }
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 Game::Initialize(){ LOG(info) << "Jarg initialization start"; glfwSetErrorCallback([](int a,const char* description){LOG(error) << description;}); int glfwErrorCode = glfwInit(); if (!glfwErrorCode) { LOG(error) << "glfwInit error " << glfwErrorCode; return glfwErrorCode; } glfwWindowHint(GLFW_SAMPLES, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, Game::MAJOR_GL); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, Game::MINOR_GL); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); monitor = nullptr; if(fullscreen) { monitor = glfwGetPrimaryMonitor(); } window = glfwCreateWindow(width, height, title.c_str(), monitor, nullptr); if (!window) { glfwTerminate(); LOG(fatal) << "Ошибка создания окна GLFW."; return false; } glfwMakeContextCurrent(window); //glfwSetWindowTitle(window, AutoVersion::GetTitle().c_str()); glfwSwapInterval(0); if (glewInit() != GLEW_OK) { LOG(fatal) << "GLEW не инициализирован."; return false; } GameObject go; go.seed = 123; for (int i =0; i<100; i++) { GenerateStar(&go); } int glVersion[2] = {-1, -1}; glGetIntegerv(GL_MAJOR_VERSION, &glVersion[0]); glGetIntegerv(GL_MINOR_VERSION, &glVersion[1]); LOG(info) << "Renderer: " << glGetString(GL_RENDERER); LOG(info) << "Vendor: " << glGetString(GL_VENDOR); LOG(info) << "Version: " << glGetString(GL_VERSION); LOG(info) << "GLSL version: " << glGetString(GL_SHADING_LANGUAGE_VERSION); LOG(info) << "using OpenGL: " << std::to_string(glVersion[0]) << "." << std::to_string(glVersion[1]); LOG(info) << "glfw: " << glfwGetVersionString(); Keyboard::Initialize(); glfwSetKeyCallback(window, [](GLFWwindow *win, int key, int scancode, int action, int mods){Keyboard::SetKey(key, scancode, action, mods);}); Mouse::Initialize(window); Mouse::SetWindowSize(width, height); // Mouse::SetFixedPosState(true); glfwSetCursorPosCallback(window, [](GLFWwindow *window, double xpos, double ypos){Mouse::SetCursorPos(xpos, ypos);}); glfwSetCursorEnterCallback(window, [](GLFWwindow *window, int entered){Mouse::CursorClientArea(entered);}); glfwSetWindowFocusCallback(window, [](GLFWwindow *window, int focused){Mouse::WindowFocus(focused);}); glfwSetMouseButtonCallback(window, [](GLFWwindow *window, int a, int b, int c){Mouse::SetButton(a, b, c);}); glfwSetWindowSizeCallback(window, [](GLFWwindow *window, int a, int b){Game::Resize(a, b); Mouse::SetWindowSize(a, b);}); glfwSetScrollCallback(window, [](GLFWwindow *window, double a, double b){Mouse::Scroll(b);}); wire = 1; spd = 1; ////////////////////////////////////////////////////////////////////////// LinesShader = std::shared_ptr<BasicJargShader>(new BasicJargShader()); LinesShader->loadShaderFromSource(GL_VERTEX_SHADER, "Shaders/colored.glsl"); LinesShader->loadShaderFromSource(GL_FRAGMENT_SHADER, "Shaders/colored.glsl"); LinesShader->Link(); mvpLine = LinesShader->locateVars("MVP"); TextureShader = std::shared_ptr<BasicJargShader>(new BasicJargShader()); TextureShader->loadShaderFromSource(GL_VERTEX_SHADER, "Shaders/textured.glsl"); TextureShader->loadShaderFromSource(GL_FRAGMENT_SHADER, "Shaders/textured.glsl"); TextureShader->Link(); mvpTex = TextureShader->locateVars("MVP"); FXAAShader = std::shared_ptr<BasicJargShader>(new BasicJargShader()); FXAAShader->loadShaderFromSource(GL_VERTEX_SHADER, "Shaders/fxaa.glsl"); FXAAShader->loadShaderFromSource(GL_FRAGMENT_SHADER, "Shaders/fxaa.glsl"); FXAAShader->Link(); BasicShader = std::shared_ptr<BasicJargShader>(new BasicJargShader()); BasicShader->loadShaderFromSource(GL_VERTEX_SHADER, "Shaders/minnaert.glsl"); BasicShader->loadShaderFromSource(GL_FRAGMENT_SHADER, "Shaders/minnaert.glsl"); BasicShader->loadShaderFromSource(GL_TESS_CONTROL_SHADER, "Shaders/minnaert.glsl"); BasicShader->loadShaderFromSource(GL_TESS_EVALUATION_SHADER, "Shaders/minnaert.glsl"); BasicShader->Link(); BasicShader->UpdateUniforms(); BasicShader->locateVars("transform.viewProjection"); //var0 BasicShader->locateVars("transform.model"); //var1 BasicShader->locateVars("transform.normal"); //var2 BasicShader->locateVars("material.texture"); testtex = std::shared_ptr<Texture>(new Texture()); testtex->Empty(vec2(256,256)); uptex = std::shared_ptr<Texture>(new Texture()); uptex->Load("up.png"); ////////////////////////////////////////////////////////////////////////// light.position = vec4(5.0f, 12.0f, 3.0f, 1.0f); light.ambient = vec4(0.2f, 0.2f, 0.2f, 1.0f); light.diffuse = vec4(1.0f, 1.0f, 1.0f, 1.0f); light.specular = vec4(1.0f, 1.0f, 1.0f, 1.0f); light.attenuation = vec3(0.000f, 0.0f, 0.00000f); batched = std::unique_ptr<Batched>(new Batched()); batched->Initialize(TextureShader.get(), LinesShader.get()); font = std::unique_ptr<Font>(new Font()); font->Initialize(); //actually not load json if(!font->Create("font.json")){ LOG(error) << "failed to load\process font.json"; } WindowsDesigner(); camera = std::unique_ptr<Camera>(new Camera()); camera->SetViewport(0, 0, width, height); camera->SetPosition(vec3(2,2,2)); camera->SetLookAt(vec3(0)); gt = std::unique_ptr<GameTimer>(new GameTimer); Generation gen; rs = new QuadTreePlane(); rs->Init(BasicShader, *camera); auto tex = std::shared_ptr<Texture>(new Texture()); tex->Load("normal.png"); icos = std::unique_ptr<Mesh>(new Mesh(Cube::getMesh())); icos->Bind(); icos->shader = BasicShader; icos->material = std::shared_ptr<Material>(new Material()); icos->material->texture = tex; //test.LoadBinary("untitled.m"); test.Bind(); for (int i = 0; i<test.meshes.size(); i++) { test.meshes[i]->shader = BasicShader; } return true; }
void Application::initInternal() { rootRegion.setBounds(CoordPercent(0.0f, 0.0f), CoordPercent(1.0f, 1.0f)); context->addAssetDirectory("assets/"); context->addAssetDirectory("../assets/"); context->addAssetDirectory("../../assets/"); context->loadFont(FontType::Normal, "sans", "fonts/Roboto-Regular.ttf"); context->loadFont(FontType::Bold, "sans-bold", "fonts/Roboto-Bold.ttf"); context->loadFont(FontType::Italic, "sans-italic", "fonts/Roboto-Italic.ttf"); context->loadFont(FontType::Code, "sans", "fonts/Hack-Regular.ttf"); context->loadFont(FontType::CodeBold, "sans-bold", "fonts/Hack-Bold.ttf"); context->loadFont(FontType::CodeItalic, "sans-bold-italic", "fonts/Hack-Italic.ttf"); context->loadFont(FontType::CodeBoldItalic, "sans-bold-italic", "fonts/Hack-BoldItalic.ttf"); context->loadFont(FontType::Entypo, "entypo", "fonts/entypo.ttf"); context->loadFont(FontType::Icon, "icons", "fonts/fontawesome.ttf"); glfwSetWindowUserPointer(context->window, this); glfwSetWindowRefreshCallback(context->window, [](GLFWwindow * window ) { Application* app = (Application *)(glfwGetWindowUserPointer(window)); try { app->onWindowRefresh(); } catch(...) { app->throwException(std::current_exception()); } }); glfwSetWindowFocusCallback(context->window, [](GLFWwindow * window, int focused ) { Application* app = (Application *)(glfwGetWindowUserPointer(window)); try { app->onWindowFocus(focused); } catch(...) { app->throwException(std::current_exception()); } }); glfwSetWindowSizeCallback(context->window, [](GLFWwindow * window, int width, int height ) { Application* app = (Application *)(glfwGetWindowUserPointer(window)); try { app->onWindowSize(width, height); } catch(...) { app->throwException(std::current_exception()); } }); glfwSetFramebufferSizeCallback(context->window, [](GLFWwindow * window, int width, int height) { Application* app = (Application *)(glfwGetWindowUserPointer(window)); try { app->onFrameBufferSize(width, height); } catch (...) { app->throwException(std::current_exception()); } }); glfwSetCharCallback(context->window, [](GLFWwindow * window, unsigned int codepoint ) { Application* app = (Application *)(glfwGetWindowUserPointer(window)); try { app->onChar(codepoint); } catch(...) { app->throwException(std::current_exception()); } }); glfwSetKeyCallback(context->window, [](GLFWwindow * window, int key, int scancode, int action, int mods) { Application* app = (Application *)(glfwGetWindowUserPointer(window)); try { app->onKey(key, scancode,action,mods); } catch(...) { app->throwException(std::current_exception()); } }); glfwSetMouseButtonCallback(context->window, [](GLFWwindow * window, int button, int action,int mods) { Application* app = (Application *)(glfwGetWindowUserPointer(window)); try { app->onMouseButton(button, action,mods); } catch(...) { app->throwException(std::current_exception()); } }); glfwSetCursorPosCallback(context->window, [](GLFWwindow * window, double xpos, double ypos ) { Application* app = (Application *)(glfwGetWindowUserPointer(window)); try { app->onCursorPos(xpos, ypos); } catch(...) { app->throwException(std::current_exception()); } }); glfwSetCursorEnterCallback(context->window, [](GLFWwindow * window, int enter) { Application* app = (Application *)(glfwGetWindowUserPointer(window)); try { app->onCursorEnter(enter); } catch(...) { app->throwException(std::current_exception()); } }); glfwSetScrollCallback(context->window, [](GLFWwindow * window, double xoffset, double yoffset ) { Application* app = (Application *)(glfwGetWindowUserPointer(window)); try { app->onScroll(xoffset, yoffset); } catch(...) { app->throwException(std::current_exception()); } }); imageShader = std::shared_ptr<ImageShader>( new ImageShader(ImageShader::Filter::NONE, true, context)); uiFrameBuffer = std::shared_ptr<GLFrameBuffer>( new GLFrameBuffer(true, context)); uiFrameBuffer->initialize(context->viewSize.x, context->viewSize.y); }
// Performs OpenGL window initialization. bool Rcsgedit::WindowInitialization() { if (!GLManager::Initialize(50.0f, 0.1f, 1000.0f, false, 1366, 768, Rcsgedit::NAME)) { std::cout << "Failed to initialize the OpenGL Manager!" << std::endl; return false; } GLManager *pM = GLManager::GetManager(); // Initialize GLFW if (!glfwInit()) { std::cout << "GLFW initialization failure!" << std::endl; return false; } // Setup GLFW // Window hints glfwDefaultWindowHints(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, GLManager::OPENGL_MAJOR); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, GLManager::OPENGL_MINOR); glfwWindowHint(GLFW_SAMPLES, GLManager::ALIASING_LEVEL); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Window creation. if (pM->fullscreen) { pWindow = glfwCreateWindow(pM->width, pM->height, pM->title.c_str(), glfwGetPrimaryMonitor(), NULL); } else { pWindow = glfwCreateWindow(pM->width, pM->height, pM->title.c_str(), NULL, NULL); } if (pWindow == NULL) { std::cout << "GLFW window creation failure: " << glewGetErrorString(glGetError()) << std::endl; return false; } glfwMakeContextCurrent(pWindow); // Callback initialization. InputSystem::Initialize(); glfwSetCharCallback(pWindow, InputSystem::KeyTyped); glfwSetKeyCallback(pWindow, InputSystem::KeyEvent); glfwSetMouseButtonCallback(pWindow, InputSystem::MouseButtonEvent); glfwSetScrollCallback(pWindow, InputSystem::ScrollEvent); glfwSetCursorEnterCallback(pWindow, InputSystem::CursorTravel); glfwSetCursorPosCallback(pWindow, InputSystem::CursorMove); glfwSetWindowSizeCallback(pWindow, InputSystem::Resize); glfwSetErrorCallback(InputSystem::ErrorCallback); // GLEW initialization. glewExperimental = GL_TRUE; GLenum err = glewInit(); if (err != GLEW_OK) { std::cout << "GLEW initialization failure: " << glewGetErrorString(err) << std::endl; return false; } // Display debug info and enable debug mode if specified. std::cout << "Using OpenGL vendor " << glGetString(GL_VENDOR) << ", version " << glGetString(GL_VERSION) << std::endl; std::cout << " >> System uses OpenGL renderer " << glGetString(GL_RENDERER) << " <<" << std::endl; return true; }
void GlfwWindow::open() { glfwSetErrorCallback(error_callback); int monitor_count(0); auto monitors(glfwGetMonitors(&monitor_count)); if (monitor_count == 0) { Logger::LOG_WARNING << "Failed to open GlfwWindow: No monitor found!" << std::endl; glfwTerminate(); return; } if (config.monitor() >= monitor_count) { Logger::LOG_WARNING << "Failed to open GlfwWindow: There is no monitor with the number " << config.monitor() << "!" << std::endl; glfwTerminate(); return; } glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, config.get_debug()); if (config.get_stereo_mode() == StereoMode::QUAD_BUFFERED) { glfwWindowHint(GLFW_STEREO, GL_TRUE); } glfw_window_ = glfwCreateWindow( config.get_size().x, config.get_size().y, config.get_title().c_str(), config.get_fullscreen_mode()? glfwGetPrimaryMonitor(): nullptr, nullptr ); if (!glfw_window_) { throw std::runtime_error("GlfwWindow::open() : unable to create window"); } glfwSetWindowUserPointer(glfw_window_, this); glfwSetWindowSizeCallback(glfw_window_, &on_window_resize); glfwSetKeyCallback( glfw_window_, &on_window_key_press); glfwSetCharCallback( glfw_window_, &on_window_char); glfwSetMouseButtonCallback( glfw_window_, &on_window_button_press); glfwSetCursorPosCallback( glfw_window_, &on_window_move_cursor); glfwSetScrollCallback( glfw_window_, &on_window_scroll); glfwSetCursorEnterCallback( glfw_window_, &on_window_enter); switch(cursor_mode_) { case CursorMode::NORMAL: glfwSetInputMode(glfw_window_, GLFW_CURSOR, GLFW_CURSOR_NORMAL); break; case CursorMode::HIDDEN: glfwSetInputMode(glfw_window_, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); break; case CursorMode::DISABLED: glfwSetInputMode(glfw_window_, GLFW_CURSOR, GLFW_CURSOR_DISABLED); break; } if (!glfw_window_) { Logger::LOG_WARNING << "Failed to open GlfwWindow: Could not create glfw3 window!" << std::endl; glfwTerminate(); return; } }
WindowGL33::CursorEnterEventType::DelegatePtr WindowGL33::addCursorEnterCallback( CursorEnterCallbackType const& callback) { glfwSetCursorEnterCallback(m_pWndHandle, WindowGL33::cursorEnterCallback); return m_cursorEnterCallbacks.addListener(callback); }