Drawing WebGL back to 2D Canvas

Hi,

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.

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 shows more detail of this in conjunction with mouse motion …