コード例 #1
0
ファイル: lesson09.js プロジェクト: dg14/node-opengl
skel.onResize = function() {
    // resize.
    gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
    gl.matrixMode(gl.PROJECTION);
    gl.loadIdentity();
    glu.perspective(45, gl.viewportWidth / gl.viewportHeight, 0.1, 100.0);
    gl.matrixMode(gl.MODELVIEW);
    gl.loadIdentity();
}
コード例 #2
0
ファイル: lesson09.js プロジェクト: dg14/node-opengl
skel.onDrawScene = function() {
    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
    gl.bindTexture(gl.TEXTURE_2D, texture[0]);
    for (var loop=0;loop<STAR_NUM;loop++) {
        gl.loadIdentity();
        gl.translatef(0.0, 0.0,zoom);
        gl.rotatef(tilt, 1.0, 0.0, 0.0);
        gl.rotatef(star[loop].angle,0.0, 1.0,0.0);
        gl.translatef(star[loop].dist, 0.0, 0.0);
        gl.rotatef(-star[loop].dist,0.0,1.0,0.0);
        gl.rotatef(-tilt, 1.0,0.0,0.0);

        if (twinkle) {
            console.log(STAR_NUM-loop);
            console.log(loop);
            console.log(STAR_NUM);
            gl.color4ub(star[STAR_NUM-loop-1].r, star[STAR_NUM-loop-1].g, star[STAR_NUM-loop-1].b, 255);
            gl.begin(gl.QUADS);
            gl.texCoords2f(0.0,0.0); gl.vertex3f(-1.0, -1.0,0.0);
            gl.texCoords2f(1.0,0.0); gl.vertex3f( 1.0, -1.0,0.0);
            gl.texCoords2f(1.0,1.0); gl.vertex3f( 1.0,  1.0,0.0);
            gl.texCoords2f(0.0,1.0); gl.vertex3f(-1.0,  1.0,0.0);
            gl.end();

        }
        gl.rotatef(spin, 0.0, 0.0, 1.0);
        gl.color4ub(star[loop].r, star[loop].g, star[loop].b,255);
        gl.begin(gl.QUADS);          // Begin Drawing The Textured Quad
        gl.texCoord2f(0.0, 0.0); gl.vertex3f(-1.0,-1.0, 0.0);
        gl.texCoord2f(1.0, 0.0); gl.vertex3f( 1.0,-1.0, 0.0);
        gl.texCoord2f(1.0, 1.0); gl.vertex3f( 1.0, 1.0, 0.0);
        gl.texCoord2f(0.0, 1.0); gl.vertex3f(-1.0, 1.0, 0.0);
        gl.end();                // Done Drawing The Textured Quad

        spin +=0.01;                           // used to spin the stars.
        star[loop].angle += loop * 1.0 / STAR_NUM * 1.0;    // change star angle.
        star[loop].dist  -= 0.01;              // bring back to center.

        if (star[loop].dist<0.0) {             // star hit the center
            star[loop].dist += 5.0;            // move 5 units from the center.
            star[loop].r = Math.round(Math.random() *256);        // new red color.
            star[loop].g = Math.round(Math.random() * 256);        // new green color.
            star[loop].b = Math.round(Math.random() * 256);        // new blue color.
        }

    }
    requestAnimationFrame(skel.onDrawScene);
}
コード例 #3
0
ファイル: lesson09.js プロジェクト: dg14/node-opengl
skel.onInitScene = function() {
    // init.
    loadTextures();
    gl.enable(gl.TEXTURE_2D);    
    gl.clearColor(0.0, 0.0, 0.0, 0.5);
    gl.clearDepth(1.0);
    gl.shadeModel(gl.SMOOTH);
    gl.matrixMode(gl.PROJECTION);
    gl.loadIdentity();
    glu.perspective(45, gl.viewportWidth / gl.viewportHeight, 0.1, 100.0);
    gl.matrixMode(gl.MODELVIEW);
    gl.blendFunc(gl.SRC_ALPHA,gl.ONE);
    gl.enable(gl.BLEND);
    for (loop=0;loop<50;loop++) {
        star[loop]= {
            angle: 0.0,
            dist: loop*1.0/STAR_NUM*5.0,
            r: Math.round(Math.random()*256),
            g: Math.round(Math.random()*256),            
            b: Math.round(Math.random()*256)
        };
    }

}
コード例 #4
0
ファイル: lesson06_keys.js プロジェクト: dg14/node-opengl
skel.onDrawScene = function() {
    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
    gl.loadIdentity(); // Reset The View
    gl.translatef(0.0, 0.0, -5.0);
    gl.translatef(x, y, z);
    gl.rotatef(xrot, 1.0, 0.0, 0.0);
    gl.rotatef(yrot, 0.0, 1.0, 0.0);
    gl.rotatef(zrot, 0.0, 0.0, 1.0);
    gl.bindTexture(gl.TEXTURE_2D, texture);
    gl.begin(gl.QUADS);
    // Front Face
    gl.texCoord2f(0.0, 0.0);
    gl.vertex3f(-1.0, -1.0, 1.0);
    gl.texCoord2f(1.0, 0.0);
    gl.vertex3f(1.0, -1.0, 1.0);
    gl.texCoord2f(1.0, 1.0);
    gl.vertex3f(1.0, 1.0, 1.0);
    gl.texCoord2f(0.0, 1.0);
    gl.vertex3f(-1.0, 1.0, 1.0);
    // Back Face
    gl.texCoord2f(1.0, 0.0);
    gl.vertex3f(-1.0, -1.0, -1.0);
    gl.texCoord2f(1.0, 1.0);
    gl.vertex3f(-1.0, 1.0, -1.0);
    gl.texCoord2f(0.0, 1.0);
    gl.vertex3f(1.0, 1.0, -1.0);
    gl.texCoord2f(0.0, 0.0);
    gl.vertex3f(1.0, -1.0, -1.0);
    // Top Face
    gl.texCoord2f(0.0, 1.0);
    gl.vertex3f(-1.0, 1.0, -1.0);
    gl.texCoord2f(0.0, 0.0);
    gl.vertex3f(-1.0, 1.0, 1.0);
    gl.texCoord2f(1.0, 0.0);
    gl.vertex3f(1.0, 1.0, 1.0);
    gl.texCoord2f(1.0, 1.0);
    gl.vertex3f(1.0, 1.0, -1.0);
    // Bottom Face
    gl.texCoord2f(1.0, 1.0);
    gl.vertex3f(-1.0, -1.0, -1.0);
    gl.texCoord2f(0.0, 1.0);
    gl.vertex3f(1.0, -1.0, -1.0);
    gl.texCoord2f(0.0, 0.0);
    gl.vertex3f(1.0, -1.0, 1.0);
    gl.texCoord2f(1.0, 0.0);
    gl.vertex3f(-1.0, -1.0, 1.0);
    // Right face
    gl.texCoord2f(1.0, 0.0);
    gl.vertex3f(1.0, -1.0, -1.0);
    gl.texCoord2f(1.0, 1.0);
    gl.vertex3f(1.0, 1.0, -1.0);
    gl.texCoord2f(0.0, 1.0);
    gl.vertex3f(1.0, 1.0, 1.0);
    gl.texCoord2f(0.0, 0.0);
    gl.vertex3f(1.0, -1.0, 1.0);
    // Left Face
    gl.texCoord2f(0.0, 0.0);
    gl.vertex3f(-1.0, -1.0, -1.0);
    gl.texCoord2f(1.0, 0.0);
    gl.vertex3f(-1.0, -1.0, 1.0);
    gl.texCoord2f(1.0, 1.0);
    gl.vertex3f(-1.0, 1.0, 1.0);
    gl.texCoord2f(0.0, 1.0);
    gl.vertex3f(-1.0, 1.0, -1.0);
    gl.end();
    if (rotate) {
        xrot += 0.3;
        yrot += 0.2;
        zrot += 0.4;
    }
    requestAnimationFrame(skel.onDrawScene);
}
コード例 #5
0
ファイル: lesson20.js プロジェクト: dg14/node-opengl
skel.onDrawScene = function() {
    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer    
    gl.loadIdentity(); // Reset The Modelview Matrix
    gl.translatef(0.0, 0.0, -2.0); // Move Into The Screen 5 Units
    gl.bindTexture(gl.TEXTURE_2D, texture[0]); // Select Our Logo Texture
    gl.begin(gl.QUADS); // Start Drawing A Textured Quad
    gl.texCoord2f(0.0, -roll + 0.0);
    gl.vertex3f(-1.1, -1.1, 0.0); // Bottom Left
    gl.texCoord2f(3.0, -roll + 0.0);
    gl.vertex3f(1.1, -1.1, 0.0); // Bottom Right
    gl.texCoord2f(3.0, -roll + 3.0);
    gl.vertex3f(1.1, 1.1, 0.0); // Top Right
    gl.texCoord2f(0.0, -roll + 3.0);
    gl.vertex3f(-1.1, 1.1, 0.0); // Top Left
    gl.end(); // Done Drawing The Quad
    gl.enable(gl.BLEND); // Enable Blending
    gl.disable(gl.DEPTH_TEST); // Disable Depth Testing
    if (masking) // Is Masking Enabled?
    {
        gl.blendFunc(gl.DST_COLOR, gl.ZERO); // Blend Screen Color With Zero (Black)
    }
    if (scene) // Are We Drawing The Second Scene?
    {
        gl.translatef(0.0, 0.0, -1.0); // Translate Into The Screen One Unit
        gl.rotatef(roll * 360, 0.0, 0.0, 1.0); // Rotate On The Z Axis 360 Degrees.
        if (masking) // Is Masking On?
        {
            gl.bindTexture(gl.TEXTURE_2D, texture[3]); // Select The Second Mask Texture
            gl.begin(gl.QUADS); // Start Drawing A Textured Quad
            gl.texCoord2f(0.0, 0.0);
            gl.vertex3f(-1.1, -1.1, 0.0); // Bottom Left
            gl.texCoord2f(1.0, 0.0);
            gl.vertex3f(1.1, -1.1, 0.0); // Bottom Right
            gl.texCoord2f(1.0, 1.0);
            gl.vertex3f(1.1, 1.1, 0.0); // Top Right
            gl.texCoord2f(0.0, 1.0);
            gl.vertex3f(-1.1, 1.1, 0.0); // Top Left
            gl.end(); // Done Drawing The Quad
        }
        gl.blendFunc(gl.ONE, gl.ONE); // Copy Image 2 Color To The Screen
        gl.bindTexture(gl.TEXTURE_2D, texture[4]); // Select The Second Image Texture
        gl.begin(gl.QUADS); // Start Drawing A Textured Quad
        gl.texCoord2f(0.0, 0.0);
        gl.vertex3f(-1.1, -1.1, 0.0); // Bottom Left
        gl.texCoord2f(1.0, 0.0);
        gl.vertex3f(1.1, -1.1, 0.0); // Bottom Right
        gl.texCoord2f(1.0, 1.0);
        gl.vertex3f(1.1, 1.1, 0.0); // Top Right
        gl.texCoord2f(0.0, 1.0);
        gl.vertex3f(-1.1, 1.1, 0.0); // Top Left
        gl.end(); // Done Drawing The Quad
    } else // Otherwise
    {
        if (masking) // Is Masking On?
        {
            gl.bindTexture(gl.TEXTURE_2D, texture[1]); // Select The First Mask Texture
            gl.begin(gl.QUADS); // Start Drawing A Textured Quad
            gl.texCoord2f(roll + 0.0, 0.0);
            gl.vertex3f(-1.1, -1.1, 0.0); // Bottom Left
            gl.texCoord2f(roll + 4.0, 0.0);
            gl.vertex3f(1.1, -1.1, 0.0); // Bottom Right
            gl.texCoord2f(roll + 4.0, 4.0);
            gl.vertex3f(1.1, 1.1, 0.0); // Top Right
            gl.texCoord2f(roll + 0.0, 4.0);
            gl.vertex3f(-1.1, 1.1, 0.0); // Top Left
            gl.end(); // Done Drawing The Quad
        }
        gl.blendFunc(gl.ONE, gl.ONE); // Copy Image 1 Color To The Screen
        gl.bindTexture(gl.TEXTURE_2D, texture[2]); // Select The First Image Texture
        gl.begin(gl.QUADS); // Start Drawing A Textured Quad
        gl.texCoord2f(roll + 0.0, 0.0);
        gl.vertex3f(-1.1, -1.1, 0.0); // Bottom Left
        gl.texCoord2f(roll + 4.0, 0.0);
        gl.vertex3f(1.1, -1.1, 0.0); // Bottom Right
        gl.texCoord2f(roll + 4.0, 4.0);
        gl.vertex3f(1.1, 1.1, 0.0); // Top Right
        gl.texCoord2f(roll + 0.0, 4.0);
        gl.vertex3f(-1.1, 1.1, 0.0); // Top Left
        gl.end(); // Done Drawing The Quad
    }
    gl.enable(gl.DEPTH_TEST); // Enable Depth Testing
    gl.disable(gl.BLEND); // Disable Blending
    roll += 0.002; // Increase Our Texture Roll Variable
    if (roll > 1.0) // Is Roll Greater Than One
    {
        roll -= 1.0; // Subtract 1 From Roll
    }
    requestAnimationFrame(skel.onDrawScene);
}