Updated to worldwind release 20070817
[worldwind-tracker.git] / gov / nasa / worldwind / BasicFrameController.java
blob3f26fb85f45d97b1b039821350b0643fb48dd7aa
1 /*
2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
5 All Rights Reserved.
6 */
7 package gov.nasa.worldwind;
9 import javax.media.opengl.*;
11 /**
12 * @author Tom Gaskins
13 * @version $Id: BasicFrameController.java 1941 2007-06-02 08:52:28Z tgaskins $
15 public class BasicFrameController implements FrameController
17 public void initializeFrame(DrawContext dc)
19 if (null == dc)
21 String msg = WorldWind.retrieveErrMsg("nullValue.DrawContextIsNull");
22 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
23 throw new IllegalArgumentException(msg);
26 javax.media.opengl.GL gl = dc.getGL();
28 gl.glPushAttrib(GL.GL_VIEWPORT_BIT | GL.GL_ENABLE_BIT | GL.GL_TRANSFORM_BIT);
30 gl.glMatrixMode(GL.GL_MODELVIEW);
31 gl.glPushMatrix();
32 gl.glLoadIdentity();
34 gl.glMatrixMode(GL.GL_PROJECTION);
35 gl.glPushMatrix();
36 gl.glLoadIdentity();
38 gl.glEnable(GL.GL_DEPTH_TEST);
41 public void finalizeFrame(DrawContext dc)
43 if (null == dc)
45 String msg = WorldWind.retrieveErrMsg("nullValue.DrawContextIsNull");
46 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
47 throw new IllegalArgumentException(msg);
50 GL gl = dc.getGL();
52 gl.glMatrixMode(GL.GL_MODELVIEW);
53 gl.glPopMatrix();
55 gl.glMatrixMode(GL.GL_PROJECTION);
56 gl.glPopMatrix();
58 gl.glPopAttrib();
60 gl.glFlush();
62 // checkGLErrors(dc);
65 /**
66 * Called to check for openGL errors. This method includes a "round-trip" between the application and renderer,
67 * which is slow. Therefore, this method is excluded from the "normal" render pass. It is here as a matter of
68 * convenience to developers, and is not part of the API.
70 * @param dc the relevant <code>DrawContext</code>
72 @SuppressWarnings({"UNUSED_SYMBOL", "UnusedDeclaration"})
73 private void checkGLErrors(DrawContext dc)
75 GL gl = dc.getGL();
76 int err = gl.glGetError();
77 if (err != GL.GL_NO_ERROR)
79 String msg = dc.getGLU().gluErrorString(err);
80 msg += err;
81 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
85 public void clearFrame(DrawContext dc)
87 java.awt.Color cc = dc.getClearColor();
88 dc.getGL().glClearColor(cc.getRed(), cc.getGreen(), cc.getBlue(), cc.getAlpha());
89 dc.getGL().glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);