GithubHelp home page GithubHelp logo

jackzhousz / renderergl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from morcillosanz/renderergl

0.0 0.0 0.0 299.02 MB

Easy to use 3D renderer in C++ and OpenGL with lighting and shadows

License: MIT License

Shell 0.01% C++ 92.60% C 7.08% CMake 0.12% GLSL 0.19% GDB 0.01%

renderergl's Introduction

RendererGL

RendererGL is a 3D renderer written in C++ and OpenGL. The main objective of this project is to create a framework that allows working with 3D graphics without the need to know computer graphics or OpenGL. So that both beginners and more experienced programmers can create a 3D scene with lighting, shadows and more advanced 3D models in an easy way.

Warning This project is still under development

The file main.cpp is an example file using ImGui and RendererGL

Take a look at some screenshots

Features

  • Trackball and first person shooter camera
  • Polytopes and groups of polytopes
  • Dynamic polytopes
  • Polytope face culling
  • Blending
  • Anti aliasing (MSAA)
  • Textures
  • Load 3D models and textures from files: .obj, .dae, ...
  • Skybox (cubemap)
  • FrameCapturer (create a texture of the scene)
  • Blinn-Phong lighting
  • Emission
  • Shadow Mapping (percentage closer filtering)
  • Normal Mapping
  • Gamma correction
  • HDR
  • Mouse ray casting
  • Object selection
  • Scene Graph

Scene Graph

A scene graph is a general data structure commonly used by vector-based graphics editing applications and modern computer games, which arranges the logical and often spatial representation of a graphical scene. It is a collection of nodes in a graph or tree structure:

  • Polytope: A set of vertices and indices (optional) that defines a shape
  • Group: A set of polytopes
  • Model: A group which contains a set of polytopes that are loaded from a file (.obj, .dae, ...)
  • Scene: Contains a set of groups, models and other scenes
  • Renderer: Contains a set of scenes. It's the one who deals with all the graphics stuff

Take a look at the example below

Example: simple rotating cube

#include "engine/window/Window.h"
#include "engine/renderer/Renderer.h"
#include "engine/renderer/TrackballCamera.h"

Renderer::Ptr renderer;

// x y z  r g b
std::vector<Vec3f> cubeVertices {
    Vec3f(-0.5, -0.5,  0.5,   0.0f, 0.0f, 1.0f),
    Vec3f( 0.5, -0.5,  0.5,   1.0f, 0.0f, 1.0f),
    Vec3f( 0.5,  0.5,  0.5,   0.0f, 1.0f, 1.0f),
    Vec3f(-0.5,  0.5,  0.5,   0.0f, 1.0f, 0.5f),
    Vec3f(-0.5, -0.5, -0.5,   0.0f, 0.0f, 1.0f),
    Vec3f( 0.5, -0.5, -0.5,   1.0f, 0.0f, 1.0f),
    Vec3f( 0.5,  0.5, -0.5,   0.0f, 1.0f, 1.0f),
    Vec3f(-0.5,  0.5, -0.5,   0.0f, 1.0f, 0.5f)
};

std::vector<unsigned int> cubeIndices {
    0, 1, 2,  1, 5, 6,  7, 6, 5,
    2, 3, 0,  6, 2, 1,  5, 4, 7,
    4, 0, 3,  4, 5, 1,  3, 2, 6,
    3, 7, 4,  1, 0, 4,  6, 7, 3 
};

int main() {

    Window window("Perspective cube example", 500, 400);

    renderer = Renderer::New(window.getWidth(), window.getHeight());

    double aspectRatio = static_cast<double>(window.getWidth()) / window.getHeight();
    TrackballCamera camera = TrackballCamera::perspectiveCamera(glm::radians(45.0f), aspectRatio, 0.1, 1000);
    camera.zoom(-2.5);
    renderer->setCamera(camera);

    Polytope::Ptr polytopeCube = Polytope::New(cubeVertices, cubeIndices);

    Group::Ptr group = Group::New();
    group->add(polytopeCube);

    Scene::Ptr scene = Scene::New();
    scene->addGroup(group);

    renderer->addScene(scene);

    while (!window.windowShouldClose()) {

        // Update scene
        polytopeCube->rotate(0.55, glm::vec3(1, 0, 1));

        // Draw scene
        renderer->clear();
        renderer->render();
        window.update();
    }

    return 0;
}

Screenshots

Multiple point lights

Shadows

Emission

Call of Duty Ghost dog

Contribution

RendererGL is an open source project under the MIT licence. Feel free to fork it and contribute

Dependencies

  • GLFW for creating a window with an OpenGL context
  • GLEW for loading OpenGL extensions
  • GLM for linear algebra stuff
  • IMGUI for the user interface
  • ASSIMP for loading 3D models from files (.obj, .dae, ...)
  • STB for loading images from files (.png, .tga, .jpg, ...)

References

Dealing with OpenGL was much easier thanks to:

renderergl's People

Contributors

morcillosanz avatar

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.