• Stars
    star
    620
  • Rank 72,387 (Top 2 %)
  • Language
    C++
  • License
    MIT License
  • Created over 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ’ป๐Ÿ“ฑ A cross platform system abstraction library written in C++ for managing windows and performing OS tasks.

Logo

CrossWindow

Cross Window is a cross platform system abstraction library for managing windows and performing OS tasks. It's designed to be easy to integrate, intuitive, and support everything you might need for your apps.

Features

  • ๐ŸŒŸ Simple Window, File Dialog, and Message Dialog Creation.

  • โŒจ๏ธ ๐Ÿ–ฑ๏ธ ๐Ÿ‘† ๐ŸŽฎ Basic Input (Keyboard, Mouse, Touch, and Gamepad).

  • ๐Ÿ‘ป Platform specific features (Mac Transparency, Mobile Accelerometer, etc.).

  • ๐Ÿ’Š Unit Tests + Test Coverage (Appveyor for Windows, CircleCI for Android / MacOS / iOS, [Travis][travis-url] for Linux/Noop).

Supported Platforms

  • ๐Ÿ–ผ๏ธ Windows - Win32

  • ๐ŸŽ Mac - Cocoa

  • ๐Ÿ“ฑ iOS - UIKit

  • ๐Ÿง Linux - XCB or XLib

  • ๐Ÿค– Android (In Progress)

  • ๐ŸŒ WebAssembly - Emscripten

  • โŒ Noop (Headless)

Installation

First add the repo as a submodule in your dependencies folder such as external/:

# โคต๏ธ Add your dependency as a git submodule:
git submodule add https://github.com/alaingalvan/crosswindow.git external/crosswindow

Then in your CMakeLists.txt file, include the following:

# โคต๏ธ Add to your CMake Project:
add_subdirectory(external/crosswindow)

# โŽ When creating your executable use CrossWindow's abstraction function:
xwin_add_executable(
    # Target
    ${PROJECT_NAME}
    # Source Files (make sure to surround in quotations so CMake treats it as a list)
    "${SOURCE_FILES}"
)

# ๐Ÿ”— Link CrossWindow to your project:
target_link_libraries(
    ${PROJECT_NAME}
    CrossWindow
)

Fill out the rest of your CMakeLists.txt file with any other source files and dependencies you may have, then in your project root:

# ๐Ÿ–ผ๏ธ To build your Visual Studio solution on Windows x64
cmake -B build -A x64

# ๐ŸŽ To build your XCode project On Mac OS for Mac OS
cmake -B build -G Xcode

# ๐Ÿ“ฑ To build your XCode project on Mac OS for iOS / iPad OS / tvOS / watchOS
cmake -B build -G Xcode -DCMAKE_SYSTEM_NAME=iOS

# ๐Ÿง To build your .make file on Linux
cmake -B build

# ๐Ÿ”จ Build on any platform:
cmake -B build --build

For WebAssembly you'll need to have Emscripten installed. Assuming you have the SDK installed, do the following to build a WebAssembly project:

# ๐ŸŒ For WebAssembly Projects
mkdir webassembly
cd webassembly
cmake .. -DXWIN_OS=WASM -DCMAKE_TOOLCHAIN_FILE="$EMSDK/emscripten/1.38.1/cmake/Modules/Platform/Emscripten.cmake" -DCMAKE_BUILD_TYPE=Release

# Run emconfigure with the normal configure command as an argument.
$EMSDK/emscripten/emconfigure ./configure

# Run emmake with the normal make to generate linked LLVM bitcode.
$EMSDK/emscripten/emmake make

# Compile the linked bitcode generated by make (project.bc) to JavaScript.
#  'project.bc' should be replaced with the make output for your project (e.g. 'yourproject.so')
$EMSDK/emscripten/emcc project.bc -o project.js

For more information visit the Emscripten Docs on CMake.

For Android Studio you'll need to make a project, then edit your build.gradle file.

// ๐Ÿค– To build your Android Studio project
android {
    ...
    externalNativeBuild {
        cmake {
            ...
            // Use the following syntax when passing arguments to variables:
            // arguments "-DVAR_NAME=ARGUMENT".
            arguments "-DXWIN_OS=ANDROID",
            // The following line passes 'rtti' and 'exceptions' to 'ANDROID_CPP_FEATURES'.
            "-DANDROID_CPP_FEATURES=rtti exceptions"
        }
    }
  buildTypes {...}

  // Use this block to link Gradle to your CMake build script.
  externalNativeBuild {
    cmake {...}
  }
}

for more information visit Android Studio's docs on CMake.

Usage

Then create a main delegate function void xmain(int argc, const char** argv) in a .cpp file in your project (for example "XMain.cpp") where you'll put your application logic:

#include "CrossWindow/CrossWindow.h"

void xmain(int argc, const char** argv)
{
    // ๐Ÿ–ผ๏ธ Create Window Description
    xwin::WindowDesc windowDesc;
    windowDesc.name = "Test";
    windowDesc.title = "My Title";
    windowDesc.visible = true;
    windowDesc.width = 1280;
    windowDesc.height = 720;

    bool closed = false;

    // ๐ŸŒŸ Initialize
    xwin::Window window;
    xwin::EventQueue eventQueue;

    if (!window.create(windowDesc, eventQueue))
    { return; }

    // ๐Ÿ Engine loop
    bool isRunning = true;

    while (isRunning)
    {
        // โ™ป๏ธ Update the event queue
        eventQueue.update();

        // ๐ŸŽˆ Iterate through that queue:
        while (!eventQueue.empty())
        {
            const xwin::Event& event = eventQueue.front();

            if (event.type == xwin::EventType::MouseInput)
            {
                const xwin::MouseInputData mouse = event.data.mouseInput;
            }
            if (event.type == xwin::EventType::Close)
            {
                window.close();
                isRunning = false;
            }

            eventQueue.pop();
        }
    }
}

This xmain function will be called from a platform specific main function that will be included in your main project by CMake. If you ever need to access something from the platform specific main function for whatever reason, you'll find it in xwin::getXWinState().

Development

Be sure to have CMake Installed.

CMake Options Description
XWIN_TESTS Whether or not unit tests are enabled. Defaults to OFF, Can be ON or OFF.
XWIN_API The OS API to use for window generation, defaults to AUTO, can be can be NOOP, WIN32, COCOA, UIKIT, XCB , ANDROID, or WASM.
XWIN_OS Optional - What Operating System to build for, functions as a quicker way of setting target platforms. Defaults to AUTO, can be NOOP, WINDOWS, MACOS, LINUX, ANDROID, IOS, WASM. If your platform supports multiple apis, the final api will be automatically set to CrossWindow defaults ( WIN32 on Windows, XCB on Linux ). If XWIN_API is set this option is ignored.

First install Git, then open any terminal in any folder and type:

# ๐Ÿ‘ Clone the repo
git clone https://github.com/alaingalvan/crosswindow.git --recurse-submodules

# ๐Ÿ’ฟ go inside the folder
cd crosswindow

# ๐Ÿ‘ฏ If you forget to `recurse-submodules` you can always run:
git submodule update --init

From there we'll need to set up our build files. Be sure to have the following installed:

Then type the following in your terminal from the repo folder:

# ๐Ÿ–ผ๏ธ To build your Visual Studio solution on Windows x64
cmake -B build -A x64 -DXWIN_TESTS=ON

# ๐ŸŽ To build your XCode project on Mac OS
cmake -B build -G Xcode -DXWIN_TESTS=ON

# ๐Ÿง To build your .make file on Linux
cmake -B build -DXWIN_TESTS=ON

# ๐Ÿ”จ Build on any platform:
cmake -B build --build

Whenever you add new files to the project, run cmake .. from your solution/project folder /build/, and if you edit the CMakeLists.txt file be sure to delete the generated files and run Cmake again.

License

CrossWindow is licensed as either MIT or Apache-2.0, whichever you would prefer.

More Repositories

1

webgpu-seed

๐Ÿ”บ๐ŸŒฑ An example on how to render a hello triangle with WebGPU.
TypeScript
296
star
2

CrossShader

โš”๏ธ A tool for cross compiling shaders. Convert between GLSL, HLSL, Metal Shader Language, or older versions of GLSL.
C++
279
star
3

directx12-seed

โœ–๐ŸŒฑ A DirectX 12 starter repo that you could use to get the ball rolling.
C++
127
star
4

image-editor-effects

๐Ÿ’Ž A WebGL example of image adjustment / effects shaders found in Photoshop, other image editors and game engines.
TypeScript
96
star
5

a-trip-through-the-graphics-pipeline-book

๐Ÿ“• A clone of @rygorous series of posts on the graphics pipeline.
84
star
6

CrossWindow-Graphics

A header only library to simplify creating ๐ŸŒ‹ Vulkan / โšช OpenGL / ๐ŸŒ WebGL / โŽDirectX / ๐Ÿค– Metal data structures with CrossWindow.
C++
79
star
7

vulkan-seed

๐ŸŒ‹๐ŸŒฑ A Vulkan starter repo that you could use to get the ball rolling.
C++
75
star
8

CrossWindow-Demos

๐Ÿฅช Examples of how to use CrossWindow for things like rendering graphics, listening to events, etc.
C++
66
star
9

webgl-seed

๐ŸŒ๐ŸŒฑ A starter repo for building WebGL applications.
TypeScript
48
star
10

raw-vulkan

๐Ÿ”ฅ Experiments building Vulkan applications, libraries, and abstractions.
C++
45
star
11

GPU-Zen-2-Baker

๐Ÿฅง An OpenGL 4.x example of GPU Zen 2's ray casting techniques for baked texture generation chapter.
CMake
41
star
12

metal-seed

๐Ÿค–๐ŸŒฑ An Apple Metal starter repo that you could use to get the ball rolling.
Objective-C++
38
star
13

opengl-seed

โšช๐ŸŒฑA modern OpenGL starter repo that you could use to get the ball rolling.
C++
33
star
14

fig-standing-desk

๐Ÿ—œ๏ธ A custom standing desk that you can control from the command line.
Rust
16
star
15

strange-attractors

โคด๏ธ Algorithms to generate strange attractors such as Lorenz, Burgers, etc.
Python
15
star
16

foil

โœจ A portfolio CMS library designed for engineers, artists, technical artists, musicians, and bloggers looking to showcase a portfolio of front-end experiments, games, art, articles, and more.
Rust
11
star
17

PxWar

๐Ÿš€ A bullethell game built with TypeScript and Canvas.
TypeScript
6
star
18

opengl-seed-wasm

๐ŸŒโšช An example of of the opengl-seed example compiled to WebAssembly.
HTML
6
star
19

ora

๐Ÿ’ก A game where you're a blur of light trying to escape an encroaching darkness made for the 2012 GameMaker Steam Workshop.
Game Maker Language
4
star
20

alaingalvan

โ‰ About Alain Galvan, Graphics Software Engineer.
3
star
21

crosswindow-imgui

๐Ÿ–Œ๏ธ An optional library wrapping ImGui and providing bindings for CrossWindow events.
C++
3
star
22

alainxyz-comments

๐Ÿ”ฎ Utterances powered comments for the Alain.xyz blog.
2
star
23

conan-vulkan-sdk

Conan package for the Vulkan SDK.
Python
2
star
24

guardian

๐Ÿ‘ผ A real time monster based role playing game (RPG) I made for GameMaker's 2010 summer competition.
Game Maker Language
2
star
25

foil-starters

๐ŸŒ  A monorepo of all available starters for the foil CMS.
SCSS
1
star