- import java.io.File;
- import java.io.IOException;
- import javax.media.opengl.GL;
- import javax.media.opengl.GLAutoDrawable;
- import javax.media.opengl.GLCanvas;
- import javax.media.opengl.GLCapabilities;
- import javax.media.opengl.GLEventListener;
- import javax.media.opengl.GLException;
- import javax.swing.JFrame;
- import zengine.geo.point.integer.PointInt2D;
- import com.sun.opengl.util.FPSAnimator;
- import com.sun.opengl.util.texture.Texture;
- import com.sun.opengl.util.texture.TextureIO;
- public class TestingArea extends JFrame {
- private final GLCapabilities glCapabilities = new GLCapabilities();
- private final GLCanvas glDataCanvas = new GLCanvas(glCapabilities);
- public TestingArea() {
- super("Test");
- setSize(900, 700);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setVisible(true);
- this.add(glDataCanvas);
- FPSAnimator animator = new FPSAnimator(glDataCanvas, 22);
- animator.start();
- glDataCanvas.addGLEventListener(new GLEventListener() {
- @Override
- public void reshape(GLAutoDrawable arg0, int arg1, int arg2,
- int arg3, int arg4) {
- // TODO Auto-generated method stub
- }
- Texture texture = null;
- @Override
- public void init(GLAutoDrawable arg0) {
- GL gl = arg0.getGL();
- gl.glClearColor(0, 0, 0, 0);
- gl.glClearDepth(-1);
- try {
- texture = TextureIO.newTexture(new File("5.png"), true);
- } catch (GLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- @Override
- public void displayChanged(GLAutoDrawable arg0, boolean arg1,
- boolean arg2) {
- }
- int width = 1024;
- int height = 768;
- @Override
- public void display(GLAutoDrawable glDrawable) {
- GL gl = glDrawable.getGL();
- gl.glMatrixMode(GL.GL_PROJECTION);
- gl.glLoadIdentity();
- gl.glViewport(0, 0, glDataCanvas.getWidth(),
- glDataCanvas.getHeight());
- gl.glOrtho(0, width, 0, height, 10000, -10000);
- gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
- int xLoc = 0;
- int yLoc = 0;
- int zLoc = 0;
- int quadWidth = 500;
- int quadHeight = 700;
- gl.glColor3f(1f / 255f * 255f, 1f / 255f * 33f,
- 1f / 255f * 100f);
- gl.glEnable(GL.GL_TEXTURE_2D);
- gl.glBindTexture(GL.GL_TEXTURE_2D, texture.getTextureObject());
- // gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE,
- // GL.GL_DECAL);
- gl.glBegin(GL.GL_QUADS);
- gl.glTexCoord2f(1, 1);
- gl.glVertex3f(xLoc, yLoc, zLoc);
- gl.glTexCoord2f(1, 0);
- gl.glVertex3f(xLoc, yLoc + quadHeight, zLoc);
- gl.glTexCoord2f(0, 0);
- gl.glVertex3f(xLoc + quadWidth, yLoc + quadHeight, zLoc);
- gl.glTexCoord2f(0, 1);
- gl.glVertex3f(xLoc + quadWidth, yLoc, zLoc);
- gl.glEnd();
- }
- });
- }
- public static void main(String[] args) {
- new TestingArea();
- }
- }