1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
| public void init(GLAutoDrawable drawable) { w = drawable.getWidth(); h = drawable.getHeight(); GL2 gl = drawable.getGL().getGL2(); glu = new GLU(); gl.glEnable(GL2.GL_SMOOTH); gl.glShadeModel(GL2.GL_SMOOTH); gl.glClearColor(0.0f,0.0f,0.0f,1.0f); gl.glClearDepth(1.0f); gl.glClearDepth(1.0f); gl.glEnable(GL.GL_DEPTH_TEST); gl.glDepthFunc(GL.GL_LEQUAL); gl.glEnable(GL.GL_LINE_SMOOTH); gl.glEnable(GL.GL_BLEND); gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_DONT_CARE); }
public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); w = drawable.getWidth(); h = drawable.getHeight(); gl.glClear(GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFFER_BIT); gl.glViewport(0, 0, w, h); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(45.0f,(float)w/(float)h,0.01f,1000000.0f); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); drawScene(drawable); }
public void reshape(GLAutoDrawable drawable, int x, int y, int w2, int h2) { GL2 gl = drawable.getGL().getGL2(); w2 = drawable.getWidth(); h2 = drawable.getHeight(); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); gl.glViewport(0, 0, w, h); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(45.0f,(float)w/(float)h,0.01f,1000000.0f); }
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { } public void drawScene(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFFER_BIT); gl.glRotatef(rotate[0],1f,0f, 0f); gl.glRotatef(rotate[1],0f,1f, 0f); gl.glRotatef(rotate[2],0f,0f, 1f); gl.glTranslatef(trans[0],trans[1],trans[2]); gl.glScalef(scale[0], scale[1], scale[2]); float hfloat = 0.1f; float hcolor = 0; for(int i=0;i<coords.size();i++){ if(coords.get(i).getRed()>1){ coords.get(i).setRed(1); } if(coords.get(i).getGreen()>1){ coords.get(i).setGreen(1); } if(coords.get(i).getBlue()>1){ coords.get(i).setBlue(1); } if(coords.get(i).getX(1)>=1f||coords.get(i).getZ(3)>=5f){ hfloat = 0; } else { hfloat = 5f; } if(light==i){ hcolor = 0.5f; } else { hcolor = 0; } gl.glPushMatrix(); gl.glTranslatef(coords.get(i).getPositionX(),coords.get(i).getPositionY()+0.01f,coords.get(i).getPositionZ()); gl.glBegin(GL2.GL_QUADS); gl.glColor3f(coords.get(i).getRed()-0.2f+hcolor,coords.get(i).getGreen()-0.2f+hcolor, coords.get(i).getBlue()-0.2f+hcolor); gl.glVertex3f(coords.get(i).getX(3)+hfloat,coords.get(i).getY(3),coords.get(i).getZ(3)+hfloat); gl.glVertex3f(coords.get(i).getX(7)+hfloat,coords.get(i).getY(7),coords.get(i).getZ(7)+hfloat); gl.glVertex3f(coords.get(i).getX(6)-hfloat,coords.get(i).getY(6),coords.get(i).getZ(6)+hfloat); gl.glVertex3f(coords.get(i).getX(2)-hfloat,coords.get(i).getY(2),coords.get(i).getZ(2)+hfloat); gl.glColor3f(coords.get(i).getRed()-0.3f+hcolor,coords.get(i).getGreen()-0.3f+hcolor, coords.get(i).getBlue()-0.3f+hcolor); gl.glVertex3f(coords.get(i).getX(4)+hfloat,coords.get(i).getY(4),coords.get(i).getZ(4)-hfloat); gl.glVertex3f(coords.get(i).getX(0)+hfloat,coords.get(i).getY(0),coords.get(i).getZ(0)-hfloat); gl.glVertex3f(coords.get(i).getX(3)+hfloat,coords.get(i).getY(3),coords.get(i).getZ(3)+hfloat); gl.glVertex3f(coords.get(i).getX(7)+hfloat,coords.get(i).getY(7),coords.get(i).getZ(7)+hfloat); gl.glColor3f(coords.get(i).getRed()-0.4f+hcolor,coords.get(i).getGreen()-0.4f+hcolor, coords.get(i).getBlue()-0.4f+hcolor); gl.glVertex3f(coords.get(i).getX(2)-hfloat,coords.get(i).getY(2),coords.get(i).getZ(2)+hfloat); gl.glVertex3f(coords.get(i).getX(1)-hfloat,coords.get(i).getY(1),coords.get(i).getZ(1)-hfloat); gl.glVertex3f(coords.get(i).getX(5)-hfloat,coords.get(i).getY(5),coords.get(i).getZ(5)-hfloat); gl.glVertex3f(coords.get(i).getX(6)-hfloat,coords.get(i).getY(6),coords.get(i).getZ(6)+hfloat); gl.glColor3f(coords.get(i).getRed()-0.5f+hcolor,coords.get(i).getGreen()-0.5f+hcolor, coords.get(i).getBlue()-0.5f+hcolor); gl.glVertex3f(coords.get(i).getX(4)+hfloat,coords.get(i).getY(4),coords.get(i).getZ(4)-hfloat); gl.glVertex3f(coords.get(i).getX(5)-hfloat,coords.get(i).getY(5),coords.get(i).getZ(5)-hfloat); gl.glVertex3f(coords.get(i).getX(6)-hfloat,coords.get(i).getY(6),coords.get(i).getZ(6)+hfloat); gl.glVertex3f(coords.get(i).getX(7)+hfloat,coords.get(i).getY(7),coords.get(i).getZ(7)+hfloat); gl.glColor3f(coords.get(i).getRed()-hfloat+hcolor,coords.get(i).getGreen()-0.1f+hcolor, coords.get(i).getBlue()-0.1f+hcolor); gl.glVertex3f(coords.get(i).getX(1)-hfloat,coords.get(i).getY(1),coords.get(i).getZ(1)-hfloat); gl.glVertex3f(coords.get(i).getX(0)+hfloat,coords.get(i).getY(0),coords.get(i).getZ(0)-hfloat); gl.glVertex3f(coords.get(i).getX(4)+hfloat,coords.get(i).getY(4),coords.get(i).getZ(4)-hfloat); gl.glVertex3f(coords.get(i).getX(5)-hfloat,coords.get(i).getY(5),coords.get(i).getZ(5)-hfloat); gl.glEnd(); gl.glPopMatrix();
} } |