{"id":21146363,"url":"https://github.com/bhallstein/oglw","last_synced_at":"2025-03-14T13:44:19.693Z","repository":{"id":143863504,"uuid":"100199225","full_name":"bhallstein/OGLW","owner":"bhallstein","description":"OpenGL-backed windowing and events. Cross-platform, very simple.","archived":false,"fork":false,"pushed_at":"2022-06-06T19:22:23.000Z","size":324,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-03T23:51:27.158Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bhallstein.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-13T19:19:50.000Z","updated_at":"2022-05-07T11:56:45.000Z","dependencies_parsed_at":"2024-07-23T20:07:25.208Z","dependency_job_id":null,"html_url":"https://github.com/bhallstein/OGLW","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhallstein%2FOGLW","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhallstein%2FOGLW/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhallstein%2FOGLW/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhallstein%2FOGLW/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bhallstein","download_url":"https://codeload.github.com/bhallstein/OGLW/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243589287,"owners_count":20315467,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-20T08:53:12.020Z","updated_at":"2025-03-14T13:44:19.669Z","avatar_url":"https://github.com/bhallstein.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# W\n\n\n*Under consideration:*\n\n- Screen config changed event\n- Screen layout object\n- Mouse hiding\n\n\n*Known issues:*\n\n- Windows:\n\t- Fullscreen windows automatically iconify when defocused due to GLFW bug #143\n\t- `Window::getPos()` \u0026 `setPos()` specify the position of the client area, rather than of the window itself, due to GLFW bug #105\n\t- When the window is switched from fullscreen mode to windowed mode or vice versa, it must be destroyed and recreated. The newly created window's context is shared with the previous one, but some OpenGL state will still need setting back up. This is also the case when calling `setScreen()` in fullscreen mode.\n\t- When a window is given focus, it may generate an `AppBecameForeground` event, even when the app wasn't previously in the background.\n- Mac:\n\t- Double-clicks on a window that is in the background result in two `LMouseDown/Up` events appearing in the `newEvents` vector simultaneously, as it is brought to the foreground.\n\n\n## About\n\nW is a very simple set of C++ classes to take care of setting up an OpenGL-backed window. The goal being to just get started working with OpenGL as quickly as possible.\n\nIt supports multiple windows (optionally using OGL resource sharing*), multiple screens, and switching between windowed and fullscreen modes. It also harvests native mouse, key, touch, and window events.\n\nW works on OS X, Windows and iOS [iOS is not actually yet supported]. On Windows, it requires GLFW 3.\n\n*Note that OpenGL contexts can share the following types of resource:\n\n- Textures\n- Buffer objects (VBOs, etc)\n- Shader \u0026 program objects\n\nOpenGL does not share VAOs or Framebuffer objects among contexts.\n\n\n## The Window class\n\nThe class W::Window represents a window. They are very simple to create \u0026 manipulate.\n\nConstructor:\n    Window(\n        int width, int height,\n        const char *title,\n        Window *share,\n        bool fullscreen,\n        int screen\n    )\n        \n- Parameters:\n\t- width, height: the desired width and height of the window (only affects windowed mode)\n\t- title: the title of the window (only affects windowed mode)\n\t- share: another window with whose OpenGL context this window will use resource sharing, or NULL\n\t- fullscreen: create in fullscreen or windowed mode?\n\t- screen: the screen on which to create the window\n\n\n### Window methods:\n\nOpenGL context methods\n\n- `void makeCurrentContext()` – make the window's OpenGL context current.\n- `void clearCurrentContext()` – make the OGL context current no longer.\n- `void flushBuffer()` – flush drawing calls made previously through the graphics pipeline.\n\nWindow attributes\n\n- `void setTitle(const char *)` – set the window title.\n\nSize \u0026 position\n\n- `void getSize(int *w, int *h)` – get the current size of the OpenGL view contained by the window.\n- `void setSize(int w, int h)` – set the OpenGL view size of the window. In windowed mode, this will result in a slightly larger overall window size, because of window chrome. If the window is in fullscreen mode, this has no effect.\n- `void getPos(int *x, int *y)` – get the position of the window’s top left corner, relative to the same corner of the screen.\n- `void setPos(int x, int y)` – set the position of the window’s top left corner.\n- `int getScreen()` – get the window’s current screen.\n- `void setScreen()` – set the window’s screen. The window will be repositioned onto that screen. If the requested screen doesn’t exist, screen zero will be used. If the window is in fullscreen mode, it will be resized to fill the new screen. On windows, if the window is in fullscreen mode, it will be destroyed and recreated..\n- `void goFullscreen()` – if in windowed mode, switch to fullscreen mode.\n- `void goWindowed()` – if in fullscreen mode, switch to windowed mode. If the window has ever been in windowed mode before, its position will be restored. Otherwise, it will be centered on the screen.\n\n\nMouse\n\n- `bool mouseIsOver()` – returns true if the mouse is over the window.\n- `void getMousePosition(int *x, int *y)` – gets the mouse position, relative to the top left pixel of the OpenGL view contained by the window.\n`void setMousePosition(int x, int y)` – similarly, sets the mouse position.\n\nEvents\n\n- `void getEvents()` – on Windows, retrieve system events and convert them to W events. NB: you only need to call this on one window per update cycle; this will retrieve events for all current windows.\n\n\n## Events\n\nW converts native events to the `W::Event` type.\n\nEvents have a `type` property, for example, `LMouseDown`. The property is of `W::EventType::T` type. See Event.h for the full list of event types.\n\nYou can register custom types of event like so:\n\n    MyClass.h:   extern W::EventType::T MyEventType;\n    MyClass.cpp: W::EventType::T MyEventType = W::Event::registerType();\n\nEvent defines several struct types encapsulating the information pertaining to an event:\n\n- MouseEvent:\n\t- int x, y\n\t- Window *window\n- KeyEvent:\n\t- KeyCode::T keyCode\n- ScrollEvent:\n\t- int dx, dy\n\t- Window *window\n- WindowEvent:\n\t- Window *window\n- TouchEvent:\n\t- int x, y\n\t- int touchID\n\nThese are stored in the following properties, respectively. Check the type of the event and use the appropriate property:\n\n- mouseEvent\n- keyEvent\n- scrollEvent\n- winEvent\n- touchEvent\n\nEvents are stored in the vector `Event::newEvents`. Iterate over them in your update cycle, then clear them.\n\nKeyCodes are of the type W::KeyCode::T and are defined in Event.h.\n\nOn Windows, GLFW’s peekmessage-based glfwPollEvents() system is used to retrieve messages from the windows queue.\n\nThese are then processed by glfw, triggering the appropriate callbacks.\n\nTherefore on Windows you need to synchronously trigger the retrieval of events in your update loop with `window-\u003egetEvents()`. NB: this can be called on any open window, but triggers the processing of events from all windows.\n\nMouse events have a window property. Key events do not – for now, they’re considered global.\n\nThe event system is switched off initially. To turn it on, set `W::Event::on = true`.\n\n\n## Screens\n\nScreens are referred to by their integer index, starting at zero.\n\n- Retrieve the total number of screens using `W::numberOfScreens()`\n- Find a screen’s position: `W::getScreenPosition(int screen, int *x, int *y)`. The top left of screen zero is considered the origin.\n- Find a screen’s size: `W::getScreenSize(int screen, int *w, int *h)`.\n\nIf the requested screen doesn't exist, `getScreenSize` \u0026`getScreenPosition` will set their parameters to -1.\n\n\n## License\n\nW is published under the open source MIT license, and comes with no warranty whatsoever. If you use it, drop me a message to let me know :)\n\nBen Hallstein, 2014\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhallstein%2Foglw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbhallstein%2Foglw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhallstein%2Foglw/lists"}