Jenis - Jenis Texture pada OpenGl
89
createWindow; init;
while Display.isCloseRequested Keyboard.isKeyDownKeyboard.KEY_ESCAPE
{ render;
Display.update; }
deinit; Display.destroy;
} catch Exception e { e.printStackTrace;
System.exit0; }
} public abstract void render;
public abstract void deinit; private void createWindow throws LWJGLException {
Display.setTitlewindowTitle; Display.setFullscreenfullscreen;
Display.setVSyncEnabledvsync; DisplayMode displayMode = null;
DisplayMode d[] = Display.getAvailableDisplayModes; for int i = 0; i d.length; i++ {
if d[i].getWidth == width d[i].getHeight == height d[i].getBitsPerPixel == 32 {
displayMode = d[i]; break;
} }
Display.setDisplayModedisplayMode; Display.create;
} private void setOrthoMode {
glViewport0, 0, width, height; glMatrixModeGL_PROJECTION;
glPushMatrix; glLoadIdentity;
gluOrtho2D0, width, height, 0; glMatrixModeGL_MODELVIEW;
glPushMatrix; glLoadIdentity;
} private void unsetOrthoMode {
glPopMatrix; glMatrixModeGL_PROJECTION;
glPopMatrix; glMatrixModeGL_MODELVIEW;
} public abstract void init;
}
GCApplication.java
import java.awt.Color; import java.awt.Graphics;
90
import java.awt.color.ColorSpace; import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage;
import java.awt.image.ColorModel; import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer; import java.awt.image.DataBufferByte;
import java.awt.image.Raster; import java.awt.image.WritableRaster;
import java.io.IOException; import java.net.URL;
import java.nio.ByteBuffer; import java.nio.ByteOrder;
import java.util.Hashtable; import javax.imageio.ImageIO;
import org.newdawn.slick.util.ResourceLoader; public class Texture {
private ColorModel glAlphaColorModel = new ComponentColorModel
ColorSpace.getInstanceColorSpace.CS_sRGB, new int[] { 8, 8, 8, 8 }, true, false,
ComponentColorModel.TRANSLUCENT, DataBuffer.TYPE_BYTE; private ColorModel glColorModel = new ComponentColorModel
ColorSpace.getInstanceColorSpace.CS_sRGB, new int[] { 8, 8, 8, 0 }, false, false,
ComponentColorModel.OPAQUE, DataBuffer.TYPE_BYTE;
private ByteBuffer imageData; private int width;
private int height; private ByteBuffer convertImageDataBufferedImage
bufferedImage {
ByteBuffer imageBuffer; WritableRaster raster;
BufferedImage texImage;
int texWidth = bufferedImage.getWidth; int texHeight = bufferedImage.getHeight;
if bufferedImage.getColorModel.hasAlpha { raster= Raster.createInterleavedRaster
DataBuffer.TYPE_BYTE,texWidth, texHeight,
4, null;
texImage = new BufferedImageglAlphaColorModel, raster, false,new HashtableString, Object;
} else { raster =Raster.createInterleavedRaster
DataBuffer.TYPE_BYTE,texWidth,texHeight,3,null; texImage= new BufferedImageglColorModel,
raster, false,new HashtableString, Object;