import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import com.sun.opengl.util.*;
public class Trazos extends JFrame implements GLEventListener
{
GLU glu = new GLU();
GL gl;
GLUT glut = new GLUT();
public static void main(String[] args)
{
Trazos frame = new Trazos();
frame.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) { System.exit(0); }
public void windowClosing(WindowEvent e) { windowClosed(e); }
} );
}
public Trazos()
{
super("Trazos");
GLCapabilities caps = new GLCapabilities();
GLCanvas canvas = new GLCanvas(caps);
canvas.addGLEventListener(this);
add("Center", canvas);
setBounds(200, 100, 500, 500);
setVisible(true);
}
void run()
{
setSize(600, 600);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void init (GLAutoDrawable DRAW)
{
gl = DRAW.getGL();
gl.glClearColor (1.0f, 1.0f, 0.0f, 0.0f);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(60.0, 1.0, 1.0, 100.0);
}
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h)
{
gl.glViewport(0, 0, w, h);
gl.glClearColor (1.0f, 1.0f, 0.0f, 0.0f);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(60.0, 1.0, 1.0, 100.0);
}
public void display(GLAutoDrawable drawable)
{
gl.glPushMatrix();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glClearDepth(1.0);
gl.glTranslated(0.0, 0.0, -15.0);
gl.glBegin(gl.GL_TRIANGLES); // Drawing Triangles
gl.glColor3f(1.0f,0.0f,0.0f); gl.glVertex3f( 0.0f, 5.0f, 0.0f); // Top
gl.glColor3f(0.0f,1.0f,0.0f); gl.glVertex3f(-7.0f,-5.0f, 0.0f); // Bottom Left
gl.glColor3f(0.0f,0.0f,1.0f); gl.glVertex3f( 7.0f,-5.0f, 0.0f); // Bottom Right
gl.glEnd();
gl.glBegin(gl.GL_QUADS);
gl.glColor3d(0.0, 1.0, 1.0);
gl.glVertex3d(-5.0, 5.0, -5.0); // (superior-izquierda)
gl.glVertex3d(-5.0, -5.0, 5.0); // (inferior-izquierda)
gl.glVertex3d(5.0, -5.0, 5.0); // (inferior-derecha)
gl.glVertex3d(5.0, 5.0, -5.0); // (superior-derecha)
gl.glEnd();
gl.glPopMatrix();
gl.glFlush();
}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged){ }
}