/* * Copyright (c) 1993-1997, Silicon Graphics, Inc. * ALL RIGHTS RESERVED * Permission to use, copy, modify, and distribute this software for * any purpose and without fee is hereby granted, provided that the above * copyright notice appear in all copies and that both the copyright notice * and this permission notice appear in supporting documentation, and that * the name of Silicon Graphics, Inc. not be used in advertising * or publicity pertaining to distribution of the software without specific, * written prior permission. */ /* * Created on 25/02/2006 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ /* * Drawf.java * * Draws the bitmapped letter F on the screen (several times). * This demonstrates use of the glBitmap() call.* * * @translated to Java by Wu Shin-Ting * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.media.opengl.*; public class Drawf extends JFrame implements GLEventListener, KeyListener { public static final Dimension PREFERRED_FRAME_SIZE = new Dimension(100, 100); byte rasters[] = {(byte)0xc0, (byte)0x00, (byte)0xc0, (byte)0x00, (byte)0xc0, (byte)0x00, (byte)0xc0, (byte)0x00, (byte)0xc0, (byte)0x00, (byte)0xff, (byte)0x00, (byte)0xff, (byte)0x00, (byte)0xc0, (byte)0x00, (byte)0xc0, (byte)0x00, (byte)0xc0, (byte)0x00, (byte)0xff, (byte)0xc0, (byte)0xff, (byte)0xc0}; /** Constructor. */ public Drawf() { // init JFrame super ("Drawf - JMDM version "); System.out.println("Constructor"); } /** We'd like to be 500x500, please. */ public Dimension getPreferredSize(){ return PREFERRED_FRAME_SIZE; } /* * METHODS DEFINED BY GLEventListener */ /** Called by drawable to initiate drawing. */ public void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glColor3f (1.0f, 1.0f, 1.0f); gl.glRasterPos2i (20, 20); gl.glBitmap (10, 12, 0.0f, 0.0f, 11.0f, 0.0f, rasters, 0); gl.glBitmap (10, 12, 0.0f, 0.0f, 11.0f, 0.0f, rasters, 0); gl.glBitmap (10, 12, 0.0f, 0.0f, 11.0f, 0.0f, rasters, 0); gl.glFlush(); } /** Called by drawable to indicate mode or device has changed. */ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged){} /** Called after OpenGL is init'ed */ public void init(GLAutoDrawable drawable) { System.out.println("init()"); GL gl = drawable.getGL(); System.err.println("INIT GL IS: " + gl.getClass().getName()); System.err.println("GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR)); System.err.println("GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER)); System.err.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION)); gl.glPixelStorei (GL.GL_UNPACK_ALIGNMENT, 1); gl.glClearColor (0.0f, 0.0f, 0.0f, 0.0f); // add a GLEventListener, which will get called when a // key is pressed drawable.addKeyListener(this); } /** Called to indicate the drawing surface has been moved and/or resized. */ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height){ System.out.println("reshape()"); GL gl = drawable.getGL(); gl.glViewport(0, 0, width, height); gl.glMatrixMode (GL.GL_PROJECTION); gl.glLoadIdentity (); gl.glOrtho (0, width, 0, height, -1.f, 1.f); gl.glMatrixMode (GL.GL_MODELVIEW); } /* * OUR HELPER METHODS */ // Methods required for the implementation of KeyListener public void keyPressed(KeyEvent e){ System.out.println("Key pressed"); if (e.getKeyChar() == 27){ System.exit(0); } } public void keyReleased(KeyEvent e){} public void keyTyped(KeyEvent e){} /** main creates and shows a Drawf-JFrame */ public static void main(String[] args){ Drawf g = new Drawf(); //Set frame location g.setLocation(100,100); GLCapabilities gl_c = new GLCapabilities(); // Disable double buffer gl_c.setDoubleBuffered(false); // get a GLCanvas GLCanvas canvas = new GLCanvas(gl_c); // add a GLEventListener, which will get called when the // canvas is resized or needs a repaint canvas.addGLEventListener(g); // now add the canvas to the JFrame. Note we use BorderLayout.CENTER // to make the canvas stretch to fill the container (ie, the frame) g.getContentPane().add(canvas, BorderLayout.CENTER); g.pack(); g.setVisible(true); } }