HTML and CSS Reference
In-Depth Information
uniform mat4 uMVMatrix
;
uniform mat4 uPMatrix
;
varying vec4 vColor
;
void
void
main
(
void
void
) {
gl_Position
=
uPMatrix
*
uMVMatrix
*
vec4
(
aVertexPosition
,
1.0
);
vColor
=
aVertexColor
;
}
<
/script>
Testing for WebGL support with Modernizr
The structure of the code in this example is much like the other applications we have written
in this topic.However,ithasbeenmodifiedtoworkwiththespecificneedsofthe3Dcontext.
Inthe
canvasApp()
function, we need to test to see whether the browser has WebGL support.
This is easily accomplished by using the
Modernizr.webgl
static constant in Modernizr:
iif
(
!
webglSupport
()) {
alert
(
"Unable to initialize WebGL"
);
return
return
;
}
function
function
webglSupport
() {
return
return
Modernizr
.
webgl
;
}
Initialization in canvasApp()
In
canvasApp()
, we still get a context, but this time it is the
experimental-webgl
context.
Also, just like in our other apps, we still call
drawScreen()
on an interval to render the can-
vas:
var
var
theCanvas
=
document
.
getElementById
(
"canvasOne"
);
webGLContext
=
theCanvas
.
getContext
(
"experimental-webgl"
);
setInterval
(
drawScreen
,
33
);
However, there is additional code in
canvasApp()
required to set up the application to rotate
the cube. A couple of the most important initialization steps are the calls to
initShaders()
and
initBuffers()
:
initShaders
();
initBuffers
();