Code Monkey home page Code Monkey logo

2d-viewer's Introduction

2D Viewer

This repository contains a small viewer library (C++ and OpenGL2) encapsulating window, and input handling, primitive, and graphical user interface (ImGui/ImPlot) rendering.
I wrote it originally for visualizing physically based simulation approaches (mass-spring systems, rigid-bodies, SPH, etc.). Over the years it has been used for teaching purposes, e.g. practical assignments, at my university.

It has the following in-source external dependencies: glfw, glm, imgui, implot, stb_image.

Minimal Example

The Viewer class provides the interface to configure window/render behaviour and to register callbacks for the following events:

  • init: is called after the opengl context is initialized
  • shutdown: is called right before the opengl context is destroyed
  • key: triggered if a key is pressed or released
  • mouseButton: triggered if a mouse button is pressed or released
  • update: called before rendering (once per frame)
  • draw: used to submit render calls (points, lines, quads, triangles, circles, ...)
  • gui: used to draw/respond to user-interface via ImGui and ImPlot
    Viewer viewer;
    viewer.mWindow.title = "Example";
    viewer.mWindow.width = 1280;
    viewer.mWindow.height = 720;
    viewer.mWindow.vsync = true;
    viewer.mWindow.mHDPI = false;

    /* install callback functions for events */
    viewer.onUpdate([](Window& window, double dt){ });
    viewer.onDraw([](Window& window, double dt){ });
    viewer.onGui([](Window& window, double dt){ });
    viewer.onMouseButton([](Window& window, Mouse& mouse, int button, int mod, bool press){ });
    viewer.onKey([](Window& window, Keyboard& keyboard, int key, int mod, bool press){ });
 
    /* start viewer (OpenGL context is created, use drawcommands and loading functions only in callbacks) */
    viewer.run();

See demo/demo.cpp for a detailed overview of the libraries functionalities.

Examples

Assignments for a physically-based simulation course (mass-spring systems, rigid-body simulation, stable fluid, finite element method). viewer_examples

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.