Canvas 3d JS Library

where 3D is born!
  • rss
  • What is C3DL?
  • Download
  • Tutorials
    • Tutorial #1: Installing Canvas 3D Addon
    • Tutorial #2: A Scene and a Cube
    • Tutorial #3: Update Callback
    • Tutorial #4: Models 101
  • Development News
  • Demos
    • Typing Game V2.1
    • Typing Game V3 (0.3 Release)
    • Explorer
    • Flickr - Picking
    • Ricochet
    • FSOSS Pictures
    • Puzzler
  • Resources
  • Contact
  • About

Limitations in the 2.0 context

Andor Salga | 2 September, 2008 | 8:54

While working in the OpenGLES 2.0 context, I came across some concerns. These originate from the limited functionality of canvas3d using this context. There are some functions which are available in 1.1 which are not included in 2.0, notably functions involving the matrix stack and lighting.

Using 1.1, users of canvas3d have access to the matrix stack commands, so they can write:

canvas3D.pushMatrix(); canvas3D.multMatrix(modelMatrix); canvas3D.drawArrays(canvas3D.TRIANGLES, 0, (vertices.length/3)); canvas3D.popMatrix();

Here, a copy of the top matrix (essentially a 4×4 array) is pushed onto a stack. Then a matrix called the modelMatrix which contains a specific model’s transformation is multiplied with the copied matrix. Therefore when drawArrays() is called, the vertices of the model are drawn using the top matrix transformation. This allows objects to be draw with their own positions, rotations and scaling.

Our library is currently not using the stack extensively; the code above is similar to the code found in the Model.js file. So emulating the 1.1 code in 2.0 is not an issue, it simply involves a line which multiplies matrices and vertices together.

// some code removed for this example. TransformedVertex = modelMatrix * currentVertex ; // The incoming vertex of a model is multiplied with the model’s transformation.

However if we ever decide to use the stack for a hierarchical structure, such as scenegraph, emulating the stack in 2.0 would likely be too slow in JavaScript and too awkward in shaders.  However, I suspect there would be preference over awkwardness if it can be done as speed is always a concern.

The next issue which is more pertinent is that of lighting. I had the task of making the 2.0 context behave identically to that of 1.1. This included getting textures working, the camera, ambient lighting, etc. The task which poses the greatest challenge is creating a way for users to create point, direction and spotlights in 2.0. In a shader, it is possible to query the OpenGLES light states using the gl_LightSource[] array, but actually setting the states using the 2.0 context isn’t provided, so this built-in variable isn’t much use. This means a structure which contains light information must be created and maintained in JavaScript, which users will be able to set.  When the scene is rendered, the light structures in the shader will be set to the values from the JavaScript code.  Then when drawing vertices, iterate over the lights and compute the final colour of the vertices.

Categories
c3dl development
Comments rss
Comments rss

« Documentation Generators Some text to look forward to »

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Search

Demos

  • Explorer
  • Flickr - Picking
  • FSOSS Pictures
  • Puzzler
  • Ricochet
  • Typing Game V2.1
  • Typing Game V3 (0.3 Release)

C3DL Development News

Namespaces and const

As our library expands with more functions, classes and global variables, the need for namespacing increases.  I started placing code in a C3DL namespace when I wrote the matrix stack operations.  However, yesterday I was looking in the constants.js file and saw the ‘tolerance’ variable.  It’s a const variable used when comparing floats to check [...]

DAE Scenegraph

We have code which parses collada/DAE files, but to a limited degree. The parser only extracts the geometry data. Therefore if a file is ‘simple’, it loads correctly since the scene graph has only one transform node. However if the collada file contains many transform nodes, each node with different geometry will be [...]

Tutorials

  • Tutorial #1: Installing Canvas 3D Addon
  • Tutorial #2: A Scene and a Cube
  • Tutorial #3: Update Callback
  • Tutorial #4: Models 101

Archives

C3DL Development News

Recent Comments

  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • Namespaces and const
  • DAE Scenegraph
  • The Matrix Stack
  • .obj to .dae
  • 0.5 Release and Other News!
  • Tracemonkey performance
  • More memory usage improvements
  • Canvas3D crashes in tracemonkey
  • Patched one hole in floating text
  • Drawering on a texture 2D canvas
  • For name spaces, my... - Jeremy Giberson
  • Great! Really really... - Edson Mattos
  • Beautiful!... - Funtomas
  • Was no need to conta... - Andrew Smith
  • Andrew, have you con... - Funtomas
  • Thanks for posting t... - Andrew Smith
  • Vlad was in town and... - Cathy Leung
  • the upside down issu... - Cathy Leung
  • Got it! the addon is... - Bill Mill
  • Yes it does. The ad... - Cathy Leung



Canvas 3d JS Library

©2007- 2008 Canvas 3d JS Library

Disclaimer: This website is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 Canada License.
The Canvas 3d JS Library and Demos found on this website are licenced under the MIT License

Creative Commons License