parent
							
								
									ec64ad21fc
								
							
						
					
					
						commit
						eee9ed14dc
					
				@ -0,0 +1,299 @@ | 
				
			||||
//package junk;
 | 
				
			||||
//
 | 
				
			||||
//
 | 
				
			||||
//import static org.lwjgl.opengl.GL11.*;
 | 
				
			||||
//
 | 
				
			||||
//import java.nio.ByteBuffer;
 | 
				
			||||
//
 | 
				
			||||
//import mightypork.gamecore.backend.lwjgl.AwtScreenshot;
 | 
				
			||||
//import mightypork.gamecore.core.modules.AppAccess;
 | 
				
			||||
//import mightypork.gamecore.core.modules.AppModule;
 | 
				
			||||
//import mightypork.gamecore.render.events.DisplayReadyEvent;
 | 
				
			||||
//import mightypork.gamecore.render.events.ViewportChangeEvent;
 | 
				
			||||
//import mightypork.utils.logging.Log;
 | 
				
			||||
//import mightypork.utils.math.constraints.rect.Rect;
 | 
				
			||||
//import mightypork.utils.math.constraints.rect.RectBound;
 | 
				
			||||
//import mightypork.utils.math.constraints.vect.Vect;
 | 
				
			||||
//import mightypork.utils.math.timing.FpsMeter;
 | 
				
			||||
//
 | 
				
			||||
//import org.lwjgl.BufferUtils;
 | 
				
			||||
//import org.lwjgl.LWJGLException;
 | 
				
			||||
//import org.lwjgl.opengl.Display;
 | 
				
			||||
//import org.lwjgl.opengl.DisplayMode;
 | 
				
			||||
//
 | 
				
			||||
//
 | 
				
			||||
///**
 | 
				
			||||
// * Display system
 | 
				
			||||
// * 
 | 
				
			||||
// * @author Ondřej Hruška (MightyPork)
 | 
				
			||||
// */
 | 
				
			||||
//@Deprecated
 | 
				
			||||
//public class DisplaySystem extends AppModule implements RectBound {
 | 
				
			||||
//	
 | 
				
			||||
//	private DisplayMode windowDisplayMode;
 | 
				
			||||
//	private int targetFps;
 | 
				
			||||
//	private FpsMeter fpsMeter;
 | 
				
			||||
//	private boolean fullscreenSwitchRequested;
 | 
				
			||||
//	
 | 
				
			||||
//	/** Current screen size */
 | 
				
			||||
//	private static final Vect screenSize = new Vect() {
 | 
				
			||||
//		
 | 
				
			||||
//		@Override
 | 
				
			||||
//		public double y()
 | 
				
			||||
//		{
 | 
				
			||||
//			return Display.getHeight();
 | 
				
			||||
//		}
 | 
				
			||||
//		
 | 
				
			||||
//		
 | 
				
			||||
//		@Override
 | 
				
			||||
//		public double x()
 | 
				
			||||
//		{
 | 
				
			||||
//			return Display.getWidth();
 | 
				
			||||
//		}
 | 
				
			||||
//	};
 | 
				
			||||
//	
 | 
				
			||||
//	private static final Rect rect = Rect.make(screenSize);
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * @param app app access
 | 
				
			||||
//	 */
 | 
				
			||||
//	public DisplaySystem(AppAccess app) {
 | 
				
			||||
//		super(app);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	@Override
 | 
				
			||||
//	protected void deinit()
 | 
				
			||||
//	{
 | 
				
			||||
//		Display.destroy();
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Set target fps (for syncing in endFrame() call).<br>
 | 
				
			||||
//	 * With vsync enabled, the target fps may not be met.
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param fps requested fps
 | 
				
			||||
//	 */
 | 
				
			||||
//	public void setTargetFps(int fps)
 | 
				
			||||
//	{
 | 
				
			||||
//		this.targetFps = fps;
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Create a main window
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param width requested width
 | 
				
			||||
//	 * @param height requested height
 | 
				
			||||
//	 * @param resizable is resizable by the user
 | 
				
			||||
//	 * @param fullscreen is in fullscreen
 | 
				
			||||
//	 * @param title window title
 | 
				
			||||
//	 */
 | 
				
			||||
//	public void createMainWindow(int width, int height, boolean resizable, boolean fullscreen, String title)
 | 
				
			||||
//	{
 | 
				
			||||
//		try {
 | 
				
			||||
//			Display.setDisplayMode(windowDisplayMode = new DisplayMode(width, height));
 | 
				
			||||
//			Display.setResizable(resizable);
 | 
				
			||||
//			Display.setVSyncEnabled(true);
 | 
				
			||||
//			Display.setTitle(title);
 | 
				
			||||
//			Display.create();
 | 
				
			||||
//			
 | 
				
			||||
//			fpsMeter = new FpsMeter();
 | 
				
			||||
//			
 | 
				
			||||
//			if (fullscreen) {
 | 
				
			||||
//				switchFullscreen();
 | 
				
			||||
//				Display.update();
 | 
				
			||||
//			}
 | 
				
			||||
//			
 | 
				
			||||
//			getEventBus().send(new DisplayReadyEvent());
 | 
				
			||||
//			
 | 
				
			||||
//		} catch (final LWJGLException e) {
 | 
				
			||||
//			throw new RuntimeException("Could not initialize screen", e);
 | 
				
			||||
//		}
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Toggle FS if possible
 | 
				
			||||
//	 */
 | 
				
			||||
//	public void switchFullscreen()
 | 
				
			||||
//	{
 | 
				
			||||
//		fullscreenSwitchRequested = true;
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	private void doSwitchFullscreen()
 | 
				
			||||
//	{
 | 
				
			||||
//		try {
 | 
				
			||||
//			
 | 
				
			||||
//			if (!Display.isFullscreen()) {
 | 
				
			||||
//				Log.f3("Entering fullscreen.");
 | 
				
			||||
//				// save window resize
 | 
				
			||||
//				windowDisplayMode = new DisplayMode(Display.getWidth(), Display.getHeight());
 | 
				
			||||
//				
 | 
				
			||||
//				Display.setDisplayMode(Display.getDesktopDisplayMode());
 | 
				
			||||
//				Display.setFullscreen(true);
 | 
				
			||||
//				Display.update();
 | 
				
			||||
//			} else {
 | 
				
			||||
//				Log.f3("Leaving fullscreen.");
 | 
				
			||||
//				Display.setDisplayMode(windowDisplayMode);
 | 
				
			||||
//				Display.update();
 | 
				
			||||
//			}
 | 
				
			||||
//			
 | 
				
			||||
//			getEventBus().send(new ViewportChangeEvent(getSize()));
 | 
				
			||||
//			
 | 
				
			||||
//		} catch (final Throwable t) {
 | 
				
			||||
//			Log.e("Failed to toggle fullscreen mode.", t);
 | 
				
			||||
//			try {
 | 
				
			||||
//				Display.setDisplayMode(windowDisplayMode);
 | 
				
			||||
//				Display.update();
 | 
				
			||||
//			} catch (final Throwable t1) {
 | 
				
			||||
//				throw new RuntimeException("Failed to revert failed fullscreen toggle.", t1);
 | 
				
			||||
//			}
 | 
				
			||||
//		}
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Take screenshot (expensive processing is done on-demand when screenshot
 | 
				
			||||
//	 * is processed).
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @return screenshot object
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static AwtScreenshot prepareScreenshot()
 | 
				
			||||
//	{
 | 
				
			||||
//		glReadBuffer(GL_FRONT);
 | 
				
			||||
//		final int width = Display.getWidth();
 | 
				
			||||
//		final int height = Display.getHeight();
 | 
				
			||||
//		final int bpp = 4;
 | 
				
			||||
//		final ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp);
 | 
				
			||||
//		glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
 | 
				
			||||
//		
 | 
				
			||||
//		final AwtScreenshot sc = new AwtScreenshot(width, height, bpp, buffer);
 | 
				
			||||
//		
 | 
				
			||||
//		return sc;
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * @return true if close was requested (i.e. click on cross)
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static boolean isCloseRequested()
 | 
				
			||||
//	{
 | 
				
			||||
//		return Display.isCloseRequested();
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Get fullscreen state
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @return is fullscreen
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static boolean isFullscreen()
 | 
				
			||||
//	{
 | 
				
			||||
//		return Display.isFullscreen();
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Get screen size. This Vect is final and views at it can safely be made.
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @return size
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static Vect getSize()
 | 
				
			||||
//	{
 | 
				
			||||
//		return screenSize;
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Get screen rect. Static version of getRect().
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @return size
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static Rect getBounds()
 | 
				
			||||
//	{
 | 
				
			||||
//		return rect;
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * @return screen width
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static int getWidth()
 | 
				
			||||
//	{
 | 
				
			||||
//		return screenSize.xi();
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * @return screen height
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static int getHeight()
 | 
				
			||||
//	{
 | 
				
			||||
//		return screenSize.yi();
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Start a OpenGL frame
 | 
				
			||||
//	 */
 | 
				
			||||
//	public void beginFrame()
 | 
				
			||||
//	{
 | 
				
			||||
//		// handle resize
 | 
				
			||||
//		if (Display.wasResized()) {
 | 
				
			||||
//			getEventBus().send(new ViewportChangeEvent(getSize()));
 | 
				
			||||
//		}
 | 
				
			||||
//		
 | 
				
			||||
//		if (fullscreenSwitchRequested) {
 | 
				
			||||
//			fullscreenSwitchRequested = false;
 | 
				
			||||
//			doSwitchFullscreen();
 | 
				
			||||
//		}
 | 
				
			||||
//		
 | 
				
			||||
//		glLoadIdentity();
 | 
				
			||||
//		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 | 
				
			||||
//		fpsMeter.frame();
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * End an OpenGL frame, flip buffers, sync to fps.
 | 
				
			||||
//	 */
 | 
				
			||||
//	public void endFrame()
 | 
				
			||||
//	{
 | 
				
			||||
//		Display.update(false); // don't poll input devices
 | 
				
			||||
//		Display.sync(targetFps);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Get screen rect. This Rect is final and views at it can safely be made.
 | 
				
			||||
//	 */
 | 
				
			||||
//	@Override
 | 
				
			||||
//	public Rect getRect()
 | 
				
			||||
//	{
 | 
				
			||||
//		return getBounds();
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * @return current FPS
 | 
				
			||||
//	 */
 | 
				
			||||
//	public long getFps()
 | 
				
			||||
//	{
 | 
				
			||||
//		return fpsMeter.getFPS();
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Get screen center. This vect is final and views at it can safely be made.
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @return screen center.
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static Vect getCenter()
 | 
				
			||||
//	{
 | 
				
			||||
//		return rect.center();
 | 
				
			||||
//	}
 | 
				
			||||
//}
 | 
				
			||||
@ -0,0 +1,542 @@ | 
				
			||||
//package junk;
 | 
				
			||||
//
 | 
				
			||||
//
 | 
				
			||||
//import static org.lwjgl.opengl.GL11.*;
 | 
				
			||||
//
 | 
				
			||||
//import java.io.IOException;
 | 
				
			||||
//
 | 
				
			||||
//import mightypork.gamecore.resources.textures.FilterMode;
 | 
				
			||||
//import mightypork.gamecore.resources.textures.ITexture;
 | 
				
			||||
//import mightypork.gamecore.resources.textures.TxQuad;
 | 
				
			||||
//import mightypork.utils.files.FileUtils;
 | 
				
			||||
//import mightypork.utils.logging.Log;
 | 
				
			||||
//import mightypork.utils.math.color.Color;
 | 
				
			||||
//import mightypork.utils.math.color.pal.RGB;
 | 
				
			||||
//import mightypork.utils.math.constraints.rect.Rect;
 | 
				
			||||
//import mightypork.utils.math.constraints.rect.caching.RectDigest;
 | 
				
			||||
//import mightypork.utils.math.constraints.vect.Vect;
 | 
				
			||||
//import mightypork.utils.math.constraints.vect.VectConst;
 | 
				
			||||
//
 | 
				
			||||
//import org.lwjgl.opengl.GL11;
 | 
				
			||||
//import org.newdawn.slick.opengl.Texture;
 | 
				
			||||
//import org.newdawn.slick.opengl.TextureLoader;
 | 
				
			||||
//
 | 
				
			||||
//
 | 
				
			||||
///**
 | 
				
			||||
// * Render utilities
 | 
				
			||||
// * 
 | 
				
			||||
// * @author Ondřej Hruška (MightyPork)
 | 
				
			||||
// */
 | 
				
			||||
//@Deprecated
 | 
				
			||||
//public class Render {
 | 
				
			||||
//	
 | 
				
			||||
//	public static final VectConst AXIS_X = Vect.make(1, 0, 0);
 | 
				
			||||
//	public static final VectConst AXIS_Y = Vect.make(0, 1, 0);
 | 
				
			||||
//	public static final VectConst AXIS_Z = Vect.make(0, 0, 1);
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Bind GL color
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param color Color color
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void setColor(Color color)
 | 
				
			||||
//	{
 | 
				
			||||
//		if (color != null) glColor4d(color.r(), color.g(), color.b(), color.a());
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Bind GL color
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param color Color color
 | 
				
			||||
//	 * @param alpha alpha multiplier
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void setColor(Color color, double alpha)
 | 
				
			||||
//	{
 | 
				
			||||
//		if (color != null) glColor4d(color.r(), color.g(), color.b(), color.a() * alpha);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Translate
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param x
 | 
				
			||||
//	 * @param y
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void translate(double x, double y)
 | 
				
			||||
//	{
 | 
				
			||||
//		glTranslated(x, y, 0);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Translate
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param x
 | 
				
			||||
//	 * @param y
 | 
				
			||||
//	 * @param z
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void translate(double x, double y, double z)
 | 
				
			||||
//	{
 | 
				
			||||
//		glTranslated(x, y, z);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Translate with coord
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param coord coord
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void translate(Vect coord)
 | 
				
			||||
//	{
 | 
				
			||||
//		glTranslated(coord.x(), coord.y(), coord.z());
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Translate with coord, discard Z
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param coord coord
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void translateXY(Vect coord)
 | 
				
			||||
//	{
 | 
				
			||||
//		glTranslated(coord.x(), coord.y(), 0);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Scale
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param x
 | 
				
			||||
//	 * @param y
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void scale(double x, double y)
 | 
				
			||||
//	{
 | 
				
			||||
//		glScaled(x, y, 0);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Scale
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param x
 | 
				
			||||
//	 * @param y
 | 
				
			||||
//	 * @param z
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void scale(double x, double y, double z)
 | 
				
			||||
//	{
 | 
				
			||||
//		glScaled(x, y, z);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Scale
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param factor vector of scaling factors
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void scale(Vect factor)
 | 
				
			||||
//	{
 | 
				
			||||
//		glScaled(factor.x(), factor.y(), factor.z());
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Scale by X factor
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param factor scaling factor
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void scaleXY(double factor)
 | 
				
			||||
//	{
 | 
				
			||||
//		glScaled(factor, factor, 1);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Scale by X factor
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param factor scaling factor
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void scaleX(double factor)
 | 
				
			||||
//	{
 | 
				
			||||
//		glScaled(factor, 1, 1);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Scale by Y factor
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param factor scaling factor
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void scaleY(double factor)
 | 
				
			||||
//	{
 | 
				
			||||
//		glScaled(1, factor, 1);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Scale by Z factor
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param factor scaling factor
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void scaleZ(double factor)
 | 
				
			||||
//	{
 | 
				
			||||
//		glScaled(1, 1, factor);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Rotate around X axis
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param angle deg
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void rotateX(double angle)
 | 
				
			||||
//	{
 | 
				
			||||
//		rotate(angle, AXIS_X);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Rotate around Y axis
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param angle deg
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void rotateY(double angle)
 | 
				
			||||
//	{
 | 
				
			||||
//		rotate(angle, AXIS_Y);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Rotate around Z axis
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param angle deg
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void rotateZ(double angle)
 | 
				
			||||
//	{
 | 
				
			||||
//		rotate(angle, AXIS_Z);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Rotate
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param angle rotate angle
 | 
				
			||||
//	 * @param axis rotation axis
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void rotate(double angle, Vect axis)
 | 
				
			||||
//	{
 | 
				
			||||
//		final Vect vec = axis.norm(1);
 | 
				
			||||
//		glRotated(angle, vec.x(), vec.y(), vec.z());
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	private static int pushed = 0;
 | 
				
			||||
//	/** Can be used to avoid texture binding and glBegin/glEnd in textured quads */
 | 
				
			||||
//	public static boolean batchTexturedQuadMode;
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Store GL state
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void pushState()
 | 
				
			||||
//	{
 | 
				
			||||
//		pushed++;
 | 
				
			||||
//		
 | 
				
			||||
//		if (pushed >= 100) {
 | 
				
			||||
//			Log.w("Suspicious number of state pushes: " + pushed);
 | 
				
			||||
//		}
 | 
				
			||||
//		
 | 
				
			||||
//		GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
 | 
				
			||||
//		GL11.glPushClientAttrib(GL11.GL_ALL_CLIENT_ATTRIB_BITS);
 | 
				
			||||
//		GL11.glMatrixMode(GL11.GL_MODELVIEW);
 | 
				
			||||
//		GL11.glPushMatrix();
 | 
				
			||||
//		GL11.glMatrixMode(GL11.GL_PROJECTION);
 | 
				
			||||
//		GL11.glPushMatrix();
 | 
				
			||||
//		GL11.glMatrixMode(GL11.GL_MODELVIEW);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Restore Gl state
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void popState()
 | 
				
			||||
//	{
 | 
				
			||||
//		if (pushed == 0) {
 | 
				
			||||
//			Log.w("Pop without push.");
 | 
				
			||||
//		}
 | 
				
			||||
//		
 | 
				
			||||
//		pushed--;
 | 
				
			||||
//		
 | 
				
			||||
//		GL11.glMatrixMode(GL11.GL_PROJECTION);
 | 
				
			||||
//		GL11.glPopMatrix();
 | 
				
			||||
//		GL11.glMatrixMode(GL11.GL_MODELVIEW);
 | 
				
			||||
//		GL11.glPopMatrix();
 | 
				
			||||
//		GL11.glPopClientAttrib();
 | 
				
			||||
//		GL11.glPopAttrib();
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Store matrix
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void pushMatrix()
 | 
				
			||||
//	{
 | 
				
			||||
//		GL11.glPushMatrix();
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Restore Gl state
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void popMatrix()
 | 
				
			||||
//	{
 | 
				
			||||
//		GL11.glPopMatrix();
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Load texture
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param resourcePath
 | 
				
			||||
//	 * @param filtering filtering mode to use while loading.
 | 
				
			||||
//	 * @return the loaded texture
 | 
				
			||||
//	 */
 | 
				
			||||
//	public synchronized static Texture loadSlickTexture(String resourcePath, FilterMode filtering)
 | 
				
			||||
//	{
 | 
				
			||||
//		
 | 
				
			||||
//		try {
 | 
				
			||||
//			
 | 
				
			||||
//			final String ext = FileUtils.getExtension(resourcePath).toUpperCase();
 | 
				
			||||
//			
 | 
				
			||||
//			final Texture texture = TextureLoader.getTexture(ext, FileUtils.getResource(resourcePath), false, filtering.num);
 | 
				
			||||
//			
 | 
				
			||||
//			if (texture == null) {
 | 
				
			||||
//				Log.w("Texture " + resourcePath + " could not be loaded.");
 | 
				
			||||
//			}
 | 
				
			||||
//			
 | 
				
			||||
//			return texture;
 | 
				
			||||
//			
 | 
				
			||||
//		} catch (final IOException e) {
 | 
				
			||||
//			Log.e("Loading of texture " + resourcePath + " failed.", e);
 | 
				
			||||
//			throw new RuntimeException("Could not load texture " + resourcePath + ".", e);
 | 
				
			||||
//		}
 | 
				
			||||
//		
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Render quad 2D
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param rect rectangle
 | 
				
			||||
//	 * @param color draw color
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void quad(Rect rect, Color color)
 | 
				
			||||
//	{
 | 
				
			||||
//		setColor(color);
 | 
				
			||||
//		quad(rect);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Render quad
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param quad the quad to draw (px)
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void quad(Rect quad)
 | 
				
			||||
//	{
 | 
				
			||||
//		final RectDigest q = quad.digest();
 | 
				
			||||
//		
 | 
				
			||||
//		// draw with color
 | 
				
			||||
//		
 | 
				
			||||
//		glDisable(GL_TEXTURE_2D);
 | 
				
			||||
//		
 | 
				
			||||
//		// quad
 | 
				
			||||
//		glBegin(GL_QUADS);
 | 
				
			||||
//		glVertex2d(q.left, q.bottom);
 | 
				
			||||
//		glVertex2d(q.right, q.bottom);
 | 
				
			||||
//		glVertex2d(q.right, q.top);
 | 
				
			||||
//		glVertex2d(q.left, q.top);
 | 
				
			||||
//		glEnd();
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Draw quad with horizontal gradient
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param quad drawn quad bounds
 | 
				
			||||
//	 * @param color1 left color
 | 
				
			||||
//	 * @param color2 right color
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void quadGradH(Rect quad, Color color1, Color color2)
 | 
				
			||||
//	{
 | 
				
			||||
//		quadColor(quad, color1, color2, color2, color1);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	public static void quadColor(Rect quad, Color color)
 | 
				
			||||
//	{
 | 
				
			||||
//		quadColor(quad, color, color, color, color);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Draw quad with coloured vertices.
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param quad drawn quad bounds
 | 
				
			||||
//	 * @param colorHMinVMin
 | 
				
			||||
//	 * @param colorHMaxVMin
 | 
				
			||||
//	 * @param colorHMaxVMax
 | 
				
			||||
//	 * @param colorHMinVMax
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void quadColor(Rect quad, Color colorHMinVMin, Color colorHMaxVMin, Color colorHMaxVMax, Color colorHMinVMax)
 | 
				
			||||
//	{
 | 
				
			||||
//		final RectDigest r = quad.digest();
 | 
				
			||||
//		
 | 
				
			||||
//		// draw with color
 | 
				
			||||
//		
 | 
				
			||||
//		glDisable(GL_TEXTURE_2D);
 | 
				
			||||
//		
 | 
				
			||||
//		glBegin(GL_QUADS);
 | 
				
			||||
//		setColor(colorHMinVMax);
 | 
				
			||||
//		glVertex2d(r.left, r.bottom);
 | 
				
			||||
//		
 | 
				
			||||
//		setColor(colorHMaxVMax);
 | 
				
			||||
//		glVertex2d(r.right, r.bottom);
 | 
				
			||||
//		
 | 
				
			||||
//		setColor(colorHMaxVMin);
 | 
				
			||||
//		glVertex2d(r.right, r.top);
 | 
				
			||||
//		
 | 
				
			||||
//		setColor(colorHMinVMin);
 | 
				
			||||
//		glVertex2d(r.left, r.top);
 | 
				
			||||
//		glEnd();
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Draw quad with vertical gradient
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param quad drawn quad bounds
 | 
				
			||||
//	 * @param color1 top color
 | 
				
			||||
//	 * @param color2 bottom color
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void quadGradV(Rect quad, Color color1, Color color2)
 | 
				
			||||
//	{
 | 
				
			||||
//		quadColor(quad, color1, color1, color2, color2);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Render textured rect
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param quad rectangle (px)
 | 
				
			||||
//	 * @param txquad texture quad
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void quadTextured(Rect quad, TxQuad txquad)
 | 
				
			||||
//	{
 | 
				
			||||
//		quadTextured(quad, txquad, RGB.WHITE);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Render textured rect
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param quad rectangle (px)
 | 
				
			||||
//	 * @param txquad texture instance
 | 
				
			||||
//	 * @param tint color tint
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void quadTextured(Rect quad, TxQuad txquad, Color tint)
 | 
				
			||||
//	{
 | 
				
			||||
//		if (!batchTexturedQuadMode) {
 | 
				
			||||
//			glEnable(GL_TEXTURE_2D);
 | 
				
			||||
//			txquad.tx.bind();
 | 
				
			||||
//			glBegin(GL_QUADS);
 | 
				
			||||
//			setColor(tint);
 | 
				
			||||
//		}
 | 
				
			||||
//		
 | 
				
			||||
//		final RectDigest q = quad.digest();
 | 
				
			||||
//		final RectDigest u = txquad.uvs.digest();
 | 
				
			||||
//		
 | 
				
			||||
//		final double offs = 0.0001;// hack to avoid white stitching
 | 
				
			||||
//		
 | 
				
			||||
//		double tL = u.left + offs, tR = u.right - offs, tT = u.top + offs, tB = u.bottom - offs;
 | 
				
			||||
//		
 | 
				
			||||
//		// handle flip
 | 
				
			||||
//		if (txquad.isFlippedY()) {
 | 
				
			||||
//			final double swap = tT;
 | 
				
			||||
//			tT = tB;
 | 
				
			||||
//			tB = swap;
 | 
				
			||||
//		}
 | 
				
			||||
//		
 | 
				
			||||
//		if (txquad.isFlippedX()) {
 | 
				
			||||
//			final double swap = tL;
 | 
				
			||||
//			tL = tR;
 | 
				
			||||
//			tR = swap;
 | 
				
			||||
//		}
 | 
				
			||||
//		
 | 
				
			||||
//		final double w = txquad.tx.getWidth01();
 | 
				
			||||
//		final double h = txquad.tx.getHeight01();
 | 
				
			||||
//		
 | 
				
			||||
//		// quad with texture
 | 
				
			||||
//		glTexCoord2d(tL * w, tB * h);
 | 
				
			||||
//		glVertex2d(q.left, q.bottom);
 | 
				
			||||
//		
 | 
				
			||||
//		glTexCoord2d(tR * w, tB * h);
 | 
				
			||||
//		glVertex2d(q.right, q.bottom);
 | 
				
			||||
//		
 | 
				
			||||
//		glTexCoord2d(tR * w, tT * h);
 | 
				
			||||
//		glVertex2d(q.right, q.top);
 | 
				
			||||
//		
 | 
				
			||||
//		glTexCoord2d(tL * w, tT * h);
 | 
				
			||||
//		glVertex2d(q.left, q.top);
 | 
				
			||||
//		
 | 
				
			||||
//		if (!batchTexturedQuadMode) glEnd();
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	/**
 | 
				
			||||
//	 * Setup Ortho projection for 2D graphics
 | 
				
			||||
//	 * 
 | 
				
			||||
//	 * @param size viewport size (screen size)
 | 
				
			||||
//	 */
 | 
				
			||||
//	public static void setupOrtho(Vect size)
 | 
				
			||||
//	{
 | 
				
			||||
//		// fix projection for changed size
 | 
				
			||||
//		glMatrixMode(GL_PROJECTION);
 | 
				
			||||
//		glLoadIdentity();
 | 
				
			||||
//		glViewport(0, 0, size.xi(), size.yi());
 | 
				
			||||
//		glOrtho(0, size.xi(), size.yi(), 0, -1000, 1000);
 | 
				
			||||
//		
 | 
				
			||||
//		// back to modelview
 | 
				
			||||
//		glMatrixMode(GL_MODELVIEW);
 | 
				
			||||
//		
 | 
				
			||||
//		glLoadIdentity();
 | 
				
			||||
//		
 | 
				
			||||
//		glDisable(GL_LIGHTING);
 | 
				
			||||
//		
 | 
				
			||||
//		glClearDepth(1f);
 | 
				
			||||
//		glEnable(GL_DEPTH_TEST);
 | 
				
			||||
//		glDepthFunc(GL_LEQUAL);
 | 
				
			||||
//		
 | 
				
			||||
//		glEnable(GL_NORMALIZE);
 | 
				
			||||
//		
 | 
				
			||||
//		glShadeModel(GL_SMOOTH);
 | 
				
			||||
//		
 | 
				
			||||
//		glEnable(GL_BLEND);
 | 
				
			||||
//		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	public static void enterBatchTexturedQuadMode(ITexture texture)
 | 
				
			||||
//	{
 | 
				
			||||
//		texture.bind();
 | 
				
			||||
//		glBegin(GL11.GL_QUADS);
 | 
				
			||||
//		batchTexturedQuadMode = true;
 | 
				
			||||
//	}
 | 
				
			||||
//	
 | 
				
			||||
//	
 | 
				
			||||
//	public static void leaveBatchTexturedQuadMode()
 | 
				
			||||
//	{
 | 
				
			||||
//		glEnd();
 | 
				
			||||
//		batchTexturedQuadMode = false;
 | 
				
			||||
//	}
 | 
				
			||||
//}
 | 
				
			||||
@ -0,0 +1,151 @@ | 
				
			||||
package mightypork.gamecore.core.modules; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
import java.io.File; | 
				
			||||
import java.util.ArrayList; | 
				
			||||
import java.util.List; | 
				
			||||
import java.util.logging.Level; | 
				
			||||
 | 
				
			||||
import mightypork.gamecore.backend.Backend; | 
				
			||||
import mightypork.gamecore.core.WorkDir.RouteSetup; | 
				
			||||
import mightypork.gamecore.core.config.ConfigSetup; | 
				
			||||
import mightypork.gamecore.core.config.KeySetup; | 
				
			||||
import mightypork.gamecore.resources.AsyncResourceLoader; | 
				
			||||
import mightypork.gamecore.resources.ResourceLoader; | 
				
			||||
import mightypork.gamecore.resources.ResourceSetup; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Init options holder class
 | 
				
			||||
 */ | 
				
			||||
public class AppInitOptions { | 
				
			||||
	 | 
				
			||||
	boolean singleInstance = false; | 
				
			||||
	 | 
				
			||||
	Backend backend = null; | 
				
			||||
	File workdir = null; | 
				
			||||
	 | 
				
			||||
	String logDir = "log"; | 
				
			||||
	String logFilePrefix = "runtime"; | 
				
			||||
	 | 
				
			||||
	String screenshotDir = "screenshots"; | 
				
			||||
	 | 
				
			||||
	int logArchiveCount = 0; | 
				
			||||
	boolean busLogging = false; | 
				
			||||
	 | 
				
			||||
	String configFile = "settings.cfg"; | 
				
			||||
	String configComment = "Main config file"; | 
				
			||||
	 | 
				
			||||
	public String lockFile = ".lock"; | 
				
			||||
	 | 
				
			||||
	final List<ResourceSetup> resourceLists = new ArrayList<>(); | 
				
			||||
	final List<KeySetup> keyLists = new ArrayList<>(); | 
				
			||||
	final List<ConfigSetup> configLists = new ArrayList<>(); | 
				
			||||
	final List<RouteSetup> routeLists = new ArrayList<>(); | 
				
			||||
	 | 
				
			||||
	ResourceLoader resourceLoader = new AsyncResourceLoader(); | 
				
			||||
	Level logLevel = Level.ALL; | 
				
			||||
	public boolean sigleInstance = true; | 
				
			||||
	Level logSoutLevel = Level.ALL; | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	public void setConfigFile(String filename, String comment) | 
				
			||||
	{ | 
				
			||||
		configFile = filename; | 
				
			||||
		configComment = comment; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	public void addConfig(ConfigSetup cfg) | 
				
			||||
	{ | 
				
			||||
		configLists.add(cfg); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	public void addKeys(KeySetup keys) | 
				
			||||
	{ | 
				
			||||
		keyLists.add(keys); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	public void addRoutes(RouteSetup keys) | 
				
			||||
	{ | 
				
			||||
		routeLists.add(keys); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	public void addResources(ResourceSetup res) | 
				
			||||
	{ | 
				
			||||
		resourceLists.add(res); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	public void setBackend(Backend backend) | 
				
			||||
	{ | 
				
			||||
		this.backend = backend; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Set whether to run in single instance mode, or allow multiple instances.<br> | 
				
			||||
	 * Multiple instances running can cause various collisions (eg. when writing | 
				
			||||
	 * config file or logging). | 
				
			||||
	 *  | 
				
			||||
	 * @param sigleInstance true to allow only one instance | 
				
			||||
	 */ | 
				
			||||
	public void setSigleInstance(boolean sigleInstance) | 
				
			||||
	{ | 
				
			||||
		this.sigleInstance = sigleInstance; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Set working directory path. If not exists, it will be created. | 
				
			||||
	 *  | 
				
			||||
	 * @param workdir work dir path | 
				
			||||
	 */ | 
				
			||||
	public void setWorkdir(File workdir) | 
				
			||||
	{ | 
				
			||||
		this.workdir = workdir; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	public void setBusLogging(boolean yes) | 
				
			||||
	{ | 
				
			||||
		busLogging = yes; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	public void setLogOptions(String logDir, String filePrefix, int archivedCount, Level logLevel) | 
				
			||||
	{ | 
				
			||||
		this.logDir = logDir; | 
				
			||||
		this.logFilePrefix = filePrefix; | 
				
			||||
		this.logArchiveCount = archivedCount; | 
				
			||||
		this.logLevel = logLevel; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	public void setResourceLoader(ResourceLoader resLoader) | 
				
			||||
	{ | 
				
			||||
		resourceLoader = resLoader; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	public void setScreenshotDir(String path) | 
				
			||||
	{ | 
				
			||||
		this.screenshotDir = path; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	public void setLockFile(String lockFile) | 
				
			||||
	{ | 
				
			||||
		this.lockFile = lockFile; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	public void setLogLevel(Level logLevel, Level soutLevel) | 
				
			||||
	{ | 
				
			||||
		this.logLevel = logLevel; | 
				
			||||
		this.logSoutLevel = soutLevel; | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
@ -1,300 +0,0 @@ | 
				
			||||
package mightypork.gamecore.render; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
import static org.lwjgl.opengl.GL11.*; | 
				
			||||
 | 
				
			||||
import java.nio.ByteBuffer; | 
				
			||||
 | 
				
			||||
import mightypork.gamecore.backend.lwjgl.AwtScreenshot; | 
				
			||||
import mightypork.gamecore.core.modules.AppAccess; | 
				
			||||
import mightypork.gamecore.core.modules.AppModule; | 
				
			||||
import mightypork.gamecore.render.events.DisplayReadyEvent; | 
				
			||||
import mightypork.gamecore.render.events.ViewportChangeEvent; | 
				
			||||
import mightypork.utils.logging.Log; | 
				
			||||
import mightypork.utils.math.constraints.rect.Rect; | 
				
			||||
import mightypork.utils.math.constraints.rect.RectBound; | 
				
			||||
import mightypork.utils.math.constraints.vect.Vect; | 
				
			||||
import mightypork.utils.math.timing.FpsMeter; | 
				
			||||
 | 
				
			||||
import org.lwjgl.BufferUtils; | 
				
			||||
import org.lwjgl.LWJGLException; | 
				
			||||
import org.lwjgl.opengl.Display; | 
				
			||||
import org.lwjgl.opengl.DisplayMode; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Display system | 
				
			||||
 *  | 
				
			||||
 * @author Ondřej Hruška (MightyPork) | 
				
			||||
 */ | 
				
			||||
@Deprecated | 
				
			||||
public class DisplaySystem extends AppModule implements RectBound { | 
				
			||||
	 | 
				
			||||
	private DisplayMode windowDisplayMode; | 
				
			||||
	private int targetFps; | 
				
			||||
	private FpsMeter fpsMeter; | 
				
			||||
	private boolean fullscreenSwitchRequested; | 
				
			||||
	 | 
				
			||||
	/** Current screen size */ | 
				
			||||
	private static final Vect screenSize = new Vect() { | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		public double y() | 
				
			||||
		{ | 
				
			||||
			return Display.getHeight(); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		public double x() | 
				
			||||
		{ | 
				
			||||
			return Display.getWidth(); | 
				
			||||
		} | 
				
			||||
	}; | 
				
			||||
	 | 
				
			||||
	private static final Rect rect = Rect.make(screenSize); | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * @param app app access | 
				
			||||
	 */ | 
				
			||||
	public DisplaySystem(AppAccess app) | 
				
			||||
	{ | 
				
			||||
		super(app); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	protected void deinit() | 
				
			||||
	{ | 
				
			||||
		Display.destroy(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Set target fps (for syncing in endFrame() call).<br> | 
				
			||||
	 * With vsync enabled, the target fps may not be met. | 
				
			||||
	 *  | 
				
			||||
	 * @param fps requested fps | 
				
			||||
	 */ | 
				
			||||
	public void setTargetFps(int fps) | 
				
			||||
	{ | 
				
			||||
		this.targetFps = fps; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Create a main window | 
				
			||||
	 *  | 
				
			||||
	 * @param width requested width | 
				
			||||
	 * @param height requested height | 
				
			||||
	 * @param resizable is resizable by the user | 
				
			||||
	 * @param fullscreen is in fullscreen | 
				
			||||
	 * @param title window title | 
				
			||||
	 */ | 
				
			||||
	public void createMainWindow(int width, int height, boolean resizable, boolean fullscreen, String title) | 
				
			||||
	{ | 
				
			||||
		try { | 
				
			||||
			Display.setDisplayMode(windowDisplayMode = new DisplayMode(width, height)); | 
				
			||||
			Display.setResizable(resizable); | 
				
			||||
			Display.setVSyncEnabled(true); | 
				
			||||
			Display.setTitle(title); | 
				
			||||
			Display.create(); | 
				
			||||
			 | 
				
			||||
			fpsMeter = new FpsMeter(); | 
				
			||||
			 | 
				
			||||
			if (fullscreen) { | 
				
			||||
				switchFullscreen(); | 
				
			||||
				Display.update(); | 
				
			||||
			} | 
				
			||||
			 | 
				
			||||
			getEventBus().send(new DisplayReadyEvent()); | 
				
			||||
			 | 
				
			||||
		} catch (final LWJGLException e) { | 
				
			||||
			throw new RuntimeException("Could not initialize screen", e); | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Toggle FS if possible | 
				
			||||
	 */ | 
				
			||||
	public void switchFullscreen() | 
				
			||||
	{ | 
				
			||||
		fullscreenSwitchRequested = true; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	private void doSwitchFullscreen() | 
				
			||||
	{ | 
				
			||||
		try { | 
				
			||||
			 | 
				
			||||
			if (!Display.isFullscreen()) { | 
				
			||||
				Log.f3("Entering fullscreen."); | 
				
			||||
				// save window resize
 | 
				
			||||
				windowDisplayMode = new DisplayMode(Display.getWidth(), Display.getHeight()); | 
				
			||||
				 | 
				
			||||
				Display.setDisplayMode(Display.getDesktopDisplayMode()); | 
				
			||||
				Display.setFullscreen(true); | 
				
			||||
				Display.update(); | 
				
			||||
			} else { | 
				
			||||
				Log.f3("Leaving fullscreen."); | 
				
			||||
				Display.setDisplayMode(windowDisplayMode); | 
				
			||||
				Display.update(); | 
				
			||||
			} | 
				
			||||
			 | 
				
			||||
			getEventBus().send(new ViewportChangeEvent(getSize())); | 
				
			||||
			 | 
				
			||||
		} catch (final Throwable t) { | 
				
			||||
			Log.e("Failed to toggle fullscreen mode.", t); | 
				
			||||
			try { | 
				
			||||
				Display.setDisplayMode(windowDisplayMode); | 
				
			||||
				Display.update(); | 
				
			||||
			} catch (final Throwable t1) { | 
				
			||||
				throw new RuntimeException("Failed to revert failed fullscreen toggle.", t1); | 
				
			||||
			} | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Take screenshot (expensive processing is done on-demand when screenshot | 
				
			||||
	 * is processed). | 
				
			||||
	 *  | 
				
			||||
	 * @return screenshot object | 
				
			||||
	 */ | 
				
			||||
	public static AwtScreenshot prepareScreenshot() | 
				
			||||
	{ | 
				
			||||
		glReadBuffer(GL_FRONT); | 
				
			||||
		final int width = Display.getWidth(); | 
				
			||||
		final int height = Display.getHeight(); | 
				
			||||
		final int bpp = 4; | 
				
			||||
		final ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp); | 
				
			||||
		glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); | 
				
			||||
		 | 
				
			||||
		final AwtScreenshot sc = new AwtScreenshot(width, height, bpp, buffer); | 
				
			||||
		 | 
				
			||||
		return sc; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * @return true if close was requested (i.e. click on cross) | 
				
			||||
	 */ | 
				
			||||
	public static boolean isCloseRequested() | 
				
			||||
	{ | 
				
			||||
		return Display.isCloseRequested(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Get fullscreen state | 
				
			||||
	 *  | 
				
			||||
	 * @return is fullscreen | 
				
			||||
	 */ | 
				
			||||
	public static boolean isFullscreen() | 
				
			||||
	{ | 
				
			||||
		return Display.isFullscreen(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Get screen size. This Vect is final and views at it can safely be made. | 
				
			||||
	 *  | 
				
			||||
	 * @return size | 
				
			||||
	 */ | 
				
			||||
	public static Vect getSize() | 
				
			||||
	{ | 
				
			||||
		return screenSize; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Get screen rect. Static version of getRect(). | 
				
			||||
	 *  | 
				
			||||
	 * @return size | 
				
			||||
	 */ | 
				
			||||
	public static Rect getBounds() | 
				
			||||
	{ | 
				
			||||
		return rect; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * @return screen width | 
				
			||||
	 */ | 
				
			||||
	public static int getWidth() | 
				
			||||
	{ | 
				
			||||
		return screenSize.xi(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * @return screen height | 
				
			||||
	 */ | 
				
			||||
	public static int getHeight() | 
				
			||||
	{ | 
				
			||||
		return screenSize.yi(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Start a OpenGL frame | 
				
			||||
	 */ | 
				
			||||
	public void beginFrame() | 
				
			||||
	{ | 
				
			||||
		// handle resize
 | 
				
			||||
		if (Display.wasResized()) { | 
				
			||||
			getEventBus().send(new ViewportChangeEvent(getSize())); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		if (fullscreenSwitchRequested) { | 
				
			||||
			fullscreenSwitchRequested = false; | 
				
			||||
			doSwitchFullscreen(); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		glLoadIdentity(); | 
				
			||||
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | 
				
			||||
		fpsMeter.frame(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * End an OpenGL frame, flip buffers, sync to fps. | 
				
			||||
	 */ | 
				
			||||
	public void endFrame() | 
				
			||||
	{ | 
				
			||||
		Display.update(false); // don't poll input devices
 | 
				
			||||
		Display.sync(targetFps); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Get screen rect. This Rect is final and views at it can safely be made. | 
				
			||||
	 */ | 
				
			||||
	@Override | 
				
			||||
	public Rect getRect() | 
				
			||||
	{ | 
				
			||||
		return getBounds(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * @return current FPS | 
				
			||||
	 */ | 
				
			||||
	public long getFps() | 
				
			||||
	{ | 
				
			||||
		return fpsMeter.getFPS(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Get screen center. This vect is final and views at it can safely be made. | 
				
			||||
	 *  | 
				
			||||
	 * @return screen center. | 
				
			||||
	 */ | 
				
			||||
	public static Vect getCenter() | 
				
			||||
	{ | 
				
			||||
		return rect.center(); | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
@ -1,542 +0,0 @@ | 
				
			||||
package mightypork.gamecore.render; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
import static org.lwjgl.opengl.GL11.*; | 
				
			||||
 | 
				
			||||
import java.io.IOException; | 
				
			||||
 | 
				
			||||
import mightypork.gamecore.resources.textures.FilterMode; | 
				
			||||
import mightypork.gamecore.resources.textures.ITexture; | 
				
			||||
import mightypork.gamecore.resources.textures.TxQuad; | 
				
			||||
import mightypork.utils.files.FileUtils; | 
				
			||||
import mightypork.utils.logging.Log; | 
				
			||||
import mightypork.utils.math.color.Color; | 
				
			||||
import mightypork.utils.math.color.pal.RGB; | 
				
			||||
import mightypork.utils.math.constraints.rect.Rect; | 
				
			||||
import mightypork.utils.math.constraints.rect.caching.RectDigest; | 
				
			||||
import mightypork.utils.math.constraints.vect.Vect; | 
				
			||||
import mightypork.utils.math.constraints.vect.VectConst; | 
				
			||||
 | 
				
			||||
import org.lwjgl.opengl.GL11; | 
				
			||||
import org.newdawn.slick.opengl.Texture; | 
				
			||||
import org.newdawn.slick.opengl.TextureLoader; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Render utilities | 
				
			||||
 *  | 
				
			||||
 * @author Ondřej Hruška (MightyPork) | 
				
			||||
 */ | 
				
			||||
@Deprecated | 
				
			||||
public class Render { | 
				
			||||
	 | 
				
			||||
	public static final VectConst AXIS_X = Vect.make(1, 0, 0); | 
				
			||||
	public static final VectConst AXIS_Y = Vect.make(0, 1, 0); | 
				
			||||
	public static final VectConst AXIS_Z = Vect.make(0, 0, 1); | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Bind GL color | 
				
			||||
	 *  | 
				
			||||
	 * @param color Color color | 
				
			||||
	 */ | 
				
			||||
	public static void setColor(Color color) | 
				
			||||
	{ | 
				
			||||
		if (color != null) glColor4d(color.r(), color.g(), color.b(), color.a()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Bind GL color | 
				
			||||
	 *  | 
				
			||||
	 * @param color Color color | 
				
			||||
	 * @param alpha alpha multiplier | 
				
			||||
	 */ | 
				
			||||
	public static void setColor(Color color, double alpha) | 
				
			||||
	{ | 
				
			||||
		if (color != null) glColor4d(color.r(), color.g(), color.b(), color.a() * alpha); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Translate | 
				
			||||
	 *  | 
				
			||||
	 * @param x | 
				
			||||
	 * @param y | 
				
			||||
	 */ | 
				
			||||
	public static void translate(double x, double y) | 
				
			||||
	{ | 
				
			||||
		glTranslated(x, y, 0); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Translate | 
				
			||||
	 *  | 
				
			||||
	 * @param x | 
				
			||||
	 * @param y | 
				
			||||
	 * @param z | 
				
			||||
	 */ | 
				
			||||
	public static void translate(double x, double y, double z) | 
				
			||||
	{ | 
				
			||||
		glTranslated(x, y, z); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Translate with coord | 
				
			||||
	 *  | 
				
			||||
	 * @param coord coord | 
				
			||||
	 */ | 
				
			||||
	public static void translate(Vect coord) | 
				
			||||
	{ | 
				
			||||
		glTranslated(coord.x(), coord.y(), coord.z()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Translate with coord, discard Z | 
				
			||||
	 *  | 
				
			||||
	 * @param coord coord | 
				
			||||
	 */ | 
				
			||||
	public static void translateXY(Vect coord) | 
				
			||||
	{ | 
				
			||||
		glTranslated(coord.x(), coord.y(), 0); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Scale | 
				
			||||
	 *  | 
				
			||||
	 * @param x | 
				
			||||
	 * @param y | 
				
			||||
	 */ | 
				
			||||
	public static void scale(double x, double y) | 
				
			||||
	{ | 
				
			||||
		glScaled(x, y, 0); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Scale | 
				
			||||
	 *  | 
				
			||||
	 * @param x | 
				
			||||
	 * @param y | 
				
			||||
	 * @param z | 
				
			||||
	 */ | 
				
			||||
	public static void scale(double x, double y, double z) | 
				
			||||
	{ | 
				
			||||
		glScaled(x, y, z); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Scale | 
				
			||||
	 *  | 
				
			||||
	 * @param factor vector of scaling factors | 
				
			||||
	 */ | 
				
			||||
	public static void scale(Vect factor) | 
				
			||||
	{ | 
				
			||||
		glScaled(factor.x(), factor.y(), factor.z()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Scale by X factor | 
				
			||||
	 *  | 
				
			||||
	 * @param factor scaling factor | 
				
			||||
	 */ | 
				
			||||
	public static void scaleXY(double factor) | 
				
			||||
	{ | 
				
			||||
		glScaled(factor, factor, 1); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Scale by X factor | 
				
			||||
	 *  | 
				
			||||
	 * @param factor scaling factor | 
				
			||||
	 */ | 
				
			||||
	public static void scaleX(double factor) | 
				
			||||
	{ | 
				
			||||
		glScaled(factor, 1, 1); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Scale by Y factor | 
				
			||||
	 *  | 
				
			||||
	 * @param factor scaling factor | 
				
			||||
	 */ | 
				
			||||
	public static void scaleY(double factor) | 
				
			||||
	{ | 
				
			||||
		glScaled(1, factor, 1); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Scale by Z factor | 
				
			||||
	 *  | 
				
			||||
	 * @param factor scaling factor | 
				
			||||
	 */ | 
				
			||||
	public static void scaleZ(double factor) | 
				
			||||
	{ | 
				
			||||
		glScaled(1, 1, factor); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Rotate around X axis | 
				
			||||
	 *  | 
				
			||||
	 * @param angle deg | 
				
			||||
	 */ | 
				
			||||
	public static void rotateX(double angle) | 
				
			||||
	{ | 
				
			||||
		rotate(angle, AXIS_X); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Rotate around Y axis | 
				
			||||
	 *  | 
				
			||||
	 * @param angle deg | 
				
			||||
	 */ | 
				
			||||
	public static void rotateY(double angle) | 
				
			||||
	{ | 
				
			||||
		rotate(angle, AXIS_Y); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Rotate around Z axis | 
				
			||||
	 *  | 
				
			||||
	 * @param angle deg | 
				
			||||
	 */ | 
				
			||||
	public static void rotateZ(double angle) | 
				
			||||
	{ | 
				
			||||
		rotate(angle, AXIS_Z); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Rotate | 
				
			||||
	 *  | 
				
			||||
	 * @param angle rotate angle | 
				
			||||
	 * @param axis rotation axis | 
				
			||||
	 */ | 
				
			||||
	public static void rotate(double angle, Vect axis) | 
				
			||||
	{ | 
				
			||||
		final Vect vec = axis.norm(1); | 
				
			||||
		glRotated(angle, vec.x(), vec.y(), vec.z()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	private static int pushed = 0; | 
				
			||||
	/** Can be used to avoid texture binding and glBegin/glEnd in textured quads */ | 
				
			||||
	public static boolean batchTexturedQuadMode; | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Store GL state | 
				
			||||
	 */ | 
				
			||||
	public static void pushState() | 
				
			||||
	{ | 
				
			||||
		pushed++; | 
				
			||||
		 | 
				
			||||
		if (pushed >= 100) { | 
				
			||||
			Log.w("Suspicious number of state pushes: " + pushed); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); | 
				
			||||
		GL11.glPushClientAttrib(GL11.GL_ALL_CLIENT_ATTRIB_BITS); | 
				
			||||
		GL11.glMatrixMode(GL11.GL_MODELVIEW); | 
				
			||||
		GL11.glPushMatrix(); | 
				
			||||
		GL11.glMatrixMode(GL11.GL_PROJECTION); | 
				
			||||
		GL11.glPushMatrix(); | 
				
			||||
		GL11.glMatrixMode(GL11.GL_MODELVIEW); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Restore Gl state | 
				
			||||
	 */ | 
				
			||||
	public static void popState() | 
				
			||||
	{ | 
				
			||||
		if (pushed == 0) { | 
				
			||||
			Log.w("Pop without push."); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		pushed--; | 
				
			||||
		 | 
				
			||||
		GL11.glMatrixMode(GL11.GL_PROJECTION); | 
				
			||||
		GL11.glPopMatrix(); | 
				
			||||
		GL11.glMatrixMode(GL11.GL_MODELVIEW); | 
				
			||||
		GL11.glPopMatrix(); | 
				
			||||
		GL11.glPopClientAttrib(); | 
				
			||||
		GL11.glPopAttrib(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Store matrix | 
				
			||||
	 */ | 
				
			||||
	public static void pushMatrix() | 
				
			||||
	{ | 
				
			||||
		GL11.glPushMatrix(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Restore Gl state | 
				
			||||
	 */ | 
				
			||||
	public static void popMatrix() | 
				
			||||
	{ | 
				
			||||
		GL11.glPopMatrix(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Load texture | 
				
			||||
	 *  | 
				
			||||
	 * @param resourcePath | 
				
			||||
	 * @param filtering filtering mode to use while loading. | 
				
			||||
	 * @return the loaded texture | 
				
			||||
	 */ | 
				
			||||
	public synchronized static Texture loadSlickTexture(String resourcePath, FilterMode filtering) | 
				
			||||
	{ | 
				
			||||
		 | 
				
			||||
		try { | 
				
			||||
			 | 
				
			||||
			final String ext = FileUtils.getExtension(resourcePath).toUpperCase(); | 
				
			||||
			 | 
				
			||||
			final Texture texture = TextureLoader.getTexture(ext, FileUtils.getResource(resourcePath), false, filtering.num); | 
				
			||||
			 | 
				
			||||
			if (texture == null) { | 
				
			||||
				Log.w("Texture " + resourcePath + " could not be loaded."); | 
				
			||||
			} | 
				
			||||
			 | 
				
			||||
			return texture; | 
				
			||||
			 | 
				
			||||
		} catch (final IOException e) { | 
				
			||||
			Log.e("Loading of texture " + resourcePath + " failed.", e); | 
				
			||||
			throw new RuntimeException("Could not load texture " + resourcePath + ".", e); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Render quad 2D | 
				
			||||
	 *  | 
				
			||||
	 * @param rect rectangle | 
				
			||||
	 * @param color draw color | 
				
			||||
	 */ | 
				
			||||
	public static void quad(Rect rect, Color color) | 
				
			||||
	{ | 
				
			||||
		setColor(color); | 
				
			||||
		quad(rect); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Render quad | 
				
			||||
	 *  | 
				
			||||
	 * @param quad the quad to draw (px) | 
				
			||||
	 */ | 
				
			||||
	public static void quad(Rect quad) | 
				
			||||
	{ | 
				
			||||
		final RectDigest q = quad.digest(); | 
				
			||||
		 | 
				
			||||
		// draw with color
 | 
				
			||||
		 | 
				
			||||
		glDisable(GL_TEXTURE_2D); | 
				
			||||
		 | 
				
			||||
		// quad
 | 
				
			||||
		glBegin(GL_QUADS); | 
				
			||||
		glVertex2d(q.left, q.bottom); | 
				
			||||
		glVertex2d(q.right, q.bottom); | 
				
			||||
		glVertex2d(q.right, q.top); | 
				
			||||
		glVertex2d(q.left, q.top); | 
				
			||||
		glEnd(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Draw quad with horizontal gradient | 
				
			||||
	 *  | 
				
			||||
	 * @param quad drawn quad bounds | 
				
			||||
	 * @param color1 left color | 
				
			||||
	 * @param color2 right color | 
				
			||||
	 */ | 
				
			||||
	public static void quadGradH(Rect quad, Color color1, Color color2) | 
				
			||||
	{ | 
				
			||||
		quadColor(quad, color1, color2, color2, color1); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	public static void quadColor(Rect quad, Color color) | 
				
			||||
	{ | 
				
			||||
		quadColor(quad, color, color, color, color); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Draw quad with coloured vertices. | 
				
			||||
	 *  | 
				
			||||
	 * @param quad drawn quad bounds | 
				
			||||
	 * @param colorHMinVMin | 
				
			||||
	 * @param colorHMaxVMin | 
				
			||||
	 * @param colorHMaxVMax | 
				
			||||
	 * @param colorHMinVMax | 
				
			||||
	 */ | 
				
			||||
	public static void quadColor(Rect quad, Color colorHMinVMin, Color colorHMaxVMin, Color colorHMaxVMax, Color colorHMinVMax) | 
				
			||||
	{ | 
				
			||||
		final RectDigest r = quad.digest(); | 
				
			||||
		 | 
				
			||||
		// draw with color
 | 
				
			||||
		 | 
				
			||||
		glDisable(GL_TEXTURE_2D); | 
				
			||||
		 | 
				
			||||
		glBegin(GL_QUADS); | 
				
			||||
		setColor(colorHMinVMax); | 
				
			||||
		glVertex2d(r.left, r.bottom); | 
				
			||||
		 | 
				
			||||
		setColor(colorHMaxVMax); | 
				
			||||
		glVertex2d(r.right, r.bottom); | 
				
			||||
		 | 
				
			||||
		setColor(colorHMaxVMin); | 
				
			||||
		glVertex2d(r.right, r.top); | 
				
			||||
		 | 
				
			||||
		setColor(colorHMinVMin); | 
				
			||||
		glVertex2d(r.left, r.top); | 
				
			||||
		glEnd(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Draw quad with vertical gradient | 
				
			||||
	 *  | 
				
			||||
	 * @param quad drawn quad bounds | 
				
			||||
	 * @param color1 top color | 
				
			||||
	 * @param color2 bottom color | 
				
			||||
	 */ | 
				
			||||
	public static void quadGradV(Rect quad, Color color1, Color color2) | 
				
			||||
	{ | 
				
			||||
		quadColor(quad, color1, color1, color2, color2); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Render textured rect | 
				
			||||
	 *  | 
				
			||||
	 * @param quad rectangle (px) | 
				
			||||
	 * @param txquad texture quad | 
				
			||||
	 */ | 
				
			||||
	public static void quadTextured(Rect quad, TxQuad txquad) | 
				
			||||
	{ | 
				
			||||
		quadTextured(quad, txquad, RGB.WHITE); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Render textured rect | 
				
			||||
	 *  | 
				
			||||
	 * @param quad rectangle (px) | 
				
			||||
	 * @param txquad texture instance | 
				
			||||
	 * @param tint color tint | 
				
			||||
	 */ | 
				
			||||
	public static void quadTextured(Rect quad, TxQuad txquad, Color tint) | 
				
			||||
	{ | 
				
			||||
		if (!batchTexturedQuadMode) { | 
				
			||||
			glEnable(GL_TEXTURE_2D); | 
				
			||||
			txquad.tx.bind(); | 
				
			||||
			glBegin(GL_QUADS); | 
				
			||||
			setColor(tint); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		final RectDigest q = quad.digest(); | 
				
			||||
		final RectDigest u = txquad.uvs.digest(); | 
				
			||||
		 | 
				
			||||
		final double offs = 0.0001;// hack to avoid white stitching
 | 
				
			||||
		 | 
				
			||||
		double tL = u.left + offs, tR = u.right - offs, tT = u.top + offs, tB = u.bottom - offs; | 
				
			||||
		 | 
				
			||||
		// handle flip
 | 
				
			||||
		if (txquad.isFlippedY()) { | 
				
			||||
			final double swap = tT; | 
				
			||||
			tT = tB; | 
				
			||||
			tB = swap; | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		if (txquad.isFlippedX()) { | 
				
			||||
			final double swap = tL; | 
				
			||||
			tL = tR; | 
				
			||||
			tR = swap; | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		final double w = txquad.tx.getWidth01(); | 
				
			||||
		final double h = txquad.tx.getHeight01(); | 
				
			||||
		 | 
				
			||||
		// quad with texture
 | 
				
			||||
		glTexCoord2d(tL * w, tB * h); | 
				
			||||
		glVertex2d(q.left, q.bottom); | 
				
			||||
		 | 
				
			||||
		glTexCoord2d(tR * w, tB * h); | 
				
			||||
		glVertex2d(q.right, q.bottom); | 
				
			||||
		 | 
				
			||||
		glTexCoord2d(tR * w, tT * h); | 
				
			||||
		glVertex2d(q.right, q.top); | 
				
			||||
		 | 
				
			||||
		glTexCoord2d(tL * w, tT * h); | 
				
			||||
		glVertex2d(q.left, q.top); | 
				
			||||
		 | 
				
			||||
		if (!batchTexturedQuadMode) glEnd(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Setup Ortho projection for 2D graphics | 
				
			||||
	 *  | 
				
			||||
	 * @param size viewport size (screen size) | 
				
			||||
	 */ | 
				
			||||
	public static void setupOrtho(Vect size) | 
				
			||||
	{ | 
				
			||||
		// fix projection for changed size
 | 
				
			||||
		glMatrixMode(GL_PROJECTION); | 
				
			||||
		glLoadIdentity(); | 
				
			||||
		glViewport(0, 0, size.xi(), size.yi()); | 
				
			||||
		glOrtho(0, size.xi(), size.yi(), 0, -1000, 1000); | 
				
			||||
		 | 
				
			||||
		// back to modelview
 | 
				
			||||
		glMatrixMode(GL_MODELVIEW); | 
				
			||||
		 | 
				
			||||
		glLoadIdentity(); | 
				
			||||
		 | 
				
			||||
		glDisable(GL_LIGHTING); | 
				
			||||
		 | 
				
			||||
		glClearDepth(1f); | 
				
			||||
		glEnable(GL_DEPTH_TEST); | 
				
			||||
		glDepthFunc(GL_LEQUAL); | 
				
			||||
		 | 
				
			||||
		glEnable(GL_NORMALIZE); | 
				
			||||
		 | 
				
			||||
		glShadeModel(GL_SMOOTH); | 
				
			||||
		 | 
				
			||||
		glEnable(GL_BLEND); | 
				
			||||
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	public static void enterBatchTexturedQuadMode(ITexture texture) | 
				
			||||
	{ | 
				
			||||
		texture.bind(); | 
				
			||||
		glBegin(GL11.GL_QUADS); | 
				
			||||
		batchTexturedQuadMode = true; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	public static void leaveBatchTexturedQuadMode() | 
				
			||||
	{ | 
				
			||||
		glEnd(); | 
				
			||||
		batchTexturedQuadMode = false; | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
Some files were not shown because too many files have changed in this diff Show More
					Loading…
					
					
				
		Reference in new issue