00001 package gui.OpenGL;
00002 import java.awt.Dimension;
00003
00004 import javax.media.opengl.DebugGL;
00005 import javax.media.opengl.GL;
00006 import javax.media.opengl.GLAutoDrawable;
00007 import javax.media.opengl.GLEventListener;
00008 import javax.media.opengl.glu.GLU;
00009
00010 import commandline.dataToImage.MeshToImageDataFilter;
00011
00012
00013 public class TestRenderer implements GLEventListener
00014 {
00015
00016 protected GL gl;
00017 protected GLAutoDrawable glDrawable;
00018 protected GLU glu;
00019 protected Camera camera;
00020 protected Dimension dimension;
00021
00022
00023 public TestRenderer(MeshToImageDataFilter triangleStorage,Dimension dimension){
00024
00025 this.dimension=dimension;
00026 }
00027
00028
00029
00030
00031 public void init(GLAutoDrawable drawable)
00032 {
00033 this.glu=new GLU();
00034 this.gl = drawable.getGL();
00035 this.glDrawable = drawable;
00036 this.camera=new Camera(gl,glu,dimension);
00037
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 gl.glEnable(GL.GL_DEPTH_TEST);
00059 gl.glDepthFunc(GL.GL_LESS);
00060
00062 gl.glDisable(GL.GL_CULL_FACE);
00063 gl.glClearColor(0.1f, 0.2f, 0.4f, 0f);
00064 gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
00065
00066 camera.aim();
00067 drawable.setGL( new DebugGL(drawable.getGL() ));
00068 }
00069
00070 public void display(GLAutoDrawable drawable)
00071 {
00072
00073
00074 gl.glMatrixMode(GL.GL_MODELVIEW);
00075
00076 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
00077
00078
00079
00080
00081
00082
00083
00084 gl.glLoadIdentity();
00085 if(this.getValueOfSetting(SHOW_AXIS)==TRUE){
00086 showAxis();
00087 }
00088 moveScene();
00089 gl.glPushMatrix();
00090
00091
00092 gl.glTranslatef(-dimension.width/2f,-dimension.height/2,0f);
00094 gl.glPopMatrix();
00095
00096
00097 }
00098
00099 protected void moveScene(){
00100
00101
00102 }
00103
00104 private void showAxis(){
00105
00106 gl.glBegin(GL.GL_LINE_STRIP);
00107 gl.glColor3f(1,0,0);
00108 gl.glVertex3f(0,0,0);
00109 gl.glColor3f(1,0,0);
00110 gl.glVertex3f(255,0,0);
00111 gl.glEnd();
00112
00113
00114 gl.glBegin(GL.GL_LINE_STRIP);
00115 gl.glColor3f(0,1,0);
00116 gl.glVertex3f(0,0,0);
00117 gl.glColor3f(0,1,0);
00118 gl.glVertex3f(0,255,0);
00119 gl.glEnd();
00120
00121
00122 gl.glBegin(GL.GL_LINE_STRIP);
00123 gl.glColor3f(0,0,1);
00124 gl.glVertex3f(0,0,0);
00125 gl.glColor3f(0,0,1);
00126 gl.glVertex3f(0,0,255);
00127 gl.glEnd();
00128
00129
00130 }
00131
00132 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
00133 {
00134 }
00135
00136 public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged)
00137 {
00138 }
00139
00140 public Camera getCamera(){
00141 return this.camera;
00142 }
00143
00144
00145 public void changeSettings(int ITEM_TO_CHANGE, int VALUE){
00146 switch(ITEM_TO_CHANGE){
00147 case MESHVIEW: this.meshview=VALUE; break;
00148 case SHOW_3D: this.show3d=VALUE; break;
00149 case SHOW_AXIS: this.show_axis=VALUE;break;
00150 case SHOW_ONLY_VERTICAL_OFFSETS: this.show_only_vertical_offsets=VALUE;break;
00151 case SHOW_WITHOUT_VERTICAL_OFFSETS: this.show_without_vertical_offset=VALUE; break;
00152 default:
00153 }
00154 }
00155
00156 public int getValueOfSetting(int ITEM_TO_CHANGE){
00157 switch(ITEM_TO_CHANGE){
00158 case MESHVIEW: return this.meshview;
00159 case SHOW_3D: return this.show3d;
00160 case SHOW_AXIS: return this.show_axis;
00161 case SHOW_ONLY_VERTICAL_OFFSETS: return this.show_only_vertical_offsets;
00162 case SHOW_WITHOUT_VERTICAL_OFFSETS: return this.show_without_vertical_offset;
00163 default: return -1;
00164 }
00165 }
00166
00167
00168
00169 public static final int MESHVIEW=0;
00170 public static final int SHOW_3D=1;
00171 public static final int SHOW_AXIS=3;
00172 public static final int SHOW_ONLY_VERTICAL_OFFSETS=4;
00173 public static final int SHOW_WITHOUT_VERTICAL_OFFSETS=5;
00174
00175 public static final int TRUE=1;
00176 public static final int FALSE=0;
00177 private int meshview=FALSE;
00178 private int show3d=FALSE;
00179 private int show_axis=FALSE;
00180 private int show_only_vertical_offsets=FALSE;
00181 private int show_without_vertical_offset=FALSE;
00182
00183 }