/**
* @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);