XYOrthographicRenderer.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
00015  */
00016 
00017 package org.ros.android.view.visualization;
00018 
00019 import android.opengl.GLSurfaceView;
00020 import org.ros.android.view.visualization.layer.Layer;
00021 import org.ros.android.view.visualization.layer.TfLayer;
00022 import org.ros.namespace.GraphName;
00023 
00024 import javax.microedition.khronos.egl.EGLConfig;
00025 import javax.microedition.khronos.opengles.GL10;
00026 
00033 public class XYOrthographicRenderer implements GLSurfaceView.Renderer {
00034 
00035   private static final Color BACKGROUND_COLOR = new Color(0.87f, 0.87f, 0.87f, 1.f);
00036 
00037   private final VisualizationView view;
00038 
00039   public XYOrthographicRenderer(VisualizationView view) {
00040     this.view = view;
00041   }
00042 
00043   @Override
00044   public void onSurfaceChanged(GL10 gl, int width, int height) {
00045     Viewport viewport = new Viewport(width, height);
00046     viewport.apply(gl);
00047     view.getCamera().setViewport(viewport);
00048     gl.glMatrixMode(GL10.GL_MODELVIEW);
00049     gl.glEnable(GL10.GL_BLEND);
00050     gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
00051     gl.glDisable(GL10.GL_DEPTH_TEST);
00052     gl.glClearColor(BACKGROUND_COLOR.getRed(), BACKGROUND_COLOR.getGreen(),
00053         BACKGROUND_COLOR.getBlue(), BACKGROUND_COLOR.getAlpha());
00054     for (Layer layer : view.getLayers()) {
00055       layer.onSurfaceChanged(view, gl, width, height);
00056     }
00057   }
00058 
00059   @Override
00060   public void onDrawFrame(GL10 gl) {
00061     gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
00062     gl.glLoadIdentity();
00063     view.getCamera().apply(gl);
00064     drawLayers(gl);
00065   }
00066 
00067   private void drawLayers(GL10 gl) {
00068     for (Layer layer : view.getLayers()) {
00069       gl.glPushMatrix();
00070       if (layer instanceof TfLayer) {
00071         GraphName layerFrame = ((TfLayer) layer).getFrame();
00072         if (layerFrame != null && view.getCamera().applyFrameTransform(gl, layerFrame)) {
00073           layer.draw(view, gl);
00074         }
00075       } else {
00076         layer.draw(view, gl);
00077       }
00078       gl.glPopMatrix();
00079     }
00080   }
00081 
00082   @Override
00083   public void onSurfaceCreated(GL10 gl, EGLConfig config) {
00084     for (Layer layer : view.getLayers()) {
00085       layer.onSurfaceCreated(view, gl, config);
00086     }
00087   }
00088 }


android_core
Author(s): Damon Kohler
autogenerated on Thu Jun 6 2019 21:20:07