Code Monkey home page Code Monkey logo

tinygl.js's Introduction

TinyGL.js

TinyGL.js is a JavaScript library providing a tiny subset of OpenGL 1.1 compatible API, which can be used to make 3D graphics on canvas. TinyGL.js is based upon TinyGL's implementation written in C and compiled to JavaScript via Emscripten. It only uses software rasterization and does not require WebGL to run.

Current implementation is based on an enhanced and bug-fixed branch of TinyGL 0.4.

Getting Started

This library is in a single JavaScript source file tinygl.js. It should be included first:

<script type="text/javascript" src="tinygl.js"></script>

Then, assuming a canvas element is already declared in the HTML, we get TinyGL.js's rendering context using the keyword experimental-tinygl:

var canvas = document.getElementById(canvas_id);
var gl = canvas.getContext('experimental-tinygl');

The semantics is almost the same with what we do for a Canvas2D or WebGL context. Now that we have the rendering context, let's begin with some basic primitives:

gl.viewport(0, 0, canvas.width, canvas.height);

gl.clearColor(0, 0, 0, 0);
gl.clear(gl.COLOR_BUFFER_BIT);

gl.matrixMode(gl.PROJECTION);
gl.loadIdentity();
gl.frustum(-2.0, 2.0, -2.0, 2.0, 6.0, 20.0);
gl.matrixMode(gl.MODELVIEW);
gl.loadIdentity();
gl.translatef(0.0, 0.0, -16.0);

gl.color3f(1, 0, 0);
gl.begin(gl.POLYGON);
  gl.vertex3f(-1, -1, 0);
  gl.vertex3f( 1, -1, 0);
  gl.vertex3f( 1,  1, 0);
  gl.vertex3f(-1,  1, 0);
gl.end();

gl.flush();
gl.swapBuffers();

Here comes our first polygon with TinyGL.js :-) See what it outputs here.

Examples

gears example atlantis example mech example earth example

more ...

Browser Requirements

TinyGL.js depends on Canvas and Typed Arrays. Make sure your browser supports these features to run codes with TinyGL.js.

Known Issues

  • Canvas width must be multiples of 4 according to TinyGL's restriction. Otherwise, there may be some columns not refreshed.

tinygl.js's People

Contributors

humu2009 avatar

Stargazers

stagas avatar wmingjian avatar  avatar mohamad hani janaty avatar Alex avatar  avatar  avatar GAURAV avatar  avatar Audi Nugraha avatar Richard Jewson avatar Jason Pepas avatar wandergis avatar  avatar Gordon avatar  avatar James Liu avatar 子龙 avatar Aria avatar Kevin Kwok avatar Dmitry Iv. avatar  avatar Jason Benaim avatar Éverton Antunes de Oliveira avatar mizt avatar S J avatar  avatar Tyler Anderson avatar Michael Anthony avatar Blaze Jayne avatar PeterLiou avatar Julian Viereck avatar Robert Konrad avatar Tim Gittos avatar Jay Little avatar  avatar Nenad Golubovic avatar Jaeho Lee (Jay) avatar Maurice Svay avatar  avatar Felicioli Claudio avatar Daosheng Mu avatar Mark Farrell avatar Eric Hu avatar  avatar Nile avatar Rich Tibbett avatar Ethan Sherbondy avatar  avatar

Watchers

James Cloos avatar Felicioli Claudio avatar Michael Anthony avatar  avatar Éverton Antunes de Oliveira avatar  avatar  avatar

tinygl.js's Issues

Error while converting TinyGL to tinugl.js

emcc -O3 -I ./TinyGL/src/ -I ./TinyGL/include/ -D NDEBUG TinyGL/src/api.c TinyGL/src/list.c TinyGL/src/vertex.c TinyGL/src/init.c TinyGL/src/matrix.c TinyGL/src/texture.c TinyGL/src/misc.c TinyGL/src/clear.c TinyGL/src/light.c TinyGL/src/query.c TinyGL/src/clip.c TinyGL/src/select.c TinyGL/src/get.c TinyGL/src/error.c TinyGL/src/zbuffer.c TinyGL/src/zline.c TinyGL/src/ztriangle.c TinyGL/src/zmath.c TinyGL/src/image_util.c TinyGL/src/oscontext.c TinyGL/src/msghandling.c TinyGL/src/arrays.c TinyGL/src/specbuf.c TinyGL/src/memory.c -o js/tinygl.o

while compiling according to your compiling instruction i got this error

No such file or directory
Traceback (most recent call last):
File "/users/extusr/akash_2019/emsdk/emscripten/1.38.31/emcc.py", line 3308, in
sys.exit(run(sys.argv))
File "/users/extusr/akash_2019/emsdk/emscripten/1.38.31/emcc.py", line 1752, in run
shared.Building.link_to_object(linker_inputs, specified_target)
File "/users/extusr/akash_2019/emsdk/emscripten/1.38.31/tools/shared.py", line 1790, in link_to_object
Building.link(linker_inputs, target)
File "/users/extusr/akash_2019/emsdk/emscripten/1.38.31/tools/shared.py", line 2053, in link
Building.link_llvm(link_args, target)
File "/users/extusr/akash_2019/emsdk/emscripten/1.38.31/tools/shared.py", line 1797, in link_llvm
output = run_process(cmd, stdout=PIPE).stdout
File "/users/extusr/akash_2019/emsdk/emscripten/1.38.31/tools/shared.py", line 174, in run_process
result.check_returncode()
File "/users/extusr/akash_2019/emsdk/emscripten/1.38.31/tools/shared.py", line 154, in check_returncode
raise Py2CalledProcessError(returncode=self.returncode, cmd=self.args, output=self.stdout, stderr=self.stderr)
tools.shared.Py2CalledProcessError: Command '['/users/extusr/akash_2019/emsdk/clang/e1.38.31_64bit/llvm-link', '/tmp/emscripten_temp_2HBOSR/api_0_24.o', '/tmp/emscripten_temp_2HBOSR/list_1_25.o', '/tmp/emscripten_temp_2HBOSR/vertex_2_26.o', '/tmp/emscripten_temp_2HBOSR/init_3_27.o', '/tmp/emscripten_temp_2HBOSR/matrix_4_28.o', '/tmp/emscripten_temp_2HBOSR/texture_5_29.o', '/tmp/emscripten_temp_2HBOSR/misc_6_30.o', '/tmp/emscripten_temp_2HBOSR/clear_7_31.o', '/tmp/emscripten_temp_2HBOSR/light_8_32.o', '/tmp/emscripten_temp_2HBOSR/query_9_33.o', '/tmp/emscripten_temp_2HBOSR/clip_10_34.o', '/tmp/emscripten_temp_2HBOSR/select_11_35.o', '/tmp/emscripten_temp_2HBOSR/get_12_36.o', '/tmp/emscripten_temp_2HBOSR/error_13_37.o', '/tmp/emscripten_temp_2HBOSR/zbuffer_14_38.o', '/tmp/emscripten_temp_2HBOSR/zline_15_39.o', '/tmp/emscripten_temp_2HBOSR/ztriangle_16_40.o', '/tmp/emscripten_temp_2HBOSR/zmath_17_41.o', '/tmp/emscripten_temp_2HBOSR/image_util_18_42.o', '/tmp/emscripten_temp_2HBOSR/oscontext_19_43.o', '/tmp/emscripten_temp_2HBOSR/msghandling_20_44.o', '/tmp/emscripten_temp_2HBOSR/arrays_21_45.o', '/tmp/emscripten_temp_2HBOSR/specbuf_22_46.o', '/tmp/emscripten_temp_2HBOSR/memory_23_47.o', '-o', 'js/tinygl.o']' returned non-zero exit status 1

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.