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
| public class SpaceRacingSimulatorEventListerer implements GLEventListener, KeyListener, MouseListener, MouseMotionListener { ... private GLU glu = new GLU(); @Override public void display(GLAutoDrawable gLDrawable) { final GL2 gl = gLDrawable.getGL().getGL2(); gl.glClearColor(0.5f, 0.5f, 0.5f, 1); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glPushMatrix(); gl.glRotatef(rot, 0, 1, 0); gl.glRotatef(rotX, 1, 0, 0); gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION,lightPos, 0); gl.glPushMatrix(); gl.glTranslatef(-0.5f, -0.5f, -0.5f); float materialColor[] = {1.0f, 1.0f, 0.0f, 1.0f}; float materialSpecular[] = {0.0f, 0.0f, 1.0f, 1.0f}; float materialEmission[] = {1.0f, 1.0f, 0.0f, 1.0f}; ... gl.glPushMatrix(); gl.glTranslatef(0, 2, 0); gl.glColor3f(0.8f, 0.8f, 0.8f); gl.glPopMatrix(); gl.glTranslatef(2, 0, 0); gl.glScalef(0.5f, 0.5f, 0.5f); gl.glTranslatef(-0.5f, -0.5f, -0.5f); drawCube(gl);
int width = 100, height = 100; byte[] src = new byte[width * height]; for (int a = 0; a < height; a++) { int color = (int)(a * 1.0f / height * 255); for(int b = 0; b < width; b++) { src[a * width + b] = (byte)color; } }
gl.glPixelStorei(GL2.GL_UNPACK_ALIGNMENT, 1); gl.glPixelStorei(GL2.GL_UNPACK_SKIP_PIXELS, 0); gl.glPixelStorei(GL2.GL_UNPACK_SKIP_ROWS, 0); gl.glPushMatrix(); gl.glLoadIdentity();
gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity();
glu.gluOrtho2D(0, windowWidth, 0, windowHeight); gl.glRasterPos2f(windowWidth / 2, windowHeight / 2); gl.glPopMatrix();
gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glPopMatrix(); } ... }
|