Giter Club home page Giter Club logo

mimicopengl-withsdl's Introduction

MimicOpenGL-withSDL

The small toy 3D software rasterizer using SDL2 library. This project seems to be built well only on Windows yet.

Getting start

Build ๐Ÿ—

You can build this project with Makefile. To build it, just type

make all

in command.

Write main.cc โœ’

By modifying main.cc source file and rebuilding project, you can change what is rendered. The user(programmer) is intended to write the code with including only "mimic/include/mimic.hh" header file which provides enough operations for rendering. For more details about the operations this project provides, see mimic/include/mimic.hh and its comments.

Brief Structure of Rendering Pipeline

The whole rendering pipeline, from vertex processing stage to per-sample operation stage, is mimicked by calling DrawArray(const uint32_t start, const uint32_t number, DrawingType type) function in mimic/include/mimic.hh, with data of context instance(global) which is set through other function calls before calling this function.

Behavior of this function varies slightly with the type parameter, but overall behavior is almost similar.

Vertex Processing

In this stage, the function calculates the position of vertex, by calling vertex shader, per each vertex. Vertex shader is descripted by user and stored in context instance previously by user calling void set_shaders(const uint32_t out_size, void (*vertex_shader)(float*[], mmath::Vec4<float>*, float[]), color_t (*fragment_shader)(struct Fragment*)) function.

Vertex Post-Processing

In this stage, some operations are conducted in order to fit vertex shader output for the pixel of output window. Perspective division(i.e. dividing xyz-coordinate by w-coordinate) is conducted in this stage.

In case of lines, the function clips the line preemptively and adjusts the coordinates and attributes.

And in case of triangles, back-face culling is conducted.

Scan Conversion(Rasterization)

The primitives, composed of vertices, are converted into fragments(pixel) in this stage. Namely, the rasterizer determines which pixel is contained in each shape, such as triangle or line. For this, it conducts DDA algorithm for lines, and conducts naive algorithm(checking for all pixel if it is in primitive) for triangles.

I plan to improve it more efficiently soon.

Fragment Processing

The fragments, created in Scan Conversion stage, are shaded in this stage, in the way which fragment shader describes. Like Vertex Processing stage, fragment shader is descripted by user and stored in context instance previously by user calling void set_shaders(const uint32_t out_size, void (*vertex_shader)(float*[], mmath::Vec4<float>*, float[]), color_t (*fragment_shader)(struct Fragment*)) function.

Per-sample Operations

Lastly, the shaded fragments are filtered by z-buffering, so that only the frontmost fragment are displayed at rendering window in this stage.

Example

Video(Link) ๐ŸŽž

Implementation of phong shading, through using this project.

Phong Shading

mimicopengl-withsdl's People

Contributors

firstin0907 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

paxbun

mimicopengl-withsdl's Issues

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.