Giter VIP home page Giter VIP logo

gorn's Introduction

GORN

Gorn Creature from Star Trek

Gorn is a simple C++11 OpenGL multiplatform renderer

Its main goals are:

  • simplicity
  • performance
  • reusability
  • support for Linux, Android, iOS and Windows (MacOS WIP)

Some functionalities that the render queue supports:

  • draw call batching
  • frustum culling
  • drawing in separate thread (TODO)

Examples

Easy to use C++ classes to wrap around the standard OpenGL API.

auto vsh = std::make_shared<Shader>(R"(#version 100

precision highp float;

attribute vec3 color;
attribute vec2 position;

uniform float timeSin;

varying vec3 Color;

void main()
{
    Color = color;
    gl_Position = vec4(position, 0.0, 0.2*timeSin+1.0);
}
)"), ShaderType::Vertex);

auto fsh = std::make_shared<Shader>(R"(#version 100

precision highp float;

uniform float timeSin;

varying vec3 Color;

void main()
{
    gl_FragColor = vec4(Color, 1.0);
}
)"), ShaderType::Fragment);

auto vao = VertexArray()
vao.setProgram(Program(vsh, fsh));

auto vbo = VertexBuffer(buffer{
    //  Position     Color
        0.0f,  0.5f, 1.0f, 0.0f, 0.0f, // Vertex 1: Red
        0.5f, -0.5f, 0.0f, 1.0f, 0.0f, // Vertex 2: Green
       -0.5f, -0.5f, 0.0f, 0.0f, 1.0f  // Vertex 3: Blue
}, VertexBuffer::Usage::StaticDraw);

vao.setAttribute(vbo, AttributeDefinition("position")
    .withType(BasicType::Float)
    .withCount(2)
    .withStride(5, BasicType::Float));

vao.setAttribute(vbo, AttributeDefinition("color")
    .withType(BasicType::Float)
    .withCount(3)
    .withStride(5, BasicType::Float)
    .withOffset(2, BasicType::Float));

vao.draw(3);

Very extendable file sources can be defined using tags.

Context ctx;
ctx.getFiles()
    .makeLoader<LocalFileLoader>("sprite", "../%s.png");
ctx.getImages()
    .makeDefaultDataLoader<PngImageLoader>();

auto img = ctx.getImages().load("sprite:kitten");

Loading assets can be done with definitions.

Context ctx;
ctx.getFiles()
    .makeLoader<LocalFileLoader>("vsh", "../%s.vsh");
ctx.getFiles()
    .makeLoader<LocalFileLoader>("fsh", "../%s.fsh");
ctx.getPrograms().getDefinitions().get("sprite")
    .withUniform(UniformKind("texture", UniformType::DiffuseTexture))
    .withShaderFile(ShaderType::Vertex, "vsh:shader")
    .withShaderFile(ShaderType::Fragment, "fsh:shader");

auto prog = ctx.getPrograms().load("sprite");

Support for materials, that combine a program with a list of textures and uniform values.

Context render;
render.getMaterials().getDefinitions().get("puppy")
    .withProgram("shader")
    .withTexture(UniformType::DiffuseTexture, "puppy.png");

Support for render commands that are executed afterwards.

Context ctx;

ctx.getQueue().addCommand("sprite:puppy")
    .withAttribute(AttributeType::Position, buffer{
        -0.25f,  0.25f,
         0.75f,  0.25f,
         0.75f, -0.75f,
        -0.25f, -0.75f
    })
    .withAttribute(AttributeType::TexCoords, buffer{
        0.0f, 1.0f,
        1.0f, 1.0f,
        1.0f, 0.0f,
        0.0f, 0.0f
    })
    .withElements({
        0, 1, 2,
        2, 3, 0
    });

ctx.getQueue().draw();

gorn's People

Contributors

miguelibero avatar sp-miguel-ibero avatar

Watchers

James Cloos avatar Kunal Dawn 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.