Created
May 28, 2012 04:57
-
-
Save goofmint/2817307 to your computer and use it in GitHub Desktop.
JSGL demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gl = new GL.Context( w, h ); | |
gl.enable( GL.TEXTURE_2D ); | |
gl.enable( GL.DEPTH_TEST ); | |
gl.clearColor( 0.0, 0.0, 0.0, 1.0 ); | |
gl.clearDepth( 1.0 ); | |
// Load grass texture | |
var tex = []; | |
gl.genTextures( 1, tex ); | |
gl.bindTexture( GL.TEXTURE_2D, tex[0] ); | |
gl.texImage2D( GL.TEXTURE_2D, 48, 16, GL.FLOAT, grassTexture ); | |
// Draw animation | |
var buf = ctx.createImageData( w, h ); | |
var frames = 0; | |
setInterval( function() | |
{ | |
var t = +new Date() / 1000; | |
gl.clear( GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT ); | |
gl.matrixMode( GL.MODELVIEW ); | |
gl.loadIdentity(); | |
gl.lookAt( 2, 2, 2, 0, 0, 0, 0, 0, 1 ); | |
gl.rotatef( t/2, 0, 0, 1 ); | |
gl.translatef( -0.5, -0.5, -0.2 ); | |
gl.matrixMode( GL.PROJECTION ); | |
gl.loadIdentity(); | |
gl.perspective( 90*h/w, w/h, 1, 4 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment