Package net.rim.device.api.opengles

Examples of net.rim.device.api.opengles.GL20


    /**
     * @see net.rim.device.api.opengles.GLField#initialize(GL)
     */
    protected void initialize(final GL g) {
        final GL20 gl = (GL20) g;

        // Create geometry for drawing a cube
        _cube = new Cube();
        _cube.init(gl);

        // Initialize OpenGL state and load all OpenGL resources
        gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        gl.glEnable(GL20.GL_DEPTH_TEST);
        gl.glEnable(GL20.GL_CULL_FACE);

        // Load the shaders
        _program =
                createShaderProgram(gl, getSource(VERTEX_SHADER),
                        getSource(FRAGMENT_SHADER));
        gl.glUseProgram(_program);

        // Get attribute locations
        _positionLoc = gl.glGetAttribLocation(_program, "position");
        _texCoordLoc = gl.glGetAttribLocation(_program, "texCoord");
        _normalLoc = gl.glGetAttribLocation(_program, "normal");

        // Get uniform locations
        _matrixLoc = gl.glGetUniformLocation(_program, "matrix");
        _lightDirectionLoc =
                gl.glGetUniformLocation(_program, "lightDirection");
        _lightAmbientLoc = gl.glGetUniformLocation(_program, "lightAmbient");
        _lightDiffuseLoc = gl.glGetUniformLocation(_program, "lightDiffuse");
        _textureLoc = gl.glGetUniformLocation(_program, "texture");

        // Set uniform values
        gl.glUniform1i(_textureLoc, 0);

        // Light direction (normalized)
        gl.glUniform3f(_lightDirectionLoc, 0.0f, 0.0f, -1.0f);

        // Ambient light color
        gl.glUniform3f(_lightAmbientLoc, 0.2f, 0.2f, 0.2f);

        // Diffuse light color
        gl.glUniform3f(_lightDiffuseLoc, 1.0f, 1.0f, 1.0f);

        // Load texture
        gl.glActiveTexture(GL20.GL_TEXTURE0);
        final EncodedImage encodedImage =
                EncodedImage.getEncodedImageResource("BlackBerry.png");
        createTexture(gl, encodedImage, GL20.GL_RGB,
                GL20.GL_UNSIGNED_SHORT_5_6_5);

View Full Code Here


    /**
     * @see net.rim.device.api.opengles.GLField#render(GL)
     */
    protected void render(final GL g) {
        final GL20 gl = (GL20) g;

        if (_sizeChanged) {
            sizeChanged(gl, getWidth(), getHeight());
            _sizeChanged = false;
        }

        gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

        gl.glUseProgram(_program);

        // Transform the cube
        _matrix.setIdentity();
        _matrix.translate(0.0f, 0.0f, -3.5f);
        _matrix.rotate(_rotationAxis, _rotation.getFloat());

        // There are no matrix modes in GL20.
        // Multiply the model-view matrix with the projection
        // matrix and pass it to the shader program.
        Matrix4f.multiply(_projection, _matrix, _matrix);
        gl.glUniformMatrix4fv(_matrixLoc, 1, false, _matrix.getArray(), 0);

        // Set the attribute location of the position, normal and texture
        // coordinates
        _cube.enableVertexAttrib(_positionLoc);
        _cube.enableTexcoordAttrib(_texCoordLoc);
View Full Code Here

TOP

Related Classes of net.rim.device.api.opengles.GL20

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.