View Full Version : Drawing WebGL back to 2D Canvas

02-17-2011, 08:41 PM

I can draw some textures (use 2D canvas) in WebGL. However, I encounter another problem. If I want to rotate the object in WebGL and then draw the current view (after rotation) in 2D canvas, how can I implement it well? Is is possible for me to pass the WebGL object or just the view of WebGL object to 2D canvas?

Thanks for your help.

02-18-2011, 11:55 AM
To get rotation you will need to add to your vertex shader the modelview and projection matrices.

uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;

void main(void) {
gl_Position = uPMatrix * uMVMatrix * vec4(Position, 1.0);

and then update them just before drawing your scene

function setMatrixUniforms() {
gl.uniformMatrix4fv(shaderProgram.pMatrixUniform, false, new Float32Array(pMatrix.flatten()));
gl.uniformMatrix4fv(shaderProgram.mvMatrixUniform, false, new Float32Array(mvMatrix.flatten()));

Post283954 (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=283954#Post2839 54) shows more detail of this in conjunction with mouse motion ...