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; }
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; }
Window* Window::Create(int Width, int Height) { Window* Win = new Window; Win->WindowHandle = glfwCreateWindow(Width, Height, "Bakge", NULL, NULL); if(Win->WindowHandle == NULL) { delete Win; return NULL; } /* Store pointer to Bakge window so global callbacks can access it */ glfwSetWindowUserPointer(Win->WindowHandle, (void*)Win); glfwSetWindowCloseCallback(Win->WindowHandle, WindowClosed); glfwSetWindowSizeCallback(Win->WindowHandle, WindowResized); glfwSetWindowPosCallback(Win->WindowHandle, WindowMoved); Win->Bind(); return Win; }
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); }
// -------------------------------------------------------------------------------------------------------------------- window::builder::builder(/*allocator*/) : _win(nullptr) , _name("Marbles") , _width(1280) , _height(720) , _fullscreen(false) , _validation(false) { _pre.reserve(8); _pre.push_back(async(launch::deferred, [this]() -> int { glfwDefaultWindowHints(); if (glfwVulkanSupported()) { glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); // use vulkan } return 0; })); _post.reserve(8); _post.push_back(async(launch::deferred, [this]() -> int { GLFWwindow* glfwWin = this->_win->_internal->_window; glfwSetWindowUserPointer(glfwWin, this->_win); glfwSetWindowPosCallback(glfwWin, [](GLFWwindow* glfwWin, int x, int y) { window* win = reinterpret_cast<window*>(glfwGetWindowUserPointer(glfwWin)); win->onReposition(win, x, y); }); glfwSetWindowCloseCallback(glfwWin, [](GLFWwindow* glfwWin) { window* win = reinterpret_cast<window*>(glfwGetWindowUserPointer(glfwWin)); win->onClose(win); }); return 0; })); }
Window::Window(int w, int h, const char *t, GLFWmonitor *m, GLFWwindow *s, const Hint &hint) :isEnable(false), X(x), Y(y), Width(this->w), Height(this->h), fbWidth(fbw), fbHeight(fbh), Title(title) { hint.apply(); if(!(wnd = glfwCreateWindow(w, h, t, m, s))) { std::cerr << "Createting Window is failed.\n"; std::cerr << "Window '" << t << "' is not enable.\n"; return; } glfwSetWindowUserPointer(wnd, this); glfwSetWindowPosCallback(wnd, position); glfwSetWindowSizeCallback(wnd, size); glfwSetFramebufferSizeCallback(wnd, fbsize); isEnable = true; ++glfw_window_count; glfwGetWindowPos (wnd, &x, &y); glfwGetWindowSize (wnd, &this->w, &this->h); glfwGetFramebufferSize(wnd, &fbw, &fbh); title = t; }
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); }
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); }
bool GLView::createWindow(std::string windowname) { if (!glfwInit()) { return false; } _glContextAttrs = { 8, 8, 8, 8, 24,8 }; 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); Size winSize = Director::getInstance()->getWinSize(); _mainWindow = glfwCreateWindow(winSize.width, winSize.height, windowname.c_str(), nullptr, nullptr); glfwMakeContextCurrent(_mainWindow); //在我们使用 GL 命令之前我们需要将创建的窗口设置为当前窗口 //glViewport(0, 0, 480, 320); 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); initGlew(); return true; }
bool EGLView::init(const char* viewName, float width, float height, float frameZoomFactor) { if(nullptr != _mainWindow) return true; setViewName(viewName); setFrameSize(width, height); setFrameZoomFactor(frameZoomFactor); glfwWindowHint(GLFW_RESIZABLE,GL_FALSE); _mainWindow = glfwCreateWindow(_screenSize.width * _frameZoomFactor, _screenSize.height * _frameZoomFactor, _viewName, nullptr, nullptr); glfwMakeContextCurrent(_mainWindow); glfwGetFramebufferSize(_mainWindow, &_frameBufferSize[0], &_frameBufferSize[1]); glfwSetMouseButtonCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseCallBack); glfwSetCursorPosCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseMoveCallBack); glfwSetCharCallback(_mainWindow, EGLViewEventHandler::OnGLFWCharCallback); glfwSetKeyCallback(_mainWindow, EGLViewEventHandler::OnGLFWKeyCallback); glfwSetWindowPosCallback(_mainWindow, EGLViewEventHandler::OnGLFWWindowPosCallback); // check OpenGL version at first const GLubyte* glVersion = glGetString(GL_VERSION); CCLOG("OpenGL version = %s", glVersion); if ( 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; } GLenum GlewInitResult = glewInit(); if (GLEW_OK != GlewInitResult) { MessageBox((char *)glewGetErrorString(GlewInitResult), "OpenGL error"); return false; } if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader) { log("Ready for GLSL"); } else { log("Not totally ready :("); } if (glewIsSupported("GL_VERSION_2_0")) { log("Ready for OpenGL 2.0"); } else { log("OpenGL 2.0 not supported"); } // if(glew_dynamic_binding() == false) // { // MessageBox("No OpenGL framebuffer support. Please upgrade the driver of your video card.", "OpenGL error"); // return false; // } // // Enable point size by default on windows. glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); return true; }
int main(int argc, char** argv) { GLFWwindow* window; GLFWmonitor* monitor = NULL; int ch, width, height; setlocale(LC_ALL, ""); glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); printf("Library initialized\n"); while ((ch = getopt(argc, argv, "f")) != -1) { switch (ch) { case 'f': monitor = glfwGetPrimaryMonitor(); break; } } window = glfwCreateWindow(640, 480, "Event Linter", monitor, 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); }
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; }
WindowGL33::PositionEventType::DelegatePtr WindowGL33::addPositionCallback(PositionCallbackType const& callback) { glfwSetWindowPosCallback(m_pWndHandle, WindowGL33::positionCallback); return m_positionCallbacks.addListener(callback); }
bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float frameZoomFactor) { setViewName(viewName); _frameZoomFactor = frameZoomFactor; if (s_intriGdipCanvasEnabled) IrregularGL::thisObject()->setupGL(); 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); // x-studio365 spec hints glfwWindowHint(GLFW_DECORATED, !s_intriWindowNoB); glfwWindowHint(GLFW_VISIBLE, s_intriWindowVisible); glfwWindowHint(GLFW_ALPHA_MASK, s_intriWindowAlphaEnabled); glfwxSetParent(s_intriWindowParent); 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); } ccMessageBox(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); // x-studio365 spec: use glfwx setMouseButtonCallback ensure update mouse coord immediately. glfwxSetMouseButtonCallback(_mainWindow, GLFWEventHandler::onGLFWMouseCallBackEx); 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); ccMessageBox(strComplain, "OpenGL version too old"); return false; } initGlew(); // Enable point size by default. glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); return true; }
bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float frameZoomFactor, HWND hParentWnd) { setViewName(viewName); _frameZoomFactor = frameZoomFactor; 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); if (hParentWnd){ 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); m_hwnd = glfwGetWin32Window(_mainWindow); if (hParentWnd){ ::SetParent(m_hwnd, hParentWnd); //改变当前窗口的样式,去掉标题 SetWindowLong(m_hwnd, GWL_STYLE, GetWindowLong(m_hwnd, GWL_STYLE) & ~WS_CAPTION); //设置位置 ::SetWindowPos(m_hwnd, HWND_TOP, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height, SWP_NOCOPYBITS | SWP_HIDEWINDOW); } return true; }
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; }
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)); }
void THIS::init(parent_t * const & p) { printv(DEBUG, "%s\n", __PRETTY_FUNCTION__); if(p == NULL) return; setParent(p); auto app = get_fnd_app(); if(!app->_M_flag.any(neb::fnd::app::util::flag::INIT_GLFW)) { printv(WARNING, "glfw not initializaed\n"); return; } auto g = std::dynamic_pointer_cast<neb::gfx::app::Base>(app->G::get_object()); //auto self = std::dynamic_pointer_cast<THIS>(shared_from_this()); if(window_) return; // create window glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); //glfwWindowHint(GLFW_VISIBLE, GL_FALSE); window_ = glfwCreateWindow( w_, h_, title_.c_str(), NULL, first_window_ ); if(first_window_ == NULL) { first_window_ = window_; } if(window_ == NULL) { glfwTerminate(); printv(DEBUG, "glfwCreateWindow failed\n"); exit(EXIT_FAILURE); } glfwSetWindowPos(window_, x_, y_); glfwMakeContextCurrent(window_); glfwSetWindowPosCallback( window_, neb::gfx::app::glfw::static_window_pos_fun); glfwSetWindowSizeCallback( window_, neb::gfx::app::glfw::static_window_size_fun); glfwSetWindowCloseCallback( window_, neb::gfx::app::glfw::static_window_close_fun); glfwSetWindowRefreshCallback( window_, neb::gfx::app::glfw::static_window_refresh_fun); glfwSetKeyCallback( window_, neb::gfx::app::glfw::static_key_fun); glfwSetMouseButtonCallback( window_, neb::gfx::app::glfw::static_mouse_button_fun); glfwSetCharCallback( window_, neb::gfx::app::glfw::staticCharFun); // add window to app's window map g->reg(shared_from_this()); //if(all(neb::app::base::option::SHADERS)) create_programs(); g->init_glew(); g->create_programs(); //printf("%s\n",glGetString(GL_SHADING_LANGUAGE_VERSION)); //Check for necessary extensions if(!GL_ARB_depth_texture || !GL_ARB_shadow) { printv(CRITICAL, "I require ARB_depth_texture and ARB_shadow extensionsn\n"); exit(0);//return false; } //Shading states glShadeModel(GL_SMOOTH); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //Depth states glClearDepth(1.0f); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glEnable(GL_NORMALIZE); checkerror("unknown"); }
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); }
bool ctx_init(struct context *ctx, int w, int h, bool debug) { assert(! ctx->win); glfwSetErrorCallback(error_callback); if (! glfwInit()) { return false; } GLFWmonitor *monitor = glfwGetPrimaryMonitor(); const GLFWvidmode *mode = glfwGetVideoMode(monitor); int mw, mh; glfwGetMonitorPhysicalSize(monitor, &mw, &mh); ctx->dpi = mode->width / (mw / 25.4); ctx->hidpi = ctx->dpi > 180.0; ctx->vidmode = mode; if (ctx->hidpi) { w *= 2; h *= 2; } glfwWindowHint(GLFW_RESIZABLE, true); glfwWindowHint(GLFW_SRGB_CAPABLE, true); // Require OpenGL 3.3 or later glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // Only support new core functionality glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true); glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, true); glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); glfwWindowHint(GLFW_SAMPLES, 16); if ((ctx->win = glfwCreateWindow(w, h, "px", NULL, NULL)) == NULL) { return false; } glfwMakeContextCurrent(ctx->win); glfwSetWindowUserPointer(ctx->win, ctx); glfwSetInputMode(ctx->win, GLFW_CURSOR, GLFW_CURSOR_NORMAL); glfwSetInputMode(ctx->win, GLFW_STICKY_KEYS, true); glfwSetKeyCallback(ctx->win, key_callback); glfwSetMouseButtonCallback(ctx->win, mouse_button_callback); glfwSetCursorPosCallback(ctx->win, cursor_pos_callback); glfwSetCursorEnterCallback(ctx->win, focus_callback); glfwSetFramebufferSizeCallback(ctx->win, framebuffer_size_callback); glfwSetWindowPosCallback(ctx->win, window_pos_callback); glfwSetCharCallback(ctx->win, char_callback); glfwSetWindowAspectRatio(ctx->win, w, h); glfwGetFramebufferSize(ctx->win, &ctx->winw, &ctx->winh); ctx_win_center(ctx); gl_init(ctx->winw, ctx->winh, debug); int vw = ctx->winw, /* Virtual screen */ vh = ctx->winh; if (ctx->hidpi) { vw /= 2; vh /= 2; /* We can't create odd-sized framebuffer textures, so we make * the screen framebuffer even in case the virtual screen isn't. */ if (vw % 2 != 0) vw ++; if (vh % 2 != 0) vh ++; } infof("ctx", "real screen size: %dx%d", ctx->winw, ctx->winh); infof("ctx", "virtual screen size: %dx%d", vw, vh); ctx->lastframe = 0; ctx->frametime = 0; ctx->transforms = NULL; ctx->ortho = mat4ortho(ctx->winw, ctx->winh); ctx->font = malloc(sizeof(*ctx->font)); ctx->screen = framebuffer_screen(vw, vh, NULL); ctx->width = ctx->hidpi ? ctx->winw / 2 : ctx->winw; ctx->height = ctx->hidpi ? ctx->winh / 2 : ctx->winh; ctx_update_cursor_pos(ctx); ctx_blend_alpha(ctx); ctx_save(ctx); glfwSetTime(0); infof("ctx", "dpi = %f", ctx->dpi); return true; }