Package fcagnin.jglsdk.glutil

Examples of fcagnin.jglsdk.glutil.MatrixStack


        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

        final Mat4 cameraMatrix = viewPole.calcMatrix();
        final Mat4 lightView = lightPole.calcMatrix();

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

        buildLights( cameraMatrix );

        nodes.get( 0 ).nodeSetOrient( Glm.rotate( new Quaternion( 1.0f ), 360.0f * timer.getAlpha(),
                new Vec3( 0.0f, 1.0f, 0.0f ) ) );

        nodes.get( 3 ).nodeSetOrient( Quaternion.mul( spinBarOrient, Glm.rotate( new Quaternion( 1.0f ),
                360.0f * timer.getAlpha(), new Vec3( 0.0f, 0.0f, 1.0f ) ) ) );

        {
            MatrixStack persMatrix = new MatrixStack();
            persMatrix.perspective( 60.0f, displayWidth / (float) displayHeight, zNear, zFar );

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

            glBindBuffer( GL_UNIFORM_BUFFER, projectionUniformBuffer );
            glBufferData( GL_UNIFORM_BUFFER, projData.fillAndFlipBuffer( mat4Buffer ), GL_STREAM_DRAW );
            glBindBuffer( GL_UNIFORM_BUFFER, 0 );
        }

        glActiveTexture( GL_TEXTURE0 + lightProjTexUnit );
        glBindTexture( GL_TEXTURE_CUBE_MAP, lightTextures[currTextureIndex] );
        glBindSampler( lightProjTexUnit, samplers[currSampler] );

        {
            MatrixStack lightProjStack = new MatrixStack();
            lightProjStack.applyMatrix( Glm.inverse( lightView ) );
            lightProjStack.applyMatrix( Glm.inverse( cameraMatrix ) );

            lightProjMatBinder.setValue( lightProjStack.top() );

            Vec4 worldLightPos = lightView.getColumn( 3 );
            Vec3 lightPos = new Vec3( Mat4.mul( cameraMatrix, worldLightPos ) );

            camLightPosBinder.setValue( lightPos );
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

        glClearColor( 0.75f, 0.75f, 1.0f, 1.0f );
        glClearDepth( 1.0f );
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

        MatrixStack modelMatrix = new MatrixStack();
        modelMatrix.setMatrix( viewPole.calcMatrix() );
        final Mat4 worldToCamMat = modelMatrix.top();

        LightBlock lightData = new LightBlock();
        lightData.ambientIntensity = new Vec4( 0.2f, 0.2f, 0.2f, 1.0f );
        float lightAttenuation = 1.0f / (halfLightDistance * halfLightDistance);
        lightData.lightAttenuation = lightAttenuation;

        lightData.lights[0] = new PerLight();
        lightData.lights[0].cameraSpaceLightPos = Mat4.mul( worldToCamMat, new Vec4( 0.707f, 0.707f, 0.0f, 0.0f ) );
        lightData.lights[0].lightIntensity = new Vec4( 0.6f, 0.6f, 0.6f, 1.0f );

        lightData.lights[1] = new PerLight();
        lightData.lights[1].cameraSpaceLightPos = Mat4.mul( worldToCamMat, calcLightPosition() );
        lightData.lights[1].lightIntensity = new Vec4( 0.4f, 0.4f, 0.4f, 1.0f );

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

        {
            glBindBufferRange( GL_UNIFORM_BUFFER, materialBlockIndex, materialUniformBuffer,
                    MaterialNames.TERRAIN.ordinal() * materialBlockOffset, MaterialBlock.SIZE );

            Mat3 normMatrix = new Mat3( modelMatrix.top() );
            normMatrix = Glm.transpose( Glm.inverse( normMatrix ) );

            glUseProgram( litMeshProg.theProgram );
            glUniformMatrix4( litMeshProg.modelToCameraMatrixUnif, false,
                    modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
            glUniformMatrix3( litMeshProg.normalModelToCameraMatrixUnif, false,
                    normMatrix.fillAndFlipBuffer( mat3Buffer ) );

            planeMesh.render();

            glUseProgram( 0 );
            glBindBufferBase( GL_UNIFORM_BUFFER, materialBlockIndex, 0 );
        }

        drawSphere( modelMatrix, new Vec3( 0.0f, 10.0f, 0.0f ), 4.0f, MaterialNames.BLUE_SHINY, drawImposter[0] );
        drawSphereOrbit( modelMatrix, new Vec3( 0.0f, 10.0f, 0.0f ), new Vec3( 0.6f, 0.8f, 0.0f ), 20.0f,
                sphereTimer.getAlpha(), 2.0f, MaterialNames.DULL_GREY, drawImposter[1] );
        drawSphereOrbit( modelMatrix, new Vec3( -10.0f, 1.0f, 0.0f ), new Vec3( 0.0f, 1.0f, 0.0f ), 10.0f,
                sphereTimer.getAlpha(), 1.0f, MaterialNames.BLACK_SHINY, drawImposter[2] );
        drawSphereOrbit( modelMatrix, new Vec3( 10.0f, 1.0f, 0.0f ), new Vec3( 0.0f, 1.0f, 0.0f ), 10.0f,
                sphereTimer.getAlpha() * 2.0f, 1.0f, MaterialNames.GOLD_METAL, drawImposter[3] );

        if ( drawLights ) {
            modelMatrix.push();

            modelMatrix.translate( new Vec3( calcLightPosition() ) );
            modelMatrix.scale( 0.5f );

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

            Vec4 lightColor = new Vec4( 1.0f );
            glUniform4( unlit.objectColorUnif, lightColor.fillAndFlipBuffer( vec4Buffer ) );
            cubeMesh.render( "flat" );

            modelMatrix.pop();
        }

        if ( drawCameraPos ) {
            modelMatrix.push();

            modelMatrix.setIdentity();
            modelMatrix.translate( new Vec3( 0.0f, 0.0f, -viewPole.getView().radius ) );

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

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

    private void initializePrograms() {
        smoothInterp = loadProgram( "SmoothVertexColors.vert", "SmoothVertexColors.frag" );
        linearInterp = loadProgram( "NoCorrectVertexColors.vert", "NoCorrectVertexColors.frag" );

        MatrixStack persMatrix = new MatrixStack();
        persMatrix.perspective( 60.0f, 1.0f, zNear, zFar );

        glUseProgram( smoothInterp.theProgram );
        glUniformMatrix4( smoothInterp.cameraToClipMatrixUnif, false,
                persMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
        glUseProgram( linearInterp.theProgram );
        glUniformMatrix4( linearInterp.cameraToClipMatrixUnif, false,
                persMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
        glUseProgram( 0 );
    }
View Full Code Here

        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() );

        final Vec4 worldLightPos = calcLightPosition();
        final Vec4 lightPosCameraSpace = Mat4.mul( modelMatrix.top(), worldLightPos );

        ProgramData whiteProg = null;
        ProgramData colorProg = null;

        switch ( lightModel ) {
            case PURE_DIFFUSE:
                whiteProg = whiteNoPhong;
                colorProg = colorNoPhong;
                break;

            case DIFFUSE_AND_SPECULAR:
                whiteProg = whitePhong;
                colorProg = colorPhong;
                break;

            case SPECULAR_ONLY:
                whiteProg = whitePhongOnly;
                colorProg = colorPhongOnly;
                break;

            default:
                break;
        }

        glUseProgram( whiteProg.theProgram );
        glUniform4f( whiteProg.lightIntensityUnif, 0.8f, 0.8f, 0.8f, 1.0f );
        glUniform4f( whiteProg.ambientIntensityUnif, 0.2f, 0.2f, 0.2f, 1.0f );
        glUniform3( whiteProg.cameraSpaceLightPosUnif, lightPosCameraSpace.fillAndFlipBuffer( vec4Buffer ) );
        float lightAttenuation = 1.2f;
        glUniform1f( whiteProg.lightAttenuationUnif, lightAttenuation );
        glUniform1f( whiteProg.shininessFactorUnif, shininessFactor );
        glUniform4( whiteProg.baseDiffuseColorUnif,
                drawDark ? darkColor.fillAndFlipBuffer( vec4Buffer ) : lightColor.fillAndFlipBuffer( vec4Buffer ) );

        glUseProgram( colorProg.theProgram );
        glUniform4f( colorProg.lightIntensityUnif, 0.8f, 0.8f, 0.8f, 1.0f );
        glUniform4f( colorProg.ambientIntensityUnif, 0.2f, 0.2f, 0.2f, 1.0f );
        glUniform3( colorProg.cameraSpaceLightPosUnif, lightPosCameraSpace.fillAndFlipBuffer( vec4Buffer ) );
        glUniform1f( colorProg.lightAttenuationUnif, lightAttenuation );
        glUniform1f( colorProg.shininessFactorUnif, shininessFactor );
        glUseProgram( 0 );

        {
            modelMatrix.push();

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

                Mat3 normMatrix = new Mat3( modelMatrix.top() );
                normMatrix = Glm.transpose( Glm.inverse( normMatrix ) );

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

                glUniformMatrix3( whiteProg.normalModelToCameraMatrixUnif, false,
                        normMatrix.fillAndFlipBuffer( mat3Buffer ) );
                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 );
                }

                Mat3 normMatrix = new Mat3( modelMatrix.top() );
                normMatrix = Glm.transpose( Glm.inverse( normMatrix ) );

                ProgramData prog = drawColoredCyl ? colorProg : whiteProg;
                glUseProgram( prog.theProgram );
                glUniformMatrix4( prog.modelToCameraMatrixUnif, false,
                        modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );

                glUniformMatrix3( prog.normalModelToCameraMatrixUnif, false,
                        normMatrix.fillAndFlipBuffer( mat3Buffer ) );

                if ( drawColoredCyl ) {
                    cylinderMesh.render( "lit-color" );
                } else {
                    cylinderMesh.render( "lit" );
                }

                glUseProgram( 0 );

                modelMatrix.pop();
            }

            // Render the light
            if ( drawLightSource ) {
                modelMatrix.push();

                modelMatrix.translate( worldLightPos.x, worldLightPos.y, worldLightPos.z );
                modelMatrix.scale( 0.1f, 0.1f, 0.1f );

                glUseProgram( unlit.theProgram );
                glUniformMatrix4( unlit.modelToCameraMatrixUnif, false,
                        modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
                glUniform4f( unlit.objectColorUnif, 0.8078f, 0.8706f, 0.9922f, 1.0f );
                cubeMesh.render( "flat" );

                modelMatrix.pop();
            }

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

        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() );

        final Vec4 worldLightPos = calcLightPosition();
        final Vec4 lightPosCameraSpace = Mat4.mul( modelMatrix.top(), worldLightPos );

        glUseProgram( fragWhiteDiffuseColor.theProgram );
        glUniform4f( fragWhiteDiffuseColor.lightIntensityUnif, 0.8f, 0.8f, 0.8f, 1.0f );
        glUniform4f( fragWhiteDiffuseColor.ambientIntensityUnif, 0.2f, 0.2f, 0.2f, 1.0f );
        glUniform3( fragWhiteDiffuseColor.cameraSpaceLightPosUnif,
                lightPosCameraSpace.fillAndFlipBuffer( vec4Buffer ) );
        glUniform1f( fragWhiteDiffuseColor.lightAttenuationUnif, lightAttenuation );
        glUniform1i( fragWhiteDiffuseColor.useRSquareUnif, useRSquare ? 1 : 0 );

        glUseProgram( fragVertexDiffuseColor.theProgram );
        glUniform4f( fragVertexDiffuseColor.lightIntensityUnif, 0.8f, 0.8f, 0.8f, 1.0f );
        glUniform4f( fragVertexDiffuseColor.ambientIntensityUnif, 0.2f, 0.2f, 0.2f, 1.0f );
        glUniform3( fragVertexDiffuseColor.cameraSpaceLightPosUnif,
                lightPosCameraSpace.fillAndFlipBuffer( vec4Buffer ) );
        glUniform1f( fragVertexDiffuseColor.lightAttenuationUnif, lightAttenuation );
        glUniform1i( fragVertexDiffuseColor.useRSquareUnif, useRSquare ? 1 : 0 );
        glUseProgram( 0 );

        {
            modelMatrix.push();

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

                Mat3 normMatrix = new Mat3( modelMatrix.top() );
                normMatrix = Glm.transpose( Glm.inverse( normMatrix ) );

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

                glUniformMatrix3( fragWhiteDiffuseColor.normalModelToCameraMatrixUnif, false,
                        normMatrix.fillAndFlipBuffer( mat3Buffer ) );
                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 );
                }

                Mat3 normMatrix = new Mat3( modelMatrix.top() );
                normMatrix = Glm.transpose( Glm.inverse( normMatrix ) );

                if ( drawColoredCyl ) {
                    glUseProgram( fragVertexDiffuseColor.theProgram );
                    glUniformMatrix4( fragVertexDiffuseColor.modelToCameraMatrixUnif, false,
                            modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );

                    glUniformMatrix3( fragVertexDiffuseColor.normalModelToCameraMatrixUnif, false,
                            normMatrix.fillAndFlipBuffer( mat3Buffer ) );
                    cylinderMesh.render( "lit-color" );
                } else {
                    glUseProgram( fragWhiteDiffuseColor.theProgram );
                    glUniformMatrix4( fragWhiteDiffuseColor.modelToCameraMatrixUnif, false,
                            modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );

                    glUniformMatrix3( fragWhiteDiffuseColor.normalModelToCameraMatrixUnif, false,
                            normMatrix.fillAndFlipBuffer( mat3Buffer ) );
                    cylinderMesh.render( "lit" );
                }
                glUseProgram( 0 );

                modelMatrix.pop();
            }

            // Render the light
            if ( drawLight ) {
                modelMatrix.push();

                modelMatrix.translate( worldLightPos.x, worldLightPos.y, worldLightPos.z );
                modelMatrix.scale( 0.1f, 0.1f, 0.1f );

                glUseProgram( unlit.theProgram );
                glUniformMatrix4( unlit.modelToCameraMatrixUnif, false,
                        modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
                glUniform4f( unlit.objectColorUnif, 0.8078f, 0.8706f, 0.9922f, 1.0f );
                cubeMesh.render( "flat" );

                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

        glClearDepth( 1.0f );
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

        final Vec3 camPos = resolveCamPosition();

        MatrixStack camMatrix = new MatrixStack();
        camMatrix.setMatrix( calcLookAtMatrix( camPos, camTarget, new Vec3( 0.0f, 1.0f, 0.0f ) ) );

        glBindBuffer( GL_UNIFORM_BUFFER, globalMatricesUBO );
        glBufferSubData( GL_UNIFORM_BUFFER, Mat4.SIZE, camMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
        glBindBuffer( GL_UNIFORM_BUFFER, 0 );

        MatrixStack modelMatrix = new MatrixStack();

        // Render the ground plane.
        {
            modelMatrix.push();
            modelMatrix.scale( 100.0f, 1.0f, 100.0f );

            glUseProgram( uniformColor.theProgram );
            glUniformMatrix4( uniformColor.modelToWorldMatrixUnif, false,
                    modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
            glUniform4f( uniformColor.baseColorUnif, 0.302f, 0.416f, 0.0589f, 1.0f );
            planeMesh.render();
            glUseProgram( 0 );

            modelMatrix.pop();
        }

        // Draw the trees.
        drawForest( modelMatrix );

        // Draw the building.
        {
            modelMatrix.push();
            modelMatrix.translate( 20.0f, 0.0f, -10.0f );

            drawParthenon( modelMatrix );

            modelMatrix.pop();
        }

        if ( drawLookatPoint ) {
            glDisable( GL_DEPTH_TEST );

            modelMatrix.push();
            modelMatrix.translate( camTarget );
            modelMatrix.scale( 1.0f, 1.0f, 1.0f );

            glUseProgram( objectColor.theProgram );
            glUniformMatrix4( objectColor.modelToWorldMatrixUnif, false,
                    modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
            cubeColorMesh.render();
            glUseProgram( 0 );

            modelMatrix.pop();

            glEnable( GL_DEPTH_TEST );
        }
    }
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();

        UnProjectionBlock unprojData = new UnProjectionBlock();
        unprojData.clipToCameraMatrix = Glm.inverse( persMatrix.top() );
        unprojData.windowSize = new Vec2( w, h );

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

        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() );

        final Vec4 worldLightPos = calcLightPosition();
        final Vec4 lightPosCameraSpace = Mat4.mul( modelMatrix.top(), worldLightPos );

        ProgramData whiteProg = programs[lightModel.ordinal()].whiteProg;
        ProgramData colorProg = programs[lightModel.ordinal()].colorProg;

        glUseProgram( whiteProg.theProgram );
        glUniform4f( whiteProg.lightIntensityUnif, 0.8f, 0.8f, 0.8f, 1.0f );
        glUniform4f( whiteProg.ambientIntensityUnif, 0.2f, 0.2f, 0.2f, 1.0f );
        glUniform3( whiteProg.cameraSpaceLightPosUnif, lightPosCameraSpace.fillAndFlipBuffer( vec4Buffer ) );
        float lightAttenuation = 1.2f;
        glUniform1f( whiteProg.lightAttenuationUnif, lightAttenuation );
        glUniform1f( whiteProg.shininessFactorUnif, matParams.getSpecularValue() );
        glUniform4( whiteProg.baseDiffuseColorUnif,
                drawDark ? darkColor.fillAndFlipBuffer( vec4Buffer ) : lightColor.fillAndFlipBuffer( vec4Buffer ) );

        glUseProgram( colorProg.theProgram );
        glUniform4f( colorProg.lightIntensityUnif, 0.8f, 0.8f, 0.8f, 1.0f );
        glUniform4f( colorProg.ambientIntensityUnif, 0.2f, 0.2f, 0.2f, 1.0f );
        glUniform3( colorProg.cameraSpaceLightPosUnif, lightPosCameraSpace.fillAndFlipBuffer( vec4Buffer ) );
        glUniform1f( colorProg.lightAttenuationUnif, lightAttenuation );
        glUniform1f( colorProg.shininessFactorUnif, matParams.getSpecularValue() );
        glUseProgram( 0 );

        {
            modelMatrix.push();

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

                Mat3 normMatrix = new Mat3( modelMatrix.top() );
                normMatrix = Glm.transpose( Glm.inverse( normMatrix ) );

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

                glUniformMatrix3( whiteProg.normalModelToCameraMatrixUnif, false,
                        normMatrix.fillAndFlipBuffer( mat3Buffer ) );
                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 );
                }

                Mat3 normMatrix = new Mat3( modelMatrix.top() );
                normMatrix = Glm.transpose( Glm.inverse( normMatrix ) );

                ProgramData prog = drawColoredCyl ? colorProg : whiteProg;
                glUseProgram( prog.theProgram );
                glUniformMatrix4( prog.modelToCameraMatrixUnif, false,
                        modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );

                glUniformMatrix3( prog.normalModelToCameraMatrixUnif, false,
                        normMatrix.fillAndFlipBuffer( mat3Buffer ) );

                if ( drawColoredCyl ) {
                    cylinderMesh.render( "lit-color" );
                } else {
                    cylinderMesh.render( "lit" );
                }

                glUseProgram( 0 );

                modelMatrix.pop();
            }

            // Render the light
            if ( drawLightSource ) {
                modelMatrix.push();

                modelMatrix.translate( worldLightPos.x, worldLightPos.y, worldLightPos.z );
                modelMatrix.scale( 0.1f, 0.1f, 0.1f );

                glUseProgram( unlit.theProgram );
                glUniformMatrix4( unlit.modelToCameraMatrixUnif, false,
                        modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
                glUniform4f( unlit.objectColorUnif, 0.8078f, 0.8706f, 0.9922f, 1.0f );
                cubeMesh.render( "flat" );

                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.