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
| private GLU glu = new GLU();
@Override
public void init(GLAutoDrawable gLDrawable) {
GL2 gl = gLDrawable.getGL().getGL2();
gl.glShadeModel(GL2.GL_SMOOTH);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClearDepthf(1.0f);
gl.glEnable(GL2.GL_DEPTH_TEST);
gl.glDepthFunc(GL2.GL_LEQUAL);
}
@Override
public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) {
GL2 gl = gLDrawable.getGL().getGL2();
if(height <= 0) {
height = 1;
}
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(0.0f, width/height, 0.0f, 11.0f);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
}
@Override
public void display(GLAutoDrawable gLDrawable) {
GL2 gl = gLDrawable.getGL().getGL2();
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
// Si je commente cette ligne, ça fonctionne
gl.glTranslatef(0, 0, -10.0f);
gl.glBegin(GL2.GL_QUADS);
gl.glColor3ub((byte)255, (byte)225, (byte)12);
gl.glVertex3f(-1, -1, 0);
gl.glVertex3f(-1, 1, 0);
gl.glVertex3f(1, 1, 0);
gl.glVertex3f(1, -1, 0);
gl.glColor3ub((byte)255, (byte)0, (byte)12);
gl.glVertex3f(-0.9f, -0.9f, 0);
gl.glVertex3f(-0.9f, 0.9f, 0);
gl.glVertex3f(0.9f, 0.9f, 0);
gl.glVertex3f(0.9f, -0.9f, 0);
gl.glEnd();
} |
Partager