Git Product home page Git Product logo

renderergl's Introduction

RendererGL

RendererGL is a basic 3D renderer written in C++ and OpenGL 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 materials.

Warning This project is still under development

Take a look at some screenshots. 3D assets are not included

Features

  • Trackball and first person shooter camera
  • Anti aliasing (MSAA)
  • Textures
  • Load 3D models and textures from files
  • Skybox (cubemap)
  • FrameCapturer: create a texture of the scene
  • Blinn-Phong lighting: Ambient, Diffuse, Specular, Emission
  • Physically Based Rendering (PBR): Albedo, Metallic, Normal, Roughness, Ambient Occlusion, Emission
  • Shadow Mapping: percentage closer filtering
  • Normal Mapping
  • Gamma correction
  • HDR
  • Mouse ray casting: object selection

Scene Graph

A scene graph is a general data structure 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. It also defines the primitive (triangles, quads...) which the polytopes inside of it will be drawn.
  • 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: rotating cube with lighting

#include <iostream>
#include <vector>

#include <engine/renderer/Renderer.h>
#include <engine/renderer/TrackballCamera.h>
#include <engine/shapes/Cube.h>

#include <GLFW/glfw3.h>

const int WIDTH = 1280;
const int HEIGHT = 900;
GLFWwindow* window;

Renderer::Ptr renderer;

int main() {

    // Create window
    if (!glfwInit()) {
        std::cout << "Couldn't initialize window" << std::endl;
        return -1;
    }

    window = glfwCreateWindow(WIDTH, HEIGHT, "Cube example", NULL, NULL);
    
    if (!window) glfwTerminate();

    glfwMakeContextCurrent(window);

    // Renderer
    renderer = Renderer::New(WIDTH, HEIGHT);
    renderer->enableLight();

    // Camera
    double aspectRatio = static_cast<double>(WIDTH) / HEIGHT;
    TrackballCamera::Ptr camera = TrackballCamera::perspectiveCamera(glm::radians(45.0f), aspectRatio, 0.1, 1000);
    renderer->setCamera(std::dynamic_pointer_cast<Camera>(camera));
    camera->zoom(-2.5);

    // Light
    DirectionalLight light(glm::vec3(1));
    light.setColor(glm::vec3(1));
    renderer->addLight(light);

    // Scene
    Cube::Ptr cube = Cube::New();

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

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

    renderer->addScene(scene);

    // Main loop
    while (!glfwWindowShouldClose(window)) {

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

        // Draw scene
        renderer->clear();
        renderer->draw();
        
        // Update window
        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    // Destroy window
    glfwTerminate();

    return 0;
}

Custom mesh

std::vector<Vec3f> vertices { ... };
std::vector<unsigned int> indices { ... };

Polytope::Ptr mesh = Polytope::New(vertices, indices);

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

Screenshots

Lighting (Blinn-Phong), shadow mapping and emission

PBR Materials

Point Cloud

Gabriel archangel by greypixel geometrics

360 image visualization example

Contribution

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

Compilation

CMake is required for compilation. Take a look at compile.md

Dependencies

  • GLEW for loading OpenGL extensions
  • GLM for linear algebra stuff
  • ASSIMP for loading 3D models from files (.obj, .dae, ...)
  • STB for loading images from files (.png, .tga, .jpg, ...)

Optional dependencies used in tests:

  • GLFW for creating a window with an OpenGL context
  • ImGui for GUI

References

Dealing with OpenGL was much easier thanks to:

renderergl's People

Contributors

morcillosanz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

renderergl's Issues

Missing assets throughout tests

Hi I always checkout out cool renderers when I see them. I went to test RendererGL but the majority of the tests have hard links to models on your local machine (example).

In the interest of not being lazy I tried to track them down and was going to create a PR, but I'm unable to find most of them.

I was able to find Block City, but most others weren't as obvious. Any change you will commit the assets to the repo and make the paths relative? Or if you zip up that models folder I'd be happy to send a PR with relative paths.

No worries either way. Very cool project!

3D model loading and rendering

Hi, I am interested about how can i load a 3D model into OpenGL and render it as expected. Could you point out the corresponding codes in this repo? Thanks a lot!

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.