// EJERCICIO 1 (dibuja un triAngulo)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import com.sun.opengl.util.GLUT;
public class E01_10 extends JFrame implements GLEventListener
{
GLU glu = new GLU();
GL gl = null;
GLUT glut = new GLUT();
public static void main(String[] args)
{
E01_10 frame = new E01_10();
frame.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) { System.exit(0); }
public void windowClosing(WindowEvent e) { windowClosed(e); }
} );
}
public E01_10()
{
super("P01_10");
GLCapabilities caps = new GLCapabilities();
GLCanvas canvas = new GLCanvas(caps);
canvas.addGLEventListener(this);
add("Center", canvas);
setSize(500, 500);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
void run() { }
public void init (GLAutoDrawable DRAW)
{
gl = DRAW.getGL();
gl.glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
gl.glLoadIdentity();
gl.glOrtho(-2.0, 7.0, -2.0, 7.0, 0.0, 1.0);
}
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h)
{
GL gl = drawable.getGL();
GLU glu = new GLU();
gl.glOrtho(-2.0, 7.0, -2.0, 7.0, 0.0, 1.0);
gl.glLoadIdentity();
}
public void display(GLAutoDrawable drawable)
{
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glBegin(GL.GL_TRIANGLES);
gl.glColor3d(1.0,0.0,0.0); gl.glVertex3d(0.0,0.8,0.0); // rojo
gl.glColor3d(0.0,1.0,0.0); gl.glVertex3d(-0.6,-0.2,0.0);// verde
gl.glColor3d(0.0,0.0,1.0); gl.glVertex3d(0.6,-0.2,0.0); // azul
gl.glEnd();
gl.glPopMatrix();
gl.glFlush();
}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged){ }
}