GithubHelp home page GithubHelp logo

samizzo / pixie Goto Github PK

View Code? Open in Web Editor NEW
26.0 3.0 4.0 863 KB

Pixie - a minimal, cross-platform pixel framebuffer library for Windows and macOS.

License: MIT License

C++ 77.51% Objective-C++ 20.72% C 1.77%
imgui macos c cpp framebuffer pixel windows library

pixie's Introduction

Pixie

msbuild mingw macOS

Pixie is a minimal, cross-platform pixel framebuffer library for Windows and macOS.

example.gif

Quick Start

Copy the following files into your project:

pixie.cpp
pixie.h
core.h
Windows: pixie_win.cpp
macOS: pixie_osx.cpp

To use Pixie:

#include "pixie.h"

int main(int argc, char** argv)
{
    Pixie::Window window;
    if (!window.open("Hello, World!", 640, 480))
        return 0;

    while (!window.HasKeyGoneUp(Pixie::Key_Escape))
    {
        uint32_t* pixels = window.GetPixels();
        // ..draw pixels!

        if (!window.Update())
            break;
    }

    window.Close();
}

The pixel byte order is BGRx (from LSB to MSB). On macOS, the pixel buffer is transformed from BGR to RGB.

Examples

Pixie has an example program in main.cpp. It can be compiled for Windows with the Visual Studio 2017 project, or for macOS with makefile_osx as follows:

make -f makefile_osx

This will generate an executable pixie_demo.

On macOS Pixie requires the CoreGraphics and AppKit frameworks.

API

Pixie has some basic keyboard and mouse handling. You can check for:

  • Mouse or key down in the current frame: HasMouseGoneDown, HasKeyGoneDown, HasAnyKeyGoneDown
  • Mouse or key up in the current frame: HasMouseGoneUp, HasKeyGoneUp
  • Mouse or key currently down: IsMouseDown, IsKeyDown, IsAnyKeyDown

The mouse position (in window coordinates) can be obtained with GetMouseX and GetMouseY.

Additionally the current time delta in seconds can be obtained with GetDelta.

ImGui

Pixie has a basic ImGui with support for:

  • Labels
  • Buttons
  • Input fields
  • Check boxes
  • Radio boxes
  • Drawing rectangles and filled rectangles

To use the ImGui, add the following files to your project:

imgui.cpp
imgui.h
font.h

and ensure that font.bmp is in your working directory.

To load the font:

Pixie::Font font;
const int FontWidth = 9;
const int FontHeight = 16;
if (!font.Load("font.bmp", FontWidth, FontHeight))
    return 0;

In your main loop:

while (!window.HasKeyGoneUp(Pixie::Key_Escape))
{
    Pixie::ImGui::Begin(&window, &font);

    if (Pixie::ImGui::Button("Hello", 100, 100, 100, 30))
        printf("Hello button was pressed\n");

    Pixie::ImGui::End();

    if (!window.Update())
        break;
}

License

Pixie is licensed under the MIT License. See LICENSE for more information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.