Code Monkey home page Code Monkey logo

software-renderer-yablokov's Introduction

Build status

SW

Simple software rasterizer with OpenGL-like interface. It's neither fast nor good, created for learning purposes. Inspired by this article: https://web.archive.org/web/20180129085015/http://forum.devmaster.net/t/advanced-rasterization/6145

Screenshot Screenshot Screenshot

Drawing

swUseProgram(program);

swBindBuffer(SW_ARRAY_BUFFER, attribs_buf_id);
swBindBuffer(SW_INDEX_BUFFER, indices_buf_id);

swSetUniform(U_MVP, SW_MAT4, &mvp_mat[0][0]);

const int stride = sizeof(float) * 8;
swVertexAttribPointer(A_POS, 3 * sizeof(float), (SWuint)stride, (void *)0);
swVertexAttribPointer(A_UVS, 2 * sizeof(float), (SWuint)stride, (void *)(6 * sizeof(float)));

swDrawElements(SW_TRIANGLE_STRIP, (SWuint)num_indices, SW_UNSIGNED_SHORT, (void *)uintptr_t(offset));

Shaders (not really, just function pointers)

enum { A_POS,
       A_UVS };

enum { V_UVS };

enum { U_MVP,
       U_AMBIENT };

VSHADER environment_vs(VS_IN, VS_OUT) {
    using namespace glm;

    *(vec2 *)V_FVARYING(V_UVS) = make_vec2(V_FATTR(A_UVS));
    *(vec4 *)V_POS_OUT = make_mat4(F_UNIFORM(U_MVP)) * vec4(make_vec3(V_FATTR(A_POS)), 1);
}

FSHADER environment_fs(FS_IN, FS_OUT) {
    using namespace glm;

    const vec4 &fl = make_vec4(F_UNIFORM(U_FLASHLIGHT_POS));

    TEXTURE(DIFFUSEMAP_SLOT, F_FVARYING_IN(V_UVS), F_COL_OUT);
    *(vec3 *) F_COL_OUT *= make_vec3(F_UNIFORM(U_AMBIENT));
}

...

SWint program = swCreateProgram();
swUseProgram(p);
swInitProgram(environment_vs, environment_fs, 2);

swRegisterUniformv(U_MVP, SW_MAT4, 1);
swRegisterUniformv(U_AMBIENT, SW_VEC3, 1);

software-renderer-yablokov's People

Contributors

sergcpp 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.