Package fcagnin.jglsdk.glutil

Examples of fcagnin.jglsdk.glutil.MatrixStack


        float vOffset = (float) (Math.sin( cyclicAngle ) * 0.25f);

        final Mat4 worldToCamMat = Glm.lookAt( new Vec3( hOffset, 1.0f, -64.0f ),
                new Vec3( hOffset, -5.0f + vOffset, -44.0f ), new Vec3( 0.0f, 1.0f, 0.0f ) );

        MatrixStack modelMatrix = new MatrixStack();
        modelMatrix.applyMatrix( worldToCamMat );

        final ProgramData prog = drawGammaProgram ? progGamma : progNoGamma;

        glUseProgram( prog.theProgram );
        glUniformMatrix4( prog.modelToCameraMatrixUnif, false, modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );

        glActiveTexture( GL_TEXTURE0 + colorTexUnit );
        glBindTexture( GL_TEXTURE_2D, drawGammaTexture ? gammaTexture : linearTexture );
        glBindSampler( colorTexUnit, samplers[currSampler] );

View Full Code Here


        glUseProgram( 0 );
    }

    @Override
    protected void reshape(int w, int h) {
        MatrixStack persMatrix = new MatrixStack();
        persMatrix.perspective( 90.0f, (w / (float) h), zNear, zFar );

        ProjectionBlock projData = new ProjectionBlock();
        projData.cameraToClipMatrix = persMatrix.top();

        glBindBuffer( GL_UNIFORM_BUFFER, projectionUniformBuffer );
        glBufferSubData( GL_UNIFORM_BUFFER, 0, projData.fillAndFlipBuffer( mat4Buffer ) );
        glBindBuffer( GL_UNIFORM_BUFFER, 0 );
View Full Code Here

        }
    }

    @Override
    protected void reshape(int w, int h) {
        MatrixStack persMatrix = new MatrixStack();
        persMatrix.perspective( 45.0f, (w / (float) h), zNear, zFar );

        ProjectionBlock projData = new ProjectionBlock();
        projData.cameraToClipMatrix = persMatrix.top();

        glBindBuffer( GL_UNIFORM_BUFFER, projectionUniformBuffer );
        glBufferSubData( GL_UNIFORM_BUFFER, 0, projData.cameraToClipMatrix.fillAndFlipBuffer( mat4Buffer ) );
        glBindBuffer( GL_UNIFORM_BUFFER, 0 );
View Full Code Here

        Vec4 bgColor = lightEnv.getBackgroundColor();
        glClearColor( bgColor.x, bgColor.y, bgColor.z, bgColor.w );
        glClearDepth( 1.0f );
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

        MatrixStack modelMatrix = new MatrixStack();
        modelMatrix.applyMatrix( viewPole.calcMatrix() );

        LightBlock lightData = lightEnv.getLightBlock( viewPole.calcMatrix() );

        glBindBuffer( GL_UNIFORM_BUFFER, lightUniformBuffer );
        glBufferData( GL_UNIFORM_BUFFER, lightData.fillAndFlipBuffer( lightBlockBuffer ), GL_STREAM_DRAW );
        glBindBuffer( GL_UNIFORM_BUFFER, 0 );

        modelMatrix.push();
        modelMatrix.rotateX( -90.0f );

        glUseProgram( progStandard.theProgram );
        glUniformMatrix4( progStandard.modelToCameraMatrixUnif, false,
                modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
        glUniform1i( progStandard.numberOfLightsUnif, lightEnv.getNumLights() );

        glActiveTexture( GL_TEXTURE0 + colorTexUnit );
        glBindTexture( GL_TEXTURE_2D, linearTexture );
        glBindSampler( colorTexUnit, samplers[currSampler] );

        terrain.render( "lit-tex" );

        glBindSampler( colorTexUnit, 0 );
        glBindTexture( GL_TEXTURE_2D, 0 );

        glUseProgram( 0 );

        modelMatrix.pop();

        // Render the sun
        {
            modelMatrix.push();

            Vec3 sunlightDir = new Vec3( lightEnv.getSunlightDirection() );
            modelMatrix.translate( sunlightDir.scale( 500.0f ) );
            modelMatrix.scale( 30.0f, 30.0f, 30.0f );

            glUseProgram( progUnlit.theProgram );
            glUniformMatrix4( progUnlit.modelToCameraMatrixUnif, false,
                    modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );

            Vec4 lightColor = lightEnv.getSunlightScaledIntensity();
            glUniform4( progUnlit.objectColorUnif, lightColor.fillAndFlipBuffer( vec4Buffer ) );
            sphere.render( "flat" );

            modelMatrix.pop();
        }

        // Draw lights
        for ( int light = 0; light < lightEnv.getNumPointLights(); light++ ) {
            modelMatrix.push();

            modelMatrix.translate( lightEnv.getPointLightWorldPos( light ) );

            glUseProgram( progUnlit.theProgram );
            glUniformMatrix4( progUnlit.modelToCameraMatrixUnif, false,
                    modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );

            Vec4 lightColor = lightEnv.getPointLightScaledIntensity( light );
            glUniform4( progUnlit.objectColorUnif, lightColor.fillAndFlipBuffer( vec4Buffer ) );
            sphere.render( "flat" );

            modelMatrix.pop();
        }

        if ( drawCameraPos ) {
            modelMatrix.push();

            // Draw lookat point.
            modelMatrix.setIdentity();
            modelMatrix.translate( 0.0f, 0.0f, -viewPole.getView().radius );

            glDisable( GL_DEPTH_TEST );
            glDepthMask( false );
            glUseProgram( progUnlit.theProgram );
            glUniformMatrix4( progUnlit.modelToCameraMatrixUnif, false,
                    modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
            glUniform4f( progUnlit.objectColorUnif, 0.25f, 0.25f, 0.25f, 1.0f );
            sphere.render( "flat" );
            glDepthMask( true );
            glEnable( GL_DEPTH_TEST );
            glUniform4f( progUnlit.objectColorUnif, 1.0f, 1.0f, 1.0f, 1.0f );
            sphere.render( "flat" );

            modelMatrix.pop();
        }
    }
View Full Code Here

        }
    }

    @Override
    protected void reshape(int w, int h) {
        MatrixStack persMatrix = new MatrixStack();
        persMatrix.perspective( 60.0f, (w / (float) h), zNear, zFar );

        ProjectionBlock projData = new ProjectionBlock();
        projData.cameraToClipMatrix = persMatrix.top();

        glBindBuffer( GL_UNIFORM_BUFFER, projectionUniformBuffer );
        glBufferSubData( GL_UNIFORM_BUFFER, 0, projData.fillAndFlipBuffer( mat4Buffer ) );
        glBindBuffer( GL_UNIFORM_BUFFER, 0 );
View Full Code Here

    protected void display() {
        glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
        glClearDepth( 1.0f );
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

        MatrixStack modelMatrix = new MatrixStack();
        modelMatrix.setMatrix( viewPole.calcMatrix() );

        Vec4 lightDirCameraSpace = Mat4.mul( modelMatrix.top(), lightDirection );

        glUseProgram( whiteDiffuseColor.theProgram );
        glUniform3( whiteDiffuseColor.dirToLightUnif, lightDirCameraSpace.fillAndFlipBuffer( vec4Buffer ) );
        glUseProgram( vertexDiffuseColor.theProgram );
        glUniform3( vertexDiffuseColor.dirToLightUnif, lightDirCameraSpace.fillAndFlipBuffer( vec4Buffer ) );
        glUseProgram( 0 );

        {
            modelMatrix.push();

            // Render the ground plane.
            {
                modelMatrix.push();

                glUseProgram( whiteDiffuseColor.theProgram );
                glUniformMatrix4( whiteDiffuseColor.modelToCameraMatrixUnif, false,
                        modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
                Mat3 normMatrix = new Mat3( modelMatrix.top() );
                glUniformMatrix3( whiteDiffuseColor.normalModelToCameraMatrixUnif, false,
                        normMatrix.fillAndFlipBuffer( mat3Buffer ) );
                glUniform4f( whiteDiffuseColor.lightIntensityUnif, 1.0f, 1.0f, 1.0f, 1.0f );
                planeMesh.render();
                glUseProgram( 0 );

                modelMatrix.pop();
            }

            // Render the Cylinder
            {
                modelMatrix.push();

                modelMatrix.applyMatrix( objtPole.calcMatrix() );

                if ( scaleCyl ) {
                    modelMatrix.scale( 1.0f, 1.0f, 0.2f );
                }

                glUseProgram( vertexDiffuseColor.theProgram );
                glUniformMatrix4( vertexDiffuseColor.modelToCameraMatrixUnif, false,
                        modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
                Mat3 normMatrix = new Mat3( modelMatrix.top() );
                if ( doInvTranspose ) {
                    normMatrix = Glm.transpose( Glm.inverse( normMatrix ) );
                }
                glUniformMatrix3( vertexDiffuseColor.normalModelToCameraMatrixUnif, false,
                        normMatrix.fillAndFlipBuffer( mat3Buffer ) );
                glUniform4f( vertexDiffuseColor.lightIntensityUnif, 1.0f, 1.0f, 1.0f, 1.0f );
                cylinderMesh.render( "lit-color" );
                glUseProgram( 0 );

                modelMatrix.pop();
            }

            modelMatrix.pop();
        }
    }
View Full Code Here

        }
    }

    @Override
    protected void reshape(int w, int h) {
        MatrixStack persMatrix = new MatrixStack();
        persMatrix.perspective( 45.0f, (w / (float) h), zNear, zFar );

        ProjectionBlock projData = new ProjectionBlock();
        projData.cameraToClipMatrix = persMatrix.top();

        glBindBuffer( GL_UNIFORM_BUFFER, projectionUniformBuffer );
        glBufferSubData( GL_UNIFORM_BUFFER, 0, projData.fillAndFlipBuffer( mat4Buffer ) );
        glBindBuffer( GL_UNIFORM_BUFFER, 0 );
View Full Code Here

    protected void display() {
        glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
        glClearDepth( 1.0f );
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

        MatrixStack modelMatrix = new MatrixStack();
        modelMatrix.setMatrix( viewPole.calcMatrix() );

        Vec4 lightDirCameraSpace = Mat4.mul( modelMatrix.top(), lightDirection );

        ProgramData whiteDiffuse = showAmbient ? whiteAmbDiffuseColor : whiteDiffuseColor;
        ProgramData vertexDiffuse = showAmbient ? vertexAmbDiffuseColor : vertexDiffuseColor;

        if ( showAmbient ) {
            glUseProgram( whiteDiffuse.theProgram );
            glUniform4f( whiteDiffuse.lightIntensityUnif, 0.8f, 0.8f, 0.8f, 1.0f );
            glUniform4f( whiteDiffuse.ambientIntensityUnif, 0.2f, 0.2f, 0.2f, 1.0f );
            glUseProgram( vertexDiffuse.theProgram );
            glUniform4f( vertexDiffuse.lightIntensityUnif, 0.8f, 0.8f, 0.8f, 1.0f );
            glUniform4f( vertexDiffuse.ambientIntensityUnif, 0.2f, 0.2f, 0.2f, 1.0f );
        } else {
            glUseProgram( whiteDiffuse.theProgram );
            glUniform4f( whiteDiffuse.lightIntensityUnif, 1.0f, 1.0f, 1.0f, 1.0f );
            glUseProgram( vertexDiffuse.theProgram );
            glUniform4f( vertexDiffuse.lightIntensityUnif, 1.0f, 1.0f, 1.0f, 1.0f );
        }

        glUseProgram( whiteDiffuse.theProgram );
        glUniform3( whiteDiffuse.dirToLightUnif, lightDirCameraSpace.fillAndFlipBuffer( vec4Buffer ) );
        glUseProgram( vertexDiffuse.theProgram );
        glUniform3( vertexDiffuse.dirToLightUnif, lightDirCameraSpace.fillAndFlipBuffer( vec4Buffer ) );
        glUseProgram( 0 );

        {
            modelMatrix.push();

            // Render the ground plane.
            {
                modelMatrix.push();

                glUseProgram( whiteDiffuse.theProgram );
                glUniformMatrix4( whiteDiffuse.modelToCameraMatrixUnif, false,
                        modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
                Mat3 normMatrix = new Mat3( modelMatrix.top() );
                glUniformMatrix3( whiteDiffuse.normalModelToCameraMatrixUnif, false,
                        normMatrix.fillAndFlipBuffer( mat3Buffer ) );
                planeMesh.render();
                glUseProgram( 0 );

                modelMatrix.pop();
            }

            // Render the Cylinder
            {
                modelMatrix.push();

                modelMatrix.applyMatrix( objtPole.calcMatrix() );

                if ( drawColoredCyl ) {
                    glUseProgram( vertexDiffuse.theProgram );
                    glUniformMatrix4( vertexDiffuse.modelToCameraMatrixUnif, false,
                            modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
                    Mat3 normMatrix = new Mat3( modelMatrix.top() );
                    glUniformMatrix3( vertexDiffuse.normalModelToCameraMatrixUnif, false,
                            normMatrix.fillAndFlipBuffer( mat3Buffer ) );
                    cylinderMesh.render( "lit-color" );
                } else {
                    glUseProgram( whiteDiffuse.theProgram );
                    glUniformMatrix4( whiteDiffuse.modelToCameraMatrixUnif, false,
                            modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
                    Mat3 normMatrix = new Mat3( modelMatrix.top() );
                    glUniformMatrix3( whiteDiffuse.normalModelToCameraMatrixUnif, false,
                            normMatrix.fillAndFlipBuffer( mat3Buffer ) );
                    cylinderMesh.render( "lit" );
                }
                glUseProgram( 0 );

                modelMatrix.pop();
            }

            modelMatrix.pop();
        }
    }
View Full Code Here

        }
    }

    @Override
    protected void reshape(int w, int h) {
        MatrixStack persMatrix = new MatrixStack();
        persMatrix.perspective( 45.0f, (w / (float) h), zNear, zFar );

        ProjectionBlock projData = new ProjectionBlock();
        projData.cameraToClipMatrix = persMatrix.top();

        glBindBuffer( GL_UNIFORM_BUFFER, projectionUniformBuffer );
        glBufferSubData( GL_UNIFORM_BUFFER, 0, projData.fillAndFlipBuffer( mat4Buffer ) );
        glBindBuffer( GL_UNIFORM_BUFFER, 0 );
View Full Code Here

    protected void display() {
        glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
        glClearDepth( 1.0f );
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

        MatrixStack modelMatrix = new MatrixStack();
        modelMatrix.setMatrix( viewPole.calcMatrix() );

        Vec4 lightDirCameraSpace = Mat4.mul( modelMatrix.top(), lightDirection );

        glUseProgram( whiteDiffuseColor.theProgram );
        glUniform3( whiteDiffuseColor.dirToLightUnif, lightDirCameraSpace.fillAndFlipBuffer( vec4Buffer ) );
        glUseProgram( vertexDiffuseColor.theProgram );
        glUniform3( vertexDiffuseColor.dirToLightUnif, lightDirCameraSpace.fillAndFlipBuffer( vec4Buffer ) );
        glUseProgram( 0 );

        {
            modelMatrix.push();

            // Render the ground plane.
            {
                modelMatrix.push();

                glUseProgram( whiteDiffuseColor.theProgram );
                glUniformMatrix4( whiteDiffuseColor.modelToCameraMatrixUnif, false,
                        modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
                Mat3 normMatrix = new Mat3( modelMatrix.top() );
                glUniformMatrix3( whiteDiffuseColor.normalModelToCameraMatrixUnif, false,
                        normMatrix.fillAndFlipBuffer( mat3Buffer ) );
                glUniform4f( whiteDiffuseColor.lightIntensityUnif, 1.0f, 1.0f, 1.0f, 1.0f );
                planeMesh.render();
                glUseProgram( 0 );

                modelMatrix.pop();
            }

            // Render the Cylinder
            {
                modelMatrix.push();

                modelMatrix.applyMatrix( objtPole.calcMatrix() );

                if ( drawColoredCyl ) {
                    glUseProgram( vertexDiffuseColor.theProgram );
                    glUniformMatrix4( vertexDiffuseColor.modelToCameraMatrixUnif, false,
                            modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
                    Mat3 normMatrix = new Mat3( modelMatrix.top() );
                    glUniformMatrix3( vertexDiffuseColor.normalModelToCameraMatrixUnif, false,
                            normMatrix.fillAndFlipBuffer( mat3Buffer ) );
                    glUniform4f( vertexDiffuseColor.lightIntensityUnif, 1.0f, 1.0f, 1.0f, 1.0f );
                    cylinderMesh.render( "lit-color" );
                } else {
                    glUseProgram( whiteDiffuseColor.theProgram );
                    glUniformMatrix4( whiteDiffuseColor.modelToCameraMatrixUnif, false,
                            modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
                    Mat3 normMatrix = new Mat3( modelMatrix.top() );
                    glUniformMatrix3( whiteDiffuseColor.normalModelToCameraMatrixUnif, false,
                            normMatrix.fillAndFlipBuffer( mat3Buffer ) );
                    glUniform4f( whiteDiffuseColor.lightIntensityUnif, 1.0f, 1.0f, 1.0f, 1.0f );
                    cylinderMesh.render( "lit" );
                }

                glUseProgram( 0 );

                modelMatrix.pop();
            }

            modelMatrix.pop();
        }
    }
View Full Code Here

TOP

Related Classes of fcagnin.jglsdk.glutil.MatrixStack

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.