Example #1
1
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;
	
}
Example #2
0
int			sp_init_glfw(t_env *e)
{
	glfwSetErrorCallback(error_callback);
	glfwInit();
	glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
	glfwWindowHint(GLFW_SAMPLES, 2);
#ifdef MAC_OS_MODE
		glfwWindowHint(GLFW_DOUBLEBUFFER, GL_TRUE);
#endif
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
	glfwWindowHint(GLFW_OPENGL_PROFILE, OPENGL_PROFILE);
	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
	e->win = glfwCreateWindow(WIN_WIDTHI, WIN_HEIGHTI, "Scop", NULL, NULL);
	if (!e->win)
	{
		glfwTerminate();
		return (ERROR("glfwCreateWindow"));
	}
#ifndef MAC_OS_MODE
	glfwSetWindowPos(e->win, 1000, 0);
#endif
	glfwSetWindowFocusCallback(e->win, &focus_callback);
	glfwSetKeyCallback(e->win, key_callback);
	glfwMakeContextCurrent(e->win);
	if (!INIT_GLEW)
		return (ERROR("glewInit()"));
	glViewport(0, 0, WIN_WIDTHI, WIN_HEIGHTI);
	glEnable(GL_DEPTH_TEST);
	return (0);
}
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);
}
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);
}
	bool WindowGL33::removeFocusCallback(FocusEventType::DelegatePtr const& callback)
	{
		bool ret = m_focusCallbacks.removeListener(callback);
		if (!m_focusCallbacks.hasListener())
			glfwSetWindowFocusCallback(m_pWndHandle, NULL);
		return ret;
	}
Example #6
0
int main(void)
{
    GLFWwindow* window;

    glfwSetErrorCallback(error_callback);

    if (!glfwInit())
        exit(EXIT_FAILURE);

    window = glfwCreateWindow(640, 480, "Fullscreen focus", glfwGetPrimaryMonitor(), NULL);
    if (!window)
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);

    glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);

    glfwSetWindowFocusCallback(window, window_focus_callback);
    glfwSetKeyCallback(window, window_key_callback);

    while (!glfwWindowShouldClose(window))
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glfwSwapBuffers(window);
        glfwWaitEvents();
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
Example #7
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);
}
Example #8
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 );
	}
Example #9
0
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
Window_Imp_Win::Window_Imp_Win(GLFWwindow* window, int32_t width, int32_t height, Log* logger, bool isFullScreen)
	: Window_Imp(logger)
	, m_window(window)
	, m_closed(false)
{
	m_size.X = width;
	m_size.Y = height;
	glfwSetWindowUserPointer(window, this);
	glfwSetWindowFocusCallback(window, CallbackOnFocus);
}
Example #10
0
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 veViewerDesktop::destroy()
{
    if (!_hwnd) return;
    glfwSetKeyCallback(_hwnd, nullptr);
    glfwSetCharCallback(_hwnd, nullptr);
    glfwSetMouseButtonCallback(_hwnd, nullptr);
    glfwSetCursorPosCallback(_hwnd, nullptr);
    glfwSetScrollCallback(_hwnd, nullptr);
    glfwSetWindowSizeCallback(_hwnd, nullptr);
    glfwSetWindowFocusCallback(_hwnd, nullptr);
    glfwSetWindowCloseCallback(_hwnd, nullptr);
    
    glfwDestroyWindow(_hwnd);
    _hwnd = nullptr;
}
Example #12
0
int vxl::_CreateWindow() {
	if (!glfwInit()) {
		std::cerr << "GLFW failed to initialize!" << std::endl;
		return -1;
	}
	// make this window use OpenGL 3.2
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
	// use the core profile so that we can have all of the goodness
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	// make sure we can use new features if needed
	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
	// make this a resizable window
	glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
	this->m_window = glfwCreateWindow(m_width, m_height, m_title.c_str(), NULL, NULL);
	if (!m_window) {
		std::cerr << "GLFW failed to create a window!" << std::endl;
		return -2;
	}
	// set the framebuffer resize callback
	glfwSetFramebufferSizeCallback(m_window, glfw_resize_callback);
	// set the key down callback
	glfwSetKeyCallback(m_window, glfw_on_key_down);
	// set the focus callback
	glfwSetWindowFocusCallback(m_window, glfw_on_window_focus);
	// set the user pointer to this instance
	// allows for us to call our class methods in the callbacks
	glfwSetWindowUserPointer(m_window, this);
	glfwMakeContextCurrent(m_window);
	glewExperimental = true;
	GLenum err = glewInit();
	if (GLEW_OK != err) {
		std::cerr << "GLEW failed to initialize!" << std::endl;
		return -3;
	}
	// enable some things for correct rendering
	_EnableGL();
	// get the main monitor video mode
	const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
	// set the glfw window to the center of the screen
	glfwSetWindowPos(m_window, (mode->width / 2) - (m_width / 2), (mode->height) / 2 - (m_height / 2));
	// set the glfw cursor to hidden
	glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
	glfwSwapInterval(1);
	return 0;
}
Example #13
0
void end()
{
    // FIXME: old-BATB specific shutdown

    // remove key callbacks
    GLFWwindow* win = glfwGetCurrentContext();
    glfwSetKeyCallback( win, 0  );                  //glutKeyboardFunc      (MainWindow::keyDownFn); 
    glfwSetCursorPosCallback( win, 0 );       //glutMouseFunc         (MainWindow::mousefn); 
    glfwSetMouseButtonCallback( win, 0 );    //glutMotionFunc        (MainWindow::motionfn);
    glfwSetWindowSizeCallback( win, 0 );     //glutReshapeFunc       (MainWindow::reshapefn);
    glfwSetWindowFocusCallback( win, 0 );   //glutVisibilityFunc    (MainWindow::visibility);

    // do some clean up
    mainWindow.exit();

    reset_gl();

}
Example #14
0
	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));
	}
Example #15
0
File: main.cpp Project: Kingwl/ray
    void init(std::size_t w, std::size_t h)
    {
		glfwInit();

		_window = glfwCreateWindow(w, h, "UI", nullptr, nullptr);
		if (_window)
		{
			glfwSetWindowUserPointer(_window, this);
			glfwSetWindowFocusCallback(_window, &setWindowFocusCallback);
			glfwSetWindowCloseCallback(_window, &setWindowCloseCallback);

			HWND hwnd = glfwGetWin32Window(_window);

			if (!this->open(hwnd, w, h))
				throw ray::failure("App::open() fail");

			if (!this->openScene("dlc:UI\\scene.map"))
				throw ray::failure("App::openScene('dlc:UI\\scene.map') fail");
		}
    }
void veViewerDesktop::create()
{
    if (_hwnd) return;
    _hwnd = glfwCreateWindow(_width, _height, _title.c_str(), nullptr, _sharedViewer? _sharedViewer->_hwnd: nullptr);
    
    glfwSetWindowUserPointer(_hwnd, this);
    glfwSetKeyCallback(_hwnd, collectKeyEvent);
    glfwSetCharCallback(_hwnd, collectCharEvent);
    glfwSetMouseButtonCallback(_hwnd, collectMouseEvent);
    glfwSetCursorPosCallback(_hwnd, collectMouseMoveEvent);
    glfwSetScrollCallback(_hwnd, collectScrollEvent);
    glfwSetWindowSizeCallback(_hwnd, collectWindowSizeEvent);
    glfwSetWindowFocusCallback(_hwnd, collectWindowFocusEvent);
    glfwSetWindowCloseCallback(_hwnd, collectWindowClose);
    
    _currentEvent.setEventType(veEvent::VE_WIN_INIT);
    _currentEvent.setWindowWidth(_width);
    _currentEvent.setWindowHeight(_height);
    _eventList.push_back(_currentEvent);
}
Example #17
0
void shovelerInputFree(ShovelerInput *input)
{
	glfwSetInputMode(input->game->window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
	glfwSetInputMode(input->game->window, GLFW_STICKY_KEYS, GL_FALSE);
	glfwSetInputMode(input->game->window, GLFW_STICKY_MOUSE_BUTTONS, GL_FALSE);

	glfwSetKeyCallback(input->game->window, NULL);
	glfwSetMouseButtonCallback(input->game->window, NULL);
	glfwSetCursorPosCallback(input->game->window, NULL);
	glfwSetScrollCallback(input->game->window, NULL);
	glfwSetWindowSizeCallback(input->game->window, NULL);
	glfwSetWindowFocusCallback(input->game->window, NULL);

	g_hash_table_destroy(input->keyCallbacks);
	g_hash_table_destroy(input->mouseButtonCallbacks);
	g_hash_table_destroy(input->cursorPositionCallbacks);
	g_hash_table_destroy(input->scrollCallbacks);
	g_hash_table_destroy(input->windowSizeCallbacks);
	free(input);
}
Example #18
0
ShovelerInput *shovelerInputCreate(ShovelerGame *game)
{
	ShovelerInput *input = malloc(sizeof(ShovelerInput));
	input->game = game;
	input->keyCallbacks = g_hash_table_new_full(g_direct_hash, g_direct_equal, freeKeyCallback, NULL);
	input->mouseButtonCallbacks = g_hash_table_new_full(g_direct_hash, g_direct_equal, freeMouseButtonCallback, NULL);
	input->cursorPositionCallbacks = g_hash_table_new_full(g_direct_hash, g_direct_equal, freeCursorPositionCallback, NULL);
	input->scrollCallbacks = g_hash_table_new_full(g_direct_hash, g_direct_equal, freeScrollCallback, NULL);
	input->windowSizeCallbacks = g_hash_table_new_full(g_direct_hash, g_direct_equal, freeWindowSizeCallback, NULL);

	glfwSetInputMode(game->window, GLFW_STICKY_KEYS, GL_TRUE);
	glfwSetInputMode(game->window, GLFW_STICKY_MOUSE_BUTTONS, GL_TRUE);

	glfwSetKeyCallback(game->window, keyHandler);
	glfwSetMouseButtonCallback(game->window, mouseButtonHandler);
	glfwSetCursorPosCallback(game->window, cursorPosHandler);
	glfwSetScrollCallback(game->window, scrollHandler);
	glfwSetWindowSizeCallback(game->window, windowSizeHandler);
	glfwSetWindowFocusCallback(game->window, windowFocusHandler);

	return input;
}
Example #19
0
	Window::Window(const char* title, int width, int height) : width(width), height(height)
	{
		if (!glfwInit())
		{
			printf("glfw init failed!\n");
			throw std::exception();
		}

		glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
		glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
		glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
		glfwWindowHint(GLFW_SAMPLES, 4);

		window = glfwCreateWindow(width, height, title, nullptr, nullptr);

		if (!window)
		{
			glfwTerminate();
			printf("glfw failed to create a window!\n");
			throw std::exception();
		}

		glfwMakeContextCurrent(window);

		glfwSetWindowSizeCallback(window, onWindowResize);
		glfwSetScrollCallback(window, onWindowMouseWheel);
		glfwSetMouseButtonCallback(window, onWindowMouseButton);
		glfwSetCursorPosCallback(window, onWindowMouseMove);
		glfwSetKeyCallback(window, onWindowKeyboard);
		glfwSetWindowFocusCallback(window, onWindowFocus);

		if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
		{
			printf("glad faild to init!\n");
			throw std::exception();
		}

		instance = this;
	}
Example #20
0
    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);

    }
Example #21
0
void Window::init(int w, int h, bool fs)
{
	if(!s_window)
	{
		// Create window
		s_window = glfwCreateWindow(w, h, WINDOW_TITLE, fs ? glfwGetPrimaryMonitor() : NULL, NULL);
	}
	else
	{
		// Change fullscreen mode
		GLFWwindow *window = glfwCreateWindow(w, h, WINDOW_TITLE, fs ? glfwGetPrimaryMonitor() : NULL, s_window);
		glfwDestroyWindow(s_window);
		s_window = window;
		s_graphicsContext->resizeViewport(w, h);
	}

	if(!s_window)
	{
		glfwTerminate();
		assert("Window could not initialize");
	}

	// Set callbacks
	glfwSetFramebufferSizeCallback(s_window, sizeChanged);
	glfwSetWindowFocusCallback(s_window, focusChanged);
	glfwSetKeyCallback(s_window, keyCallback);
	glfwSetCharCallback(s_window, charCallback);
	glfwSetMouseButtonCallback(s_window, mouseButtonCallback);
	glfwSetCursorPosCallback(s_window, cursorMoveCallback);
	glfwSetScrollCallback(s_window, scrollCallback);

	glfwMakeContextCurrent(s_window);
	Graphics::setVsync(1);
	glfwShowWindow(s_window);

	s_fullScreen = fs;
	s_focus = true;
}
Example #22
0
int main(void)
{
    GLFWwindow window;

    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    window = glfwCreateWindow(640, 480, GLFW_FULLSCREEN, "Fullscreen focus", NULL);
    if (!window)
    {
        glfwTerminate();

        fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);

    glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);

    glfwSetWindowFocusCallback(window_focus_callback);
    glfwSetKeyCallback(window_key_callback);
    glfwSetWindowCloseCallback(window_close_callback);

    while (running)
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glfwSwapBuffers(window);
        glfwWaitEvents();
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
	void* CommonWindowImpl::create(const WindowSettings& settings)
	{
		ensureGLFWInit();

		GLFWwindow* wndwHandle;

		glfwWindowHint(GLFW_ALPHA_BITS, settings.useBlending ? 8 : 0);
		glfwWindowHint(GLFW_DEPTH_BITS, settings.useDepthBuffer ? 16 : 0);
		glfwWindowHint(GLFW_STENCIL_BITS, settings.useStencilBuffer ? 8 : 0);
		glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
		glfwWindowHint(GLFW_SAMPLES, settings.antialiasingSamples);
        
		int majorVer = settings.contextVersionMajor == 0 ? 4 : settings.contextVersionMajor,
			minorVer = settings.contextVersionMajor == 0 ? 4 : settings.contextVersionMinor;

		do
		{
			glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, majorVer);
			glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minorVer);

			wndwHandle = glfwCreateWindow(
				(int)settings.size.x,
				(int)settings.size.y,
				settings.title.c_str(),
				settings.fullScreen ? glfwGetPrimaryMonitor() : nullptr,
				nullptr
				);

			if (--minorVer < 0)
			{
				--majorVer;
				minorVer = 9;
			}

		} while (!wndwHandle && majorVer > 0);

		if (!wndwHandle)
		{
			std::cout << "Failed to create an OpenGL context! Exiting..." <<std::endl;
			std::exit(EXIT_FAILURE);
		}

		++windowRefs;
		glfwMakeContextCurrent(wndwHandle);

		glfwSetWindowPos(wndwHandle, (int)settings.position.x, (int)settings.position.y);
		glfwSwapInterval(settings.useVsync ? 1 : 0);

        if (ns_resizeFunc)
        {
            glfwSetWindowSizeCallback(wndwHandle, [](GLFWwindow*, int x, int y)
            {
                ns_resizeFunc(x, y);
            });
        }
        
		glewExperimental = GL_TRUE;

		/////////////////////////////
		CheckGLError("before glewInit");
		glewInit();
		GLenum errCode = glGetError();
		if (errCode != GL_INVALID_ENUM && errCode != GL_NO_ERROR)
		{
			WriteError("Window creation failed!!! D:");
			assert(false);
		}

		//std::cout << "glew init might produce GL_INVALID_ENUM error. Just ignore it" << std::endl;
		//oglCheck(glewInit());
		////////////////////////////

		if(majorVer >= 3)
		{
			GLuint vertexArray;
			glGenVertexArrays(1, &vertexArray);
			glBindVertexArray(vertexArray);
		}

		glfwSetWindowFocusCallback(wndwHandle, FocusCallback);

		return static_cast<void*>(wndwHandle);
	}
Example #24
0
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);
}
Example #25
0
SimpleApp::SimpleFrameListener::SimpleFrameListener(SimpleApp *app)
{
	this->app = app;
	glfwSetWindowFocusCallback(app->glfwWindow, GLFWFrameListener::GLFWWindwoFocusCB);
}
Example #26
0
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));
}
Example #27
0
// program entry
int32_t main(int32_t argc, char *argv[])
{
    GLFWwindow* window;
    int32_t width, height;

    NvAssetLoaderInit(NULL);

    sWindowIsFocused = true;
    sForcedRenderCount = 0;

    if( !glfwInit() )
    {
        fprintf( stderr, "Failed to initialize GLFW\n" );
        exit( EXIT_FAILURE );
    }

    glfwSetErrorCallback(glfwError);

    NvLinuxPlatformContext* platform = new NvLinuxPlatformContext;

    // add command line arguments
    for (int i = 1; i < argc; i++) {
        platform->m_commandLine.push_back(argv[i]);
    }

    sApp = NvAppFactory(platform);

    NvEGLConfiguration config(NvGfxAPIVersionGL4(), 8, 8, 8, 8, 16, 0);
    sApp->configurationCallback(config);

    // Does not seem to work...
/*
    if (config.api == GLAppContext::Configuration::API_ES)
        glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
    
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, config.majVer);
    //glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
    */

    NvGLLinuxAppContext* context = new NvGLLinuxAppContext(config);

    window = glfwCreateWindow( 1280, 720, "Linux SDK Application", NULL, NULL );
    if (!window)
    {
        fprintf( stderr, "Failed to open GLFW window\n" );
        glfwTerminate();
        exit( EXIT_FAILURE );
    }

    platform->setWindow(window);

    context->setWindow(window);
    sApp->setGLContext(context);

    // Set callback functions
    glfwSetFramebufferSizeCallback(window, reshape);
    glfwSetWindowFocusCallback(window, focus);
    setInputCallbacksGLFW(window);

    context->bindContext();
    glfwSwapInterval( 1 );

    glfwGetFramebufferSize(window, &width, &height);

    int32_t major = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
    int32_t minor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR);
    config.apiVer = NvGfxAPIVersion(NvGfxAPI::GL, major, minor);

    glGetIntegerv(GL_RED_BITS, (GLint*)&config.redBits);
    glGetIntegerv(GL_GREEN_BITS, (GLint*)&config.greenBits);
    glGetIntegerv(GL_BLUE_BITS, (GLint*)&config.blueBits);
    glGetIntegerv(GL_ALPHA_BITS, (GLint*)&config.alphaBits);
    glGetIntegerv(GL_DEPTH_BITS, (GLint*)&config.depthBits);
    glGetIntegerv(GL_STENCIL_BITS, (GLint*)&config.stencilBits);

    context->setConfiguration(config);

#if 1
    // get extensions (need for ES2.0)
    GLenum err = glewInit();
    if (GLEW_OK != err)
    {
      /* Problem: glewInit failed, something is seriously wrong. */
      fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
      exit(-1);
    }
    fprintf(stdout, "Using GLEW %s\n", glewGetString(GLEW_VERSION));
#endif

    // Parse command-line options
    initGL(argc, argv);

    reshape(window, width, height);

    sApp->mainLoop();

    // Shut down the app before shutting down GL
    delete sApp;

    // Terminate GLFW
    glfwTerminate();

    NvAssetLoaderShutdown();

    // Exit program
    exit( EXIT_SUCCESS );
}
Example #28
0
int main(int argc, char** argv)
{
    int width, height, ch;
    GLFWmonitor* monitor = NULL;
    GLFWwindow* window;

    glfwSetErrorCallback(error_callback);

    if (!glfwInit())
        exit(EXIT_FAILURE);

    while ((ch = getopt(argc, argv, "fh")) != -1)
    {
        switch (ch)
        {
            case 'h':
                usage();
                exit(EXIT_SUCCESS);

            case 'f':
                monitor = glfwGetPrimaryMonitor();
                break;

            default:
                usage();
                exit(EXIT_FAILURE);
        }
    }

    if (monitor)
    {
        GLFWvidmode mode = glfwGetVideoMode(monitor);
        width = mode.width;
        height = mode.height;
    }
    else
    {
        width = 640;
        height = 480;
    }

    window = glfwCreateWindow(width, height, "Iconify", monitor, NULL);
    if (!window)
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);

    glfwSetKeyCallback(window, key_callback);
    glfwSetWindowSizeCallback(window, window_size_callback);
    glfwSetWindowFocusCallback(window, window_focus_callback);
    glfwSetWindowIconifyCallback(window, window_iconify_callback);

    printf("Window is %s and %s\n",
           glfwGetWindowParam(window, GLFW_ICONIFIED) ? "iconified" : "restored",
           glfwGetWindowParam(window, GLFW_FOCUSED) ? "focused" : "defocused");

    glEnable(GL_SCISSOR_TEST);

    while (!glfwWindowShouldClose(window))
    {
        glfwGetWindowSize(window, &width, &height);

        glScissor(0, 0, width, height);
        glClearColor(0, 0, 0, 0);
        glClear(GL_COLOR_BUFFER_BIT);

        glScissor(0, 0, 640, 480);
        glClearColor(1, 1, 1, 0);
        glClear(GL_COLOR_BUFFER_BIT);

        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
Example #29
0
File: iconify.c Project: 2php/glfw
int main(int argc, char** argv)
{
    int ch, i, window_count;
    int auto_iconify = GLFW_TRUE, fullscreen = GLFW_FALSE, all_monitors = GLFW_FALSE;
    GLFWwindow** windows;

    while ((ch = getopt(argc, argv, "afhn")) != -1)
    {
        switch (ch)
        {
            case 'a':
                all_monitors = GLFW_TRUE;
                break;

            case 'h':
                usage();
                exit(EXIT_SUCCESS);

            case 'f':
                fullscreen = GLFW_TRUE;
                break;

            case 'n':
                auto_iconify = GLFW_FALSE;
                break;

            default:
                usage();
                exit(EXIT_FAILURE);
        }
    }

    glfwSetErrorCallback(error_callback);

    if (!glfwInit())
        exit(EXIT_FAILURE);

    glfwWindowHint(GLFW_AUTO_ICONIFY, auto_iconify);

    if (fullscreen && all_monitors)
    {
        int monitor_count;
        GLFWmonitor** monitors = glfwGetMonitors(&monitor_count);

        window_count = monitor_count;
        windows = calloc(window_count, sizeof(GLFWwindow*));

        for (i = 0;  i < monitor_count;  i++)
        {
            windows[i] = create_window(monitors[i]);
            if (!windows[i])
                break;
        }
    }
    else
    {
        GLFWmonitor* monitor = NULL;

        if (fullscreen)
            monitor = glfwGetPrimaryMonitor();

        window_count = 1;
        windows = calloc(window_count, sizeof(GLFWwindow*));
        windows[0] = create_window(monitor);
    }

    for (i = 0;  i < window_count;  i++)
    {
        glfwSetKeyCallback(windows[i], key_callback);
        glfwSetFramebufferSizeCallback(windows[i], framebuffer_size_callback);
        glfwSetWindowSizeCallback(windows[i], window_size_callback);
        glfwSetWindowFocusCallback(windows[i], window_focus_callback);
        glfwSetWindowIconifyCallback(windows[i], window_iconify_callback);
        glfwSetWindowRefreshCallback(windows[i], window_refresh_callback);

        window_refresh_callback(windows[i]);

        printf("Window is %s and %s\n",
            glfwGetWindowAttrib(windows[i], GLFW_ICONIFIED) ? "iconified" : "restored",
            glfwGetWindowAttrib(windows[i], GLFW_FOCUSED) ? "focused" : "defocused");
    }

    for (;;)
    {
        glfwWaitEvents();

        for (i = 0;  i < window_count;  i++)
        {
            if (glfwWindowShouldClose(windows[i]))
                break;
        }

        if (i < window_count)
            break;

        // Workaround for an issue with msvcrt and mintty
        fflush(stdout);
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
Example #30
0
int main(int argc, char* argv[]) {
    if (argv[0] != NULL) {
        std::string progDirectory(argv[0]);
        std::cout << "Program directory: " << progDirectory << std::endl;
        progDirectory = progDirectory.substr(0, progDirectory.find_last_of("/") + 1);
        Utility::programDirectory = progDirectory;
    }

    GLFWwindow* window;
    windowWidth = 640;
    windowHeight = 480;

    glfwSetErrorCallback(error_callback);
    
    if (!glfwInit())
        exit(EXIT_FAILURE);

    setCoreProfile();

    window = glfwCreateWindow(windowWidth, windowHeight, "Voxel Constructor", NULL, NULL);
    if (!window) {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    glfwMakeContextCurrent(window);

    std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;

    glfwSetKeyCallback(window, key_callback);
    glfwSetMouseButtonCallback(window, mouseButton_callback);
    glfwSetCursorPosCallback(window, cursorPos_callback);
    glfwSetWindowSizeCallback(window, window_size_callback);
    glfwSetWindowFocusCallback(window, focus_callback);
    glfwSetCharCallback(window, char_callback);


    double previousFrameTime = glfwGetTime();
    double frameTime = glfwGetTime();
    double delta = 0.0;

    struct timespec timeSleep;
    timeSleep.tv_sec = 0;
    timeSleep.tv_nsec = 33333333;

    state = new State();

    mouseButton_callback(window, GLFW_MOUSE_BUTTON_LEFT, 0, 0); // Ensure mouse button is released upon starting

    double secondCounter = 0.0;
    int frames = 0;

    while (!glfwWindowShouldClose(window)) {
        frameTime = glfwGetTime();
        delta = frameTime - previousFrameTime;
        if (paused) {
            nanosleep(&timeSleep, NULL);
        } else {
            state->update(delta);
            //pollKeys(state, window, delta);
        }
        state->display(window);
        glfwPollEvents();
        previousFrameTime = frameTime;
        state->setCursorPosition(cursorX, cursorY);
        frames++;
        secondCounter += delta;
        if (secondCounter > 1.0) {
            secondCounter = 0.0;
            // std::cout << "FPS: " << frames << std::endl;
            frames = 0;
        }
    }

    glfwDestroyWindow(window);

    glfwTerminate();
    exit(EXIT_SUCCESS);
}