Dessiner un cercle avec Jogl

Pour dessiner ce cercle, on utiliser la librairie Jogl (openGL pour Java) Voici le code :

package org.intro;
 
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;
import javax.swing.JFrame;
 
public class Cercle implements GLEventListener
{
	public static void main(String[] args)
	{
		new Cercle();
	}
 
	public Cercle()
	{
		JFrame frame = new JFrame("Le cercle");
		GLCanvas canvas = new GLCanvas();
 
		canvas.addGLEventListener(this);
 
		frame.add(canvas);
		frame.setSize(300,300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}
 
	public void display(GLAutoDrawable drawable)
	{
		System.err.println("DISPLAY !!");
 
		GL gl = drawable.getGL();
		gl.glClear(GL.GL_COLOR_BUFFER_BIT); //On efface le contenu
 
		gl.glColor3f(0.2f, 0.9f, 0.6f);
 
//        float vectorY1=0.9f;
//        float vectorX1=0;
//        float angle,angd=0,angf=7f,vectorX,vectorY,x=0,y=0,r=0.9f;
 
//      gl.glBegin(GL.GL_LINE_STRIP);
//      for(angle=angd;angle<=angf;angle+=0.0001f)
//      {
//          vectorX=x+(r*(float)Math.sin((double)angle));
//          vectorY=y+(r*(float)Math.cos((double)angle));
//          gl.glVertex2d(vectorX1,vectorY1);
//          vectorY1=vectorY;
//          vectorX1=vectorX;
//      }
// OU
 
        gl.glBegin(GL.GL_LINE_LOOP);
 
        for(float i=0; i<=Math.PI*2; i+= 0.1f)
        {
        	gl.glVertex2d(Math.cos(i), Math.sin(i));
        }
 
        gl.glEnd();
 
	}
 
	public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2)
	{
		System.err.println("DISPLAY CHANGE !!");
	}
 
	public void init(GLAutoDrawable drawable)
	{
		System.err.println("INIT !!");
		GL gl = drawable.getGL();
 
		gl.glClearColor(0.5f, 0.3f, 0.8f, 1f); //Quand on efface, on met cette couleur !!
	}
 
	public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4)
	{
		System.err.println("RESHAPE !!");
	}
}
 
java/jogl/dessiner_cercle.txt · Dernière modification: 2008/08/13 13:56 (édition externe)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki