Example #1
0
File: input.c Project: eledot/Plum
GLFWAPI int glfwGetKey(GLFWwindow handle, int key)
{
    _GLFWwindow* window = (_GLFWwindow*) handle;

    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return GLFW_RELEASE;
    }

    if (key < 0 || key > GLFW_KEY_LAST)
    {
        _glfwSetError(GLFW_INVALID_ENUM,
                      "The specified key is invalid");
        return GLFW_RELEASE;
    }

    if (window->key[key] == GLFW_STICK)
    {
        // Sticky mode: release key now
        window->key[key] = GLFW_RELEASE;
        return GLFW_PRESS;
    }

    return (int) window->key[key];
}
Example #2
0
File: input.c Project: eledot/Plum
GLFWAPI int glfwGetMouseButton(GLFWwindow handle, int button)
{
    _GLFWwindow* window = (_GLFWwindow*) handle;

    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return GLFW_RELEASE;
    }

    if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
    {
        _glfwSetError(GLFW_INVALID_ENUM,
                      "The specified mouse button is invalid");
        return GLFW_RELEASE;
    }

    if (window->mouseButton[button] == GLFW_STICK)
    {
        // Sticky mode: release mouse button now
        window->mouseButton[button] = GLFW_RELEASE;
        return GLFW_PRESS;
    }

    return (int) window->mouseButton[button];
}
Example #3
0
GLFWAPI int glfwGetJoystickAxes(int joy, float* axes, int numaxes)
{
    int i;

    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return 0;
    }

    if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
    {
        _glfwSetError(GLFW_INVALID_ENUM, NULL);
        return 0;
    }

    if (axes == NULL || numaxes < 0)
    {
        _glfwSetError(GLFW_INVALID_VALUE, NULL);
        return 0;
    }

    // Clear positions
    for (i = 0;  i < numaxes;  i++)
        axes[i] = 0.0f;

    return _glfwPlatformGetJoystickAxes(joy, axes, numaxes);
}
Example #4
0
GLFWAPI void glfwSetMousePos(GLFWwindow handle, int xpos, int ypos)
{
    _GLFWwindow* window = (_GLFWwindow*) handle;

    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return;
    }

    if (_glfwLibrary.activeWindow != window)
    {
        _glfwSetError(GLFW_WINDOW_NOT_ACTIVE, NULL);
        return;
    }

    // Don't do anything if the mouse position did not change
    if (xpos == window->cursorPosX && ypos == window->cursorPosY)
        return;

    // Set GLFW mouse position
    window->cursorPosX = xpos;
    window->cursorPosY = ypos;

    // Do not move physical cursor in locked cursor mode
    if (window->cursorMode == GLFW_CURSOR_CAPTURED)
        return;

    // Update physical cursor position
    _glfwPlatformSetMouseCursorPos(window, xpos, ypos);
}
Example #5
0
GLFWAPI int glfwGetJoystickButtons(int joy,
                                   unsigned char* buttons,
                                   int numbuttons)
{
    int i;

    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return 0;
    }

    if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
    {
        _glfwSetError(GLFW_INVALID_ENUM, NULL);
        return 0;
    }

    if (buttons == NULL || numbuttons < 0)
    {
        _glfwSetError(GLFW_INVALID_VALUE, NULL);
        return 0;
    }

    // Clear button states
    for (i = 0;  i < numbuttons;  i++)
        buttons[i] = GLFW_RELEASE;

    return _glfwPlatformGetJoystickButtons(joy, buttons, numbuttons);
}
Example #6
0
GLFWAPI int glfwGetInputMode(GLFWwindow handle, int mode)
{
    _GLFWwindow* window = (_GLFWwindow*) handle;

    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return 0;
    }

    switch (mode)
    {
        case GLFW_CURSOR_MODE:
            return window->cursorMode;
        case GLFW_STICKY_KEYS:
            return window->stickyKeys;
        case GLFW_STICKY_MOUSE_BUTTONS:
            return window->stickyMouseButtons;
        case GLFW_SYSTEM_KEYS:
            return window->systemKeys;
        case GLFW_KEY_REPEAT:
            return window->keyRepeat;
        default:
            _glfwSetError(GLFW_INVALID_ENUM, NULL);
            return 0;
    }
}
Example #7
0
File: input.c Project: eledot/Plum
GLFWAPI void glfwSetInputMode(GLFWwindow handle, int mode, int value)
{
    _GLFWwindow* window = (_GLFWwindow*) handle;

    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return;
    }

    switch (mode)
    {
        case GLFW_CURSOR_MODE:
            setCursorMode(window, value);
            break;
        case GLFW_STICKY_KEYS:
            setStickyKeys(window, value ? GL_TRUE : GL_FALSE);
            break;
        case GLFW_STICKY_MOUSE_BUTTONS:
            setStickyMouseButtons(window, value ? GL_TRUE : GL_FALSE);
            break;
        default:
            _glfwSetError(GLFW_INVALID_ENUM, NULL);
            break;
    }
}
Example #8
0
GLFWAPI int glfwExtensionSupported(const char* extension)
{
    const GLubyte* extensions;
    _GLFWwindow* window;

    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return GL_FALSE;
    }

    window = _glfwLibrary.currentWindow;
    if (!window)
    {
        _glfwSetError(GLFW_NO_CURRENT_CONTEXT, NULL);
        return GL_FALSE;
    }

    if (extension == NULL || *extension == '\0')
    {
        _glfwSetError(GLFW_INVALID_VALUE, NULL);
        return GL_FALSE;
    }

    if (window->glMajor < 3)
    {
        // Check if extension is in the old style OpenGL extensions string

        extensions = glGetString(GL_EXTENSIONS);
        if (extensions != NULL)
        {
            if (_glfwStringInExtensionString(extension, extensions))
                return GL_TRUE;
        }
    }
    else
    {
        int i;
        GLint count;

        // Check if extension is in the modern OpenGL extensions string list

        glGetIntegerv(GL_NUM_EXTENSIONS, &count);

        for (i = 0;  i < count;  i++)
        {
             if (strcmp((const char*) window->GetStringi(GL_EXTENSIONS, i),
                         extension) == 0)
             {
                 return GL_TRUE;
             }
        }
    }

    // Check if extension is in the platform-specific string
    return _glfwPlatformExtensionSupported(extension);
}
Example #9
0
static int openJoystickDevice(int joy, const char* path)
{
#ifdef _GLFW_USE_LINUX_JOYSTICKS
    char numAxes, numButtons;
    int fd, version;

    fd = open(path, O_RDONLY | O_NONBLOCK);
    if (fd == -1)
        return GL_FALSE;

    _glfwLibrary.X11.joystick[joy].fd = fd;

    // Verify that the joystick driver version is at least 1.0
    ioctl(fd, JSIOCGVERSION, &version);
    if (version < 0x010000)
    {
        // It's an old 0.x interface (we don't support it)
        close(fd);
        return GL_FALSE;
    }

    ioctl(fd, JSIOCGAXES, &numAxes);
    _glfwLibrary.X11.joystick[joy].numAxes = (int) numAxes;

    ioctl(fd, JSIOCGBUTTONS, &numButtons);
    _glfwLibrary.X11.joystick[joy].numButtons = (int) numButtons;

    _glfwLibrary.X11.joystick[joy].axis =
        (float*) malloc(sizeof(float) * numAxes);
    if (_glfwLibrary.X11.joystick[joy].axis == NULL)
    {
        close(fd);

        _glfwSetError(GLFW_OUT_OF_MEMORY, NULL);
        return GL_FALSE;
    }

    _glfwLibrary.X11.joystick[joy].button =
        (unsigned char*) malloc(sizeof(char) * numButtons);
    if (_glfwLibrary.X11.joystick[joy].button == NULL)
    {
        free(_glfwLibrary.X11.joystick[joy].axis);
        close(fd);

        _glfwSetError(GLFW_OUT_OF_MEMORY, NULL);
        return GL_FALSE;
    }

    _glfwLibrary.X11.joystick[joy].present = GL_TRUE;
#endif // _GLFW_USE_LINUX_JOYSTICKS

    return GL_TRUE;
}
Example #10
0
GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param)
{
    _GLFWwindow* window = (_GLFWwindow*) handle;

    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return 0;
    }

    switch (param)
    {
        case GLFW_FOCUSED:
            return window == _glfwLibrary.focusedWindow;
        case GLFW_ICONIFIED:
            return window->iconified;
        case GLFW_CLOSE_REQUESTED:
            return window->closeRequested;
        case GLFW_REFRESH_RATE:
            return window->refreshRate;
        case GLFW_RESIZABLE:
            return window->resizable;
        case GLFW_VISIBLE:
            return window->visible;
        case GLFW_POSITION_X:
            return window->positionX;
        case GLFW_POSITION_Y:
            return window->positionY;
        case GLFW_CLIENT_API:
            return window->clientAPI;
        case GLFW_CONTEXT_VERSION_MAJOR:
            return window->glMajor;
        case GLFW_CONTEXT_VERSION_MINOR:
            return window->glMinor;
        case GLFW_CONTEXT_REVISION:
            return window->glRevision;
        case GLFW_CONTEXT_ROBUSTNESS:
            return window->glRobustness;
        case GLFW_OPENGL_FORWARD_COMPAT:
            return window->glForward;
        case GLFW_OPENGL_DEBUG_CONTEXT:
            return window->glDebug;
        case GLFW_OPENGL_PROFILE:
            return window->glProfile;
    }

    _glfwSetError(GLFW_INVALID_ENUM, NULL);
    return 0;
}
Example #11
0
GLFWAPI const char* glfwGetJoystickName(int joy)
{
    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return NULL;
    }

    if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
    {
        _glfwSetError(GLFW_INVALID_ENUM, NULL);
        return NULL;
    }

    return _glfwPlatformGetJoystickName(joy);
}
Example #12
0
GLFWAPI int glfwGetJoystickParam(int joy, int param)
{
    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return 0;
    }

    if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
    {
        _glfwSetError(GLFW_INVALID_ENUM, NULL);
        return 0;
    }

    return _glfwPlatformGetJoystickParam(joy, param);
}
Example #13
0
static void setCursorMode(_GLFWwindow* window, int mode)
{
    int centerPosX, centerPosY;

    if (mode != GLFW_CURSOR_NORMAL &&
        mode != GLFW_CURSOR_HIDDEN &&
        mode != GLFW_CURSOR_CAPTURED)
    {
        _glfwSetError(GLFW_INVALID_ENUM, NULL);
        return;
    }

    if (window->cursorMode == mode)
        return;

    centerPosX = window->width / 2;
    centerPosY = window->height / 2;

    if (mode == GLFW_CURSOR_CAPTURED)
        _glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
    else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
    {
        _glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
        _glfwInputCursorMotion(window,
                               centerPosX - window->cursorPosX,
                               centerPosY - window->cursorPosY);
    }

    _glfwPlatformSetCursorMode(window, mode);

    window->cursorMode = mode;
}
Example #14
0
File: input.c Project: eledot/Plum
static void setCursorMode(_GLFWwindow* window, int newMode)
{
    int oldMode, centerPosX, centerPosY;

    if (newMode != GLFW_CURSOR_NORMAL &&
        newMode != GLFW_CURSOR_HIDDEN &&
        newMode != GLFW_CURSOR_CAPTURED)
    {
        _glfwSetError(GLFW_INVALID_ENUM, NULL);
        return;
    }

    oldMode = window->cursorMode;
    if (oldMode == newMode)
        return;

    centerPosX = window->width / 2;
    centerPosY = window->height / 2;

    if (oldMode == GLFW_CURSOR_CAPTURED || newMode == GLFW_CURSOR_CAPTURED)
        _glfwPlatformSetCursorPos(window, centerPosX, centerPosY);

    _glfwPlatformSetCursorMode(window, newMode);
    window->cursorMode = newMode;

    if (oldMode == GLFW_CURSOR_CAPTURED)
        _glfwInputCursorMotion(window, window->cursorPosX, window->cursorPosY);
}
Example #15
0
GLFWAPI void glfwSetWindowSize(GLFWwindow handle, int width, int height)
{
    _GLFWwindow* window = (_GLFWwindow*) handle;

    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return;
    }

    if (window->iconified)
    {
        // TODO: Figure out if this is an error
        return;
    }

    // Don't do anything if the window size did not change
    if (width == window->width && height == window->height)
        return;

    _glfwPlatformSetWindowSize(window, width, height);

    if (window->mode == GLFW_FULLSCREEN)
    {
        // Refresh window parameters (may have changed due to changed video
        // modes)
        _glfwPlatformRefreshWindowParams(window);
    }
}
Example #16
0
void glfwDefaultWindowHints(void)
{
    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return;
    }

    memset(&_glfwLibrary.hints, 0, sizeof(_glfwLibrary.hints));

    // The default is OpenGL with minimum version 1.0
    _glfwLibrary.hints.clientAPI = GLFW_OPENGL_API;
    _glfwLibrary.hints.glMajor = 1;
    _glfwLibrary.hints.glMinor = 0;

    // The default is to show the window and allow window resizing
    _glfwLibrary.hints.resizable = GL_TRUE;
    _glfwLibrary.hints.visible   = GL_TRUE;

    // The default window position is the upper left corner of the screen
    _glfwLibrary.hints.positionX = 0;
    _glfwLibrary.hints.positionY = 0;

    // The default is 24 bits of color, 24 bits of depth and 8 bits of stencil
    _glfwLibrary.hints.redBits     = 8;
    _glfwLibrary.hints.greenBits   = 8;
    _glfwLibrary.hints.blueBits    = 8;
    _glfwLibrary.hints.depthBits   = 24;
    _glfwLibrary.hints.stencilBits = 8;
}
Example #17
0
GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname)
{
    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return NULL;
    }

    if (!_glfwLibrary.currentWindow)
    {
        _glfwSetError(GLFW_NO_CURRENT_CONTEXT, NULL);
        return NULL;
    }

    return _glfwPlatformGetProcAddress(procname);
}
Example #18
0
GLFWAPI void glfwSwapInterval(int interval)
{
    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return;
    }

    if (!_glfwLibrary.currentWindow)
    {
        _glfwSetError(GLFW_NO_CURRENT_CONTEXT, NULL);
        return;
    }

    _glfwPlatformSwapInterval(interval);
}
Example #19
0
int _glfwCreateContext(_GLFWwindow* window,
                       const _GLFWwndconfig* wndconfig,
                       const _GLFWfbconfig* fbconfig)
{
    _GLFWfbconfig closest;

    // Choose the best available fbconfig
    {
        unsigned int fbcount;
        _GLFWfbconfig* fbconfigs;
        const _GLFWfbconfig* result;

        fbconfigs = getFBConfigs(window, &fbcount);
        if (!fbconfigs)
            return GL_FALSE;

        result = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount);
        if (!result)
        {
            _glfwSetError(GLFW_PLATFORM_ERROR,
                          "GLX: No GLXFBConfig matched the criteria");

            free(fbconfigs);
            return GL_FALSE;
        }

        closest = *result;
        free(fbconfigs);
    }

    return createContext(window, wndconfig, closest.platformID);
}
Example #20
0
GLboolean _glfwRefreshContextParams(void)
{
    _GLFWwindow* window = _glfwLibrary.currentWindow;

    if (!parseGLVersion(&window->glMajor,
                        &window->glMinor,
                        &window->glRevision))
    {
        return GL_FALSE;
    }

    if (window->glMajor > 2)
    {
        // OpenGL 3.0+ uses a different function for extension string retrieval
        // We cache it here instead of in glfwExtensionSupported mostly to alert
        // users as early as possible that their build may be broken

        window->GetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress("glGetStringi");
        if (!window->GetStringi)
        {
            _glfwSetError(GLFW_PLATFORM_ERROR,
                          "glfwCreateWindow: Entry point retrieval is broken");
            return GL_FALSE;
        }
    }

    // Read back forward-compatibility flag
    {
      window->glForward = GL_FALSE;

      if (window->glMajor >= 3)
      {
          GLint flags;
          glGetIntegerv(GL_CONTEXT_FLAGS, &flags);

          if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)
              window->glForward = GL_TRUE;
          if (flags & 0)
              window->glDebug = GL_TRUE;
      }
    }

    // Read back OpenGL context profile
    {
      window->glProfile = 0;

      if (window->glMajor > 3 || (window->glMajor == 3 && window->glMinor >= 2))
      {
          GLint mask;
          glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);

          if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
              window->glProfile = GLFW_OPENGL_COMPAT_PROFILE;
          else if (mask & GL_CONTEXT_CORE_PROFILE_BIT)
              window->glProfile = GLFW_OPENGL_CORE_PROFILE;
      }
    }

    return GL_TRUE;
}
Example #21
0
void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
{
    WCHAR* wideString;
    HANDLE stringHandle;
    size_t wideSize;

    wideString = _glfwCreateWideStringFromUTF8(string);
    if (!wideString)
    {
        _glfwSetError(GLFW_PLATFORM_ERROR,
                        "Win32: Failed to convert clipboard string to "
                        "wide string");
        return;
    }

    wideSize = (wcslen(wideString) + 1) * sizeof(WCHAR);

    stringHandle = GlobalAlloc(GMEM_MOVEABLE, wideSize);
    if (!stringHandle)
    {
        free(wideString);

        _glfwSetError(GLFW_PLATFORM_ERROR,
                      "Win32: Failed to allocate global handle for clipboard");
        return;
    }

    memcpy(GlobalLock(stringHandle), wideString, wideSize);
    GlobalUnlock(stringHandle);

    if (!OpenClipboard(window->Win32.handle))
    {
        GlobalFree(stringHandle);
        free(wideString);

        _glfwSetError(GLFW_PLATFORM_ERROR,
                      "Win32: Failed to open clipboard");
        return;
    }

    EmptyClipboard();
    SetClipboardData(CF_UNICODETEXT, stringHandle);
    CloseClipboard();

    free(wideString);
}
Example #22
0
GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode)
{
    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return;
    }

    if (mode == NULL)
    {
        _glfwSetError(GLFW_INVALID_VALUE,
                      "glfwGetDesktopMode: Parameter 'mode' cannot be NULL");
        return;
    }

    _glfwPlatformGetDesktopMode(mode);
}
Example #23
0
void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask)
{
    if (!wglCopyContext(src->WGL.context, dst->WGL.context, mask))
    {
        _glfwSetError(GLFW_PLATFORM_ERROR,
                      "Win32/WGL: Failed to copy OpenGL context attributes");
    }
}
Example #24
0
GLFWAPI void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun)
{
    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return;
    }

    _glfwLibrary.mouseButtonCallback = cbfun;
}
Example #25
0
const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
{
    HANDLE stringHandle;

    if (!IsClipboardFormatAvailable(CF_UNICODETEXT))
    {
        _glfwSetError(GLFW_FORMAT_UNAVAILABLE, NULL);
        return NULL;
    }

    if (!OpenClipboard(window->Win32.handle))
    {
        _glfwSetError(GLFW_PLATFORM_ERROR,
                      "Win32: Failed to open clipboard");
        return NULL;
    }

    stringHandle = GetClipboardData(CF_UNICODETEXT);
    if (!stringHandle)
    {
        CloseClipboard();

        _glfwSetError(GLFW_PLATFORM_ERROR,
                      "Win32: Failed to retrieve clipboard data");
        return NULL;
    }

    free(_glfwLibrary.Win32.clipboardString);
    _glfwLibrary.Win32.clipboardString =
        _glfwCreateUTF8FromWideString(GlobalLock(stringHandle));

    GlobalUnlock(stringHandle);
    CloseClipboard();

    if (!_glfwLibrary.Win32.clipboardString)
    {
        _glfwSetError(GLFW_PLATFORM_ERROR,
                      "Win32: Failed to convert wide string to UTF-8");
        return NULL;
    }

    return _glfwLibrary.Win32.clipboardString;
}
Example #26
0
GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun)
{
    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return;
    }

    _glfwLibrary.keyCallback = cbfun;
}
Example #27
0
GLFWAPI GLFWwindow glfwGetCurrentContext(void)
{
    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return GL_FALSE;
    }

    return _glfwLibrary.currentWindow;
}
Example #28
0
GLFWAPI void glfwSetCursorEnterCallback(GLFWcursorenterfun cbfun)
{
    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return;
    }

    _glfwLibrary.cursorEnterCallback = cbfun;
}
Example #29
0
GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun)
{
    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return;
    }

    _glfwLibrary.scrollCallback = cbfun;
}
Example #30
0
File: input.c Project: eledot/Plum
GLFWAPI void glfwSetScrollCallback(GLFWwindow handle, GLFWscrollfun cbfun)
{
    _GLFWwindow* window = (_GLFWwindow*) handle;

    if (!_glfwInitialized)
    {
        _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
        return;
    }

    window->scrollCallback = cbfun;
}