Esempio n. 1
0
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);
}
Esempio n. 2
0
void Init()
{
  const int window_width = 800,
           window_height = 600;
 
  if (glfwInit() != GL_TRUE)
    Shut_Down(1);
  // 800 x 600, 16 bit color, no depth, alpha or stencil buffers, windowed
  if (glfwOpenWindow(window_width, window_height, 5, 6, 5,
                  0, 0, 0, GLFW_WINDOW) != GL_TRUE)
    Shut_Down(1);
  glfwSetWindowTitle("The GLFW Window");
 
  glfwSetKeyCallback( OnKeyPressed );
  glfwSetCharCallback( OnCharPressed );
  glfwSetWindowCloseCallback(OnClose);
  glfwSetWindowSizeCallback(OnResize);
  glfwSetWindowRefreshCallback(OnRefresh);
  glfwSetMouseWheelCallback(OnMouseWheel);
  glfwSetMousePosCallback(OnMouseMove);
  glfwSetMouseButtonCallback(OnMouseClick);
  
  // set the projection matrix to a normal frustum with a max depth of 50
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  float aspect_ratio = ((float)window_height) / window_width;
  glFrustum(.5, -.5, -.5 * aspect_ratio, .5 * aspect_ratio, 1, 50);
  glMatrixMode(GL_MODELVIEW);
  
  PullInfo();
}
Esempio n. 3
0
	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();
	}
Esempio n. 4
0
void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window)
{
    glfwSetMouseButtonCallback(window, ImGui_ImplGlfw_MouseButtonCallback);
    glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback);
    glfwSetKeyCallback(window, ImGui_ImplGlfw_KeyCallback);
    glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback);
}
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);
}
Esempio n. 6
0
bool GameEngineC::loadGLFW(int width, int height) {
    if (!glfwInit()) {
        return false;
    }

    glfWwindow = glfwCreateWindow(width, height, "Test", NULL, NULL);
    if (glfWwindow) {
        glfwShowWindow(glfWwindow);

        glfwMakeContextCurrent(glfWwindow);

        glfwSetMouseButtonCallback(glfWwindow, mouseButtonCallback);
        glfwSetCursorPosCallback(glfWwindow, (GLFWcursorposfun) cursorPosCallback);
        glfwSetScrollCallback(glfWwindow, (GLFWscrollfun) scrollCallback);
        glfwSetKeyCallback(glfWwindow, (GLFWkeyfun) keyCallback);
        glfwSetCharCallback(glfWwindow, (GLFWcharfun) charCallback);
        glfwSetWindowSizeCallback(glfWwindow, (GLFWwindowsizefun) windowResize);

        if (onGLFWLoad) {
            onGLFWLoad();
        }
        return true;
    }
    return false;
}
Esempio n. 7
0
  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;
    }
  }
Esempio n. 8
0
File: main.cpp Progetto: riteme/test
int main() {
    glfwInit();

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

    GLFWwindow *window = glfwCreateWindow(800, 600, "LearnOpenGL", nullptr, nullptr);
    glfwSetCharCallback(window, character_callback);

    glfwMakeContextCurrent(window);
    if (window == NULL) {
        std::cout << "Failed to create GLFW window" << std::endl;
        glfwTerminate();
        return -1;
    }

    glfwShowWindow(window);

    glfwMakeContextCurrent(window);

    while (!glfwWindowShouldClose(window)) {
        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwDestroyWindow(window);

    glfwTerminate();
    return 0;
}  // function main
Esempio n. 9
0
GlfwAppWindow::GlfwAppWindow(const char *title, bool fullscreen, int width, int height)
{
	if (!glfwInit())
	{
		throw std::runtime_error("Failed to initialize OpenGL");
	}

	m_window = (glfwCreateWindow(
		fullscreen ? glfwGetVideoMode(glfwGetPrimaryMonitor())->width : width,
		fullscreen ? glfwGetVideoMode(glfwGetPrimaryMonitor())->height : height,
		title,
		fullscreen ? glfwGetPrimaryMonitor() : nullptr,
		nullptr));

	//m_clipboard.reset(new GlfwClipboard(*m_window));
	//m_input.reset(new GlfwInput(*m_window));
	m_render.reset(new RenderOpenGL());

	glfwSetMouseButtonCallback(m_window, GLFWProcessors::OnMouseButton);
	glfwSetCursorPosCallback(m_window, GLFWProcessors::OnCursorPos);
	glfwSetScrollCallback(m_window, GLFWProcessors::OnScroll);
	glfwSetKeyCallback(m_window, GLFWProcessors::OnKey);
	glfwSetCharCallback(m_window, GLFWProcessors::OnChar);
	glfwSetFramebufferSizeCallback(m_window, GLFWProcessors::OnFramebufferSize);


	glfwSetWindowSizeCallback(m_window, GLFWProcessors::OnFramebufferSize);
	glfwSetWindowCloseCallback(m_window, [](GLFWwindow* w) {});

	glfwMakeContextCurrent(m_window);
	glfwSwapInterval(1);	
}
Esempio n. 10
0
void VogueWindow::InitializeWindowContext(GLFWwindow* window)
{
	/* Window resize callback */
	glfwSetWindowSizeCallback(window, WindowResizeCallback);

	/* Window close message callback */
	glfwSetWindowCloseCallback(window, WindowCloseCallback);

	/* Input callbacks */
	glfwSetKeyCallback(window, KeyCallback);
	glfwSetCharCallback(window, CharacterCallback);
	glfwSetMouseButtonCallback(window, MouseButtonCallback);
	glfwSetScrollCallback(window, MouseScrollCallback);

	/* Center on screen */
	const GLFWvidmode* vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
	glfwGetWindowSize(window, &m_windowWidth, &m_windowHeight);
	glfwSetWindowPos(window, (vidmode->width - m_windowWidth) / 2, (vidmode->height - m_windowHeight) / 2);

	/* Make the window's context current */
	glfwMakeContextCurrent(window);
	glfwSwapInterval(m_pVogueSettings->m_vsync);

	/* Force resize */
	WindowResizeCallback(window, m_windowWidth, m_windowHeight);

	/* Show the window */
	glfwShowWindow(window);
}
Esempio n. 11
0
// entry point
int main(int argc, char *argv[])
{
    GLFWwindow* window;
    int width, height;

    if (!glfwInit()) {
        std::cout << "[GLFW] error: Failed to initialize GLFW" << std::endl;
        exit(EXIT_FAILURE);
    }

    glfwWindowHint(GLFW_DEPTH_BITS, 16);

    window = glfwCreateWindow(960, 540, "3dmap", NULL, NULL);
    if (!window) {
        std::cout << "[GLFW] error: Failed to open GLFW window" << std::endl;
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    // Set callback functions
    glfwSetFramebufferSizeCallback(window, reshape);
    glfwSetCharCallback(window, character);
    glfwSetMouseButtonCallback(window, mouse);
    glfwSetScrollCallback(window, scroll);
    glfwSetCursorPosCallback(window, cursor);
    glfwSetErrorCallback(error);

    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);

    GLenum err = glewInit();
    if (GLEW_OK != err) {
            // Problem: glewInit failed, something is seriously wrong
            std::cout << "[GLEW] error: glewInit failed: " << glewGetErrorString(err) << std::endl;
            exit(EXIT_FAILURE);
    }

    glfwGetFramebufferSize(window, &width, &height);

    _dispatcher = new Dispatcher(width, height);

    // Main loop
    while (!glfwWindowShouldClose(window)) {
        _dispatcher->renderScene();

        // Swap buffers
        glfwSwapBuffers(window);
        glfwPollEvents();

        _dispatcher->idle();
    }

    // Terminate GLFW
    glfwTerminate();

    delete _dispatcher;

    // Exit program
    exit(EXIT_SUCCESS);
}
Esempio n. 12
0
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);
}
Esempio n. 13
0
// OpenGL code based on http://open.gl tutorials
void InitGL()
{
	glfwSetErrorCallback(glfw_error_callback);

    if (!glfwInit())
        exit(1);

	//glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	//glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
	//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	//glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
	glfwWindowHint(GLFW_REFRESH_RATE, 60);
	glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
	window = glfwCreateWindow(1280, 720, "ImGui OpenGL example", nullptr, nullptr);
	glfwMakeContextCurrent(window);

	glfwSetKeyCallback(window, glfw_key_callback);
	glfwSetScrollCallback(window, glfw_scroll_callback);
	glfwSetCharCallback(window, glfw_char_callback);

	glewExperimental = GL_TRUE;
	glewInit();

	GLenum err = GL_NO_ERROR;
	err = glGetError(); IM_ASSERT(err == GL_NO_ERROR);
}
Esempio n. 14
0
GLFWwindow* initializeInterface(GLuint width, GLuint height){
    GLFWwindow* wind;
    glfwInit();
    // Set all the required options for GLFW
    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);

    // Create a GLFWwindow object that we can use for GLFW's functions
    wind = glfwCreateWindow(width, height, "Rubik's Cube Simulator", nullptr, nullptr);
    glfwMakeContextCurrent(wind);

    // Set the required callback functions
    glfwSetKeyCallback(wind, key_callback);

	glfwSetCharCallback(wind, text_callback);

    // Set this to true so GLEW knows to use a modern approach to retrieving function pointers and extensions
    glewExperimental = GL_TRUE;
    // Initialize GLEW to setup the OpenGL Function pointers
    glewInit();

    // Define the viewport dimensions
    glViewport(0, 0, width, height);

    glEnable(GL_DEPTH_TEST);

    return wind;
}
bool initGLFW()
{
	glfwSetErrorCallback(errorCB);
	if (!glfwInit())
		exit(EXIT_FAILURE);

	gpWindow = glfwCreateWindow(gWidth, gHeight, "Computer Graphics", NULL, NULL);
	if (!gpWindow){
		glfwTerminate();
		exit(EXIT_FAILURE);
	}

	const GLFWvidmode * vidMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
	glfwSetWindowPos(gpWindow, (vidMode->width - gWidth) >> 1, (vidMode->height - gHeight) >> 1);

	glfwMakeContextCurrent(gpWindow);

	glfwSetKeyCallback(gpWindow, keyInput);
	glfwSetWindowSizeCallback(gpWindow, reshape);
	glfwSetMouseButtonCallback(gpWindow, mouseButton);
	glfwSetCursorPosCallback(gpWindow, cursorPos);
	glfwSetCharCallback(gpWindow, charInput);

	return true;
}
void ShellSystemInterface::ToggleKeyboardMode(KeyboardMode nmode){
	keyboard_mode = nmode;
	if(inputRegistered){
		glfwSetCharCallback(NULL);
		glfwSetKeyCallback(NULL);
		registerKeyboardInput();
	}
}
Esempio n. 17
0
		void DebugLayer::init(graphics::Window* window)
		{
			m_window = window;

			ImGui_ImplGlfwGL3_Init(window->getGLFWwindow(), false);
			glfwSetCharCallback(m_window->getGLFWwindow(), ImGui_ImplGlfwGL3_CharCallback);
			glfwSetScrollCallback(window->getGLFWwindow(), ImGui_ImplGlfwGL3_ScrollCallback);
		}
Esempio n. 18
0
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);
}
Esempio n. 19
0
void Window::open() {
   // If this is the first window -> init GLFW
  if(s_eventReceiver.empty()) {
    if(!glfwInit()) {
      logError("[Window] GLFW initialization failed!");
      throw runtime_error("GLFW initialization failed");
    }
  }

  // set window hints
  if(m_version.first != 0) {
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, m_version.first);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, m_version.second);
  }
  glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
  glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

  // Create window
  m_window
      = glfwCreateWindow(m_size.x, m_size.y, m_title.c_str(), nullptr, nullptr);
  if(!m_window) {
    // if this is the first window, call glfwTerminate to clean up resources
    if(s_eventReceiver.empty()) {
      glfwTerminate();
    }

    // log error and throw
    logError("[Window] GLFW window creation failed");
    throw runtime_error("GLFW window creation failed");
  }

  // check attributes
  int major = glfwGetWindowAttrib(m_window, GLFW_CONTEXT_VERSION_MAJOR);
  int minor = glfwGetWindowAttrib(m_window, GLFW_CONTEXT_VERSION_MINOR);
  if(major != m_version.first || minor != m_version.second) {
    logWarning("[Window] Actual version <",
               major, ".", minor,
               "> differs from version hint <",
               m_version.first, ".", m_version.second,
               ">!");
  }

  // add to list of event receiving windows
  s_eventReceiver[m_window] = this;

  // prepare event callbacks
  glfwSetWindowSizeCallback(m_window, Window::resizeCallback);
  glfwSetKeyCallback(m_window, Window::keyCallback);
  glfwSetCharCallback(m_window, Window::charCallback);
  glfwSetMouseButtonCallback(m_window, Window::mouseButtonCallback);
  glfwSetCursorPosCallback(m_window, Window::mousePosCallback);
  glfwSetScrollCallback(m_window, Window::mouseScrollCallback);

  glfwSetWindowCloseCallback(m_window, Window::windowCloseCallback);

  log("[Window] Opened new GLFW window: Success! (Handle: ", m_window, ")");
}
Esempio n. 20
0
int main(int argc, char** argv) {
    int running = GL_TRUE;
    // Initialize GLFW
    if (!glfwInit()) {
        exit(EXIT_FAILURE);
    }

    glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
    //    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
    //    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 1);
    //        glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL

    // Open an OpenGL window
    if (!glfwOpenWindow(1280, 720, 0, 0, 0, 0, 32, 0, GLFW_WINDOW)) {
        glfwTerminate();
        return EXIT_FAILURE;
    }

    glfwSetWindowTitle("Capivara-GL Test");

    //    glEnable(GL_LINE_SMOOTH);
    //    glEnable(GL_BLEND);
    //    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //    glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
    //    glLineWidth(1.5f);

    glfwEnable(GLFW_KEY_REPEAT);
    glfwEnable(GLFW_STICKY_KEYS);

    glEnable(GL_MULTISAMPLE);
    glDisable(GL_DEPTH_TEST);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    initComponents();
    glfwSetKeyCallback(keyCallback);
    glfwSetCharCallback(charCallback);
    glfwSetWindowRefreshCallback(display);
    glfwSetWindowSizeCallback(reshape);
    glfwSetMousePosCallback(mousePosition);
    glfwSetMouseButtonCallback(mouseButton);
    //-------------------------------------------------------------------------
    // Main loop
    while (running) {
        display();
        glfwSwapBuffers();

        running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
    }
    deleteComponents();

    // Close window and terminate GLFW
    glfwTerminate();
    return EXIT_SUCCESS;
}
Esempio n. 21
0
	void Keyboard::Init()
	{
		if (!g_keyboard)
			g_keyboard = this;

		GLFWwindow* window = GetApp()->GetWindow()->GetGLFWWindow();
		glfwSetKeyCallback(window, key_callback);
		glfwSetCharCallback(window, char_callback);
	}
Esempio n. 22
0
	void Window::SetCallbacks() const
	{
		glfwSetKeyCallback( this->handle, this->OnKey );
		glfwSetMouseButtonCallback( this->handle, this->OnMouse );
		glfwSetScrollCallback( this->handle, this->OnScroll );
		glfwSetCharCallback( this->handle, this->OnChar );
		glfwSetCursorPosCallback( this->handle, this->OnMousePos );
		glfwSetWindowFocusCallback( this->handle, this->OnFocus );
	}
void ShellSystemInterface::UnRegisterInputDevices(){
	glfwSetCharCallback(NULL);
	glfwSetKeyCallback(NULL);
	
	glfwSetMousePosCallback(NULL);
	glfwSetMouseButtonCallback(NULL);
	glfwSetMouseWheelCallback(NULL);
	inputRegistered = false;
}
void ShellSystemInterface::registerKeyboardInput(){
	if(!uiHandle.get()){
		std::cerr << "Warning, unsafe to activate event listening without at least";
		std::cerr << " one Rocket::Core::Context attached to ShellSystemInterface." << std::endl;
	}
	switch(keyboard_mode){
		case Text:
			glfwSetCharCallback(&HandleCharToggle); break;
		case Keys:
			glfwSetKeyCallback(&HandleKeyToggle); break;
		case Text_And_Keys:
			glfwSetCharCallback(&HandleCharToggle);
			glfwSetKeyCallback(&HandleKeyToggle);
			break;
		default:
			std::cerr << "Error: Reached evil state in ShellSystemInterface::RegisterInputDevices()" << std::endl;
	}
}
Esempio n. 25
0
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);
    }
}
Esempio n. 26
0
bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float frameZoomFactor, bool resizable)
{
    setViewName(viewName);

    _frameZoomFactor = frameZoomFactor;
    _resizable = resizable;

    glfwWindowHint(GLFW_RESIZABLE, resizable ? GL_TRUE : GL_FALSE);
    
    glfwWindowHint(GLFW_RED_BITS,_glContextAttrs.redBits);
    glfwWindowHint(GLFW_GREEN_BITS,_glContextAttrs.greenBits);
    glfwWindowHint(GLFW_BLUE_BITS,_glContextAttrs.blueBits);
    glfwWindowHint(GLFW_ALPHA_BITS,_glContextAttrs.alphaBits);
    glfwWindowHint(GLFW_DEPTH_BITS,_glContextAttrs.depthBits);
    glfwWindowHint(GLFW_STENCIL_BITS,_glContextAttrs.stencilBits);

    _mainWindow = glfwCreateWindow(rect.size.width * _frameZoomFactor,
                                   rect.size.height * _frameZoomFactor,
                                   _viewName.c_str(),
                                   _monitor,
                                   nullptr);
    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);

    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;
}
Esempio n. 27
0
void sendInputToOverlay()
{
	// Set GLFW event callbacks. I removed glfwSetWindowSizeCallback for conciseness
	glfwSetMouseButtonCallback(appWindow, myTwEventMouseButtonGLFW); // - Directly redirect GLFW mouse button events to AntTweakBar
	glfwSetCursorPosCallback(appWindow, myTwEventMousePosGLFW); // - Directly redirect GLFW mouse position events to AntTweakBar
	glfwSetScrollCallback(appWindow, myTwEventMouseWheelGLFW); // - Directly redirect GLFW mouse wheel events to AntTweakBar
	glfwSetKeyCallback(appWindow, myTwEventKeyGLFW); // - Directly redirect GLFW key events to AntTweakBar
	glfwSetCharCallback(appWindow, myTwEventCharGLFW); // - Directly redirect GLFW char events to AntTweakBar
	glfwSetInputMode(appWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}
Esempio n. 28
0
void setupCallbacks(){
    glfwSetWindowSizeCallback( GLFWWindowSizeCb );
    glfwSetWindowCloseCallback( GLFWWindowCloseCb );
    glfwSetWindowRefreshCallback( GLFWWindowRefreshCb );
    glfwSetKeyCallback( GLFWKeyCb );
    glfwSetCharCallback( GLFWMousePosCb );
    glfwSetMouseButtonCallback( GLFWMouseButtonCb );
    glfwSetMousePosCallback( GLFWMousePosCb );
    glfwSetMouseWheelCallback( GLFWMouseWheelCb );
};
Esempio n. 29
0
Interface::~Interface()
{
    glfwSetKeyCallback         (window, nullptr);
    glfwSetCharCallback        (window, nullptr);
    glfwSetMouseButtonCallback (window, nullptr);
    glfwSetCursorPosCallback   (window, nullptr);
    glfwSetScrollCallback      (window, nullptr);

    windowMap.erase(windowMap.find(window));
}
Esempio n. 30
0
void Window::setEventsCallbacks()
{
    glfwSetKeyCallback(_window->get(), Window::keyCallback);
    glfwSetCharCallback(_window->get(), Window::charCallback);
    glfwSetMouseButtonCallback(_window->get(), Window::mouseBtnCallback);
    glfwSetCursorPosCallback(_window->get(), Window::mousePosCallback);
    glfwSetScrollCallback(_window->get(), Window::scrollCallback);
    glfwSetDropCallback(_window->get(), Window::pathdropCallback);
    glfwSetWindowCloseCallback(_window->get(), Window::closeCallback);
}