本文整理汇总了Java中org.newdawn.slick.opengl.renderer.SGL类的典型用法代码示例。如果您正苦于以下问题:Java SGL类的具体用法?Java SGL怎么用?Java SGL使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SGL类属于org.newdawn.slick.opengl.renderer包,在下文中一共展示了SGL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Image
import org.newdawn.slick.opengl.renderer.SGL; //导入依赖的package包/类
/**
* Create an image based on a file at the specified location
*
* @param ref The location of the image file to load
* @param flipped True if the image should be flipped on the y-axis on load
* @param f The filtering method to use when scaling this image
* @param transparent The color to treat as transparent
* @throws SlickException Indicates a failure to load the image
*/
public Image(String ref, boolean flipped, int f, Color transparent) throws SlickException {
this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;
this.transparent = transparent;
this.flipped = flipped;
try {
this.ref = ref;
int[] trans = null;
if (transparent != null) {
trans = new int[3];
trans[0] = (int) (transparent.r * 255);
trans[1] = (int) (transparent.g * 255);
trans[2] = (int) (transparent.b * 255);
}
texture = InternalTextureLoader.get().getTexture(ref, flipped, filter, trans);
} catch (IOException e) {
Log.error(e);
throw new SlickException("Failed to load image from: "+ref, e);
}
}
示例2: load
import org.newdawn.slick.opengl.renderer.SGL; //导入依赖的package包/类
/**
* Load the image
*
* @param in The input stream to read the image from
* @param ref The name that should be assigned to the image
* @param flipped True if the image should be flipped on the y-axis on load
* @param f The filter to use when scaling this image
* @param transparent The color to treat as transparent
* @throws SlickException Indicates a failure to load the image
*/
private void load(InputStream in, String ref, boolean flipped, int f, Color transparent) throws SlickException {
this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;
try {
this.ref = ref;
int[] trans = null;
if (transparent != null) {
trans = new int[3];
trans[0] = (int) (transparent.r * 255);
trans[1] = (int) (transparent.g * 255);
trans[2] = (int) (transparent.b * 255);
}
texture = InternalTextureLoader.get().getTexture(in, ref, flipped, filter, trans);
} catch (IOException e) {
Log.error(e);
throw new SlickException("Failed to load image from: "+ref, e);
}
}
示例3: reload
import org.newdawn.slick.opengl.renderer.SGL; //导入依赖的package包/类
/**
* Reload a given texture blob
*
* @param texture The texture being reloaded
* @param srcPixelFormat The source pixel format
* @param componentCount The component count
* @param minFilter The minification filter
* @param magFilter The magnification filter
* @param textureBuffer The pixel data
* @return The ID of the newly created texture
*/
public int reload(TextureImpl texture, int srcPixelFormat, int componentCount,
int minFilter, int magFilter, ByteBuffer textureBuffer) {
int target = SGL.GL_TEXTURE_2D;
int textureID = createTextureID();
GL.glBindTexture(target, textureID);
GL.glTexParameteri(target, SGL.GL_TEXTURE_MIN_FILTER, minFilter);
GL.glTexParameteri(target, SGL.GL_TEXTURE_MAG_FILTER, magFilter);
// produce a texture from the byte buffer
GL.glTexImage2D(target,
0,
dstPixelFormat,
texture.getTextureWidth(),
texture.getTextureHeight(),
0,
srcPixelFormat,
SGL.GL_UNSIGNED_BYTE,
textureBuffer);
return textureID;
}
示例4: setWorldClip
import org.newdawn.slick.opengl.renderer.SGL; //导入依赖的package包/类
/**
* Set clipping that controls which areas of the world will be drawn to.
* Note that world clip is different from standard screen clip in that it's
* defined in the space of the current world coordinate - i.e. it's affected
* by translate, rotate, scale etc.
*
* @param x
* The x coordinate of the top left corner of the allowed area
* @param y
* The y coordinate of the top left corner of the allowed area
* @param width
* The width of the allowed area
* @param height
* The height of the allowed area
*/
public void setWorldClip(float x, float y, float width, float height) {
predraw();
worldClipRecord = new Rectangle(x, y, width, height);
GL.glEnable(SGL.GL_CLIP_PLANE0);
worldClip.put(1).put(0).put(0).put(-x).flip();
GL.glClipPlane(SGL.GL_CLIP_PLANE0, worldClip);
GL.glEnable(SGL.GL_CLIP_PLANE1);
worldClip.put(-1).put(0).put(0).put(x + width).flip();
GL.glClipPlane(SGL.GL_CLIP_PLANE1, worldClip);
GL.glEnable(SGL.GL_CLIP_PLANE2);
worldClip.put(0).put(1).put(0).put(-y).flip();
GL.glClipPlane(SGL.GL_CLIP_PLANE2, worldClip);
GL.glEnable(SGL.GL_CLIP_PLANE3);
worldClip.put(0).put(-1).put(0).put(y + height).flip();
GL.glClipPlane(SGL.GL_CLIP_PLANE3, worldClip);
postdraw();
}
示例5: fill
import org.newdawn.slick.opengl.renderer.SGL; //导入依赖的package包/类
/**
* Draw the the given shape filled in. Only the vertices are set.
* The colour has to be set independently of this method.
*
* @param shape The shape to fill.
* @param callback The callback that will be invoked for each shape point
*/
private static final void fill(Shape shape, PointCallback callback) {
Triangulator tris = shape.getTriangles();
GL.glBegin(SGL.GL_TRIANGLES);
for (int i=0;i<tris.getTriangleCount();i++) {
for (int p=0;p<3;p++) {
float[] pt = tris.getTrianglePoint(i, p);
float[] np = callback.preRenderPoint(shape, pt[0],pt[1]);
if (np == null) {
GL.glVertex2f(pt[0],pt[1]);
} else {
GL.glVertex2f(np[0],np[1]);
}
}
}
GL.glEnd();
}
示例6: renderGlyph
import org.newdawn.slick.opengl.renderer.SGL; //导入依赖的package包/类
/**
* Loads a single glyph to the backing texture, if it fits.
*
* @param glyph The glyph to be rendered
* @param width The expected width of the glyph
* @param height The expected height of the glyph
* @throws SlickException if the glyph could not be rendered.
*/
private void renderGlyph(Glyph glyph, int width, int height) throws SlickException {
// Draw the glyph to the scratch image using Java2D.
scratchGraphics.setComposite(AlphaComposite.Clear);
scratchGraphics.fillRect(0, 0, MAX_GLYPH_SIZE, MAX_GLYPH_SIZE);
scratchGraphics.setComposite(AlphaComposite.SrcOver);
scratchGraphics.setColor(java.awt.Color.white);
for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();)
((Effect)iter.next()).draw(scratchImage, scratchGraphics, unicodeFont, glyph);
glyph.setShape(null); // The shape will never be needed again.
WritableRaster raster = scratchImage.getRaster();
int[] row = new int[width];
for (int y = 0; y < height; y++) {
raster.getDataElements(0, y, width, 1, row);
scratchIntBuffer.put(row);
}
GL.glTexSubImage2D(SGL.GL_TEXTURE_2D, 0, pageX, pageY, width, height, SGL.GL_BGRA, SGL.GL_UNSIGNED_BYTE,
scratchByteBuffer);
scratchIntBuffer.clear();
glyph.setImage(pageImage.getSubImage(pageX, pageY, width, height));
}
示例7: build
import org.newdawn.slick.opengl.renderer.SGL; //导入依赖的package包/类
/**
* Build the display list
*/
private void build() {
if (list == -1) {
list = GL.glGenLists(1);
SlickCallable.enterSafeBlock();
GL.glNewList(list, SGL.GL_COMPILE);
runnable.run();
GL.glEndList();
SlickCallable.leaveSafeBlock();
} else {
throw new RuntimeException("Attempt to build the display list more than once in CachedRender");
}
}
示例8: clampTexture
import org.newdawn.slick.opengl.renderer.SGL; //导入依赖的package包/类
/**
* Clamp the loaded texture to it's edges
*/
public void clampTexture() {
if (GL.canTextureMirrorClamp()) {
GL.glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_S, SGL.GL_MIRROR_CLAMP_TO_EDGE_EXT);
GL.glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_T, SGL.GL_MIRROR_CLAMP_TO_EDGE_EXT);
} else {
GL.glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_S, SGL.GL_CLAMP);
GL.glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_T, SGL.GL_CLAMP);
}
}
示例9: drawString
import org.newdawn.slick.opengl.renderer.SGL; //导入依赖的package包/类
/**
* @see Font#drawString(float, float, String, Color, int, int)
*/
public void drawString(float x, float y, String text, Color col,
int startIndex, int endIndex) {
fontImage.bind();
col.bind();
GL.glTranslatef(x, y, 0);
if (displayListCaching && startIndex == 0 && endIndex == text.length() - 1) {
DisplayList displayList = (DisplayList)displayLists.get(text);
if (displayList != null) {
GL.glCallList(displayList.id);
} else {
// Compile a new display list.
displayList = new DisplayList();
displayList.text = text;
int displayListCount = displayLists.size();
if (displayListCount < DISPLAY_LIST_CACHE_SIZE) {
displayList.id = baseDisplayListID + displayListCount;
} else {
displayList.id = eldestDisplayListID;
displayLists.remove(eldestDisplayList.text);
}
displayLists.put(text, displayList);
GL.glNewList(displayList.id, SGL.GL_COMPILE_AND_EXECUTE);
render(text, startIndex, endIndex);
GL.glEndList();
}
} else {
render(text, startIndex, endIndex);
}
GL.glTranslatef(-x, -y, 0);
}
示例10: render
import org.newdawn.slick.opengl.renderer.SGL; //导入依赖的package包/类
/**
* Render based on immediate rendering
*
* @param text The text to be rendered
* @param start The index of the first character in the string to render
* @param end The index of the last character in the string to render
*/
private void render(String text, int start, int end) {
GL.glBegin(SGL.GL_QUADS);
int x = 0, y = 0;
CharDef lastCharDef = null;
char[] data = text.toCharArray();
for (int i = 0; i < data.length; i++) {
int id = data[i];
if (id == '\n') {
x = 0;
y += getLineHeight();
continue;
}
if (id >= chars.length) {
continue;
}
CharDef charDef = chars[id];
if (charDef == null) {
continue;
}
if (lastCharDef != null) x += lastCharDef.getKerning(id);
lastCharDef = charDef;
if ((i >= start) && (i <= end)) {
charDef.draw(x, y);
}
x += charDef.xadvance;
}
GL.glEnd();
}
示例11: fillRect
import org.newdawn.slick.opengl.renderer.SGL; //导入依赖的package包/类
/**
* Fill a rectangle on the canvas in the current color
*
* @param x1
* The x coordinate of the top left corner
* @param y1
* The y coordinate of the top left corner
* @param width
* The width of the rectangle to fill
* @param height
* The height of the rectangle to fill
*/
public void fillRect(float x1, float y1, float width, float height) {
predraw();
TextureImpl.bindNone();
currentColor.bind();
GL.glBegin(SGL.GL_QUADS);
GL.glVertex2f(x1, y1);
GL.glVertex2f(x1 + width, y1);
GL.glVertex2f(x1 + width, y1 + height);
GL.glVertex2f(x1, y1 + height);
GL.glEnd();
postdraw();
}
示例12: draw
import org.newdawn.slick.opengl.renderer.SGL; //导入依赖的package包/类
/**
* Draw a section of this image at a particular location and scale on the screen
*
* @param x The x position to draw the image
* @param y The y position to draw the image
* @param x2 The x position of the bottom right corner of the drawn image
* @param y2 The y position of the bottom right corner of the drawn image
* @param srcx The x position of the rectangle to draw from this image (i.e. relative to this image)
* @param srcy The y position of the rectangle to draw from this image (i.e. relative to this image)
* @param srcx2 The x position of the bottom right cornder of rectangle to draw from this image (i.e. relative to this image)
* @param srcy2 The t position of the bottom right cornder of rectangle to draw from this image (i.e. relative to this image)
* @param filter The colour filter to apply when drawing
*/
public void draw(float x, float y, float x2, float y2, float srcx, float srcy, float srcx2, float srcy2, Color filter) {
init();
if (alpha != 1) {
if (filter == null) {
filter = Color.white;
}
filter = new Color(filter);
filter.a *= alpha;
}
filter.bind();
texture.bind();
GL.glTranslatef(x, y, 0);
if (angle != 0) {
GL.glTranslatef(centerX, centerY, 0.0f);
GL.glRotatef(angle, 0.0f, 0.0f, 1.0f);
GL.glTranslatef(-centerX, -centerY, 0.0f);
}
GL.glBegin(SGL.GL_QUADS);
drawEmbedded(0,0,x2-x,y2-y,srcx,srcy,srcx2,srcy2);
GL.glEnd();
if (angle != 0) {
GL.glTranslatef(centerX, centerY, 0.0f);
GL.glRotatef(-angle, 0.0f, 0.0f, 1.0f);
GL.glTranslatef(-centerX, -centerY, 0.0f);
}
GL.glTranslatef(-x, -y, 0);
// GL.glBegin(SGL.GL_QUADS);
// drawEmbedded(x,y,x2,y2,srcx,srcy,srcx2,srcy2);
// GL.glEnd();
}
示例13: startUse
import org.newdawn.slick.opengl.renderer.SGL; //导入依赖的package包/类
/**
* Start using this sheet. This method can be used for optimal rendering of a collection
* of sprites from a single sprite sheet. First, startUse(). Then render each sprite by
* calling renderInUse(). Finally, endUse(). Between start and end there can be no rendering
* of other sprites since the rendering is locked for this sprite sheet.
*/
public void startUse() {
if (inUse != null) {
throw new RuntimeException("Attempt to start use of a sprite sheet before ending use with another - see endUse()");
}
inUse = this;
init();
Color.white.bind();
texture.bind();
GL.glBegin(SGL.GL_QUADS);
}
示例14: getBackground
import org.newdawn.slick.opengl.renderer.SGL; //导入依赖的package包/类
/**
* Get the current graphics context background color
*
* @return The background color of this graphics context
*/
public Color getBackground() {
predraw();
FloatBuffer buffer = BufferUtils.createFloatBuffer(16);
GL.glGetFloat(SGL.GL_COLOR_CLEAR_VALUE, buffer);
postdraw();
return new Color(buffer);
}
示例15: bind
import org.newdawn.slick.opengl.renderer.SGL; //导入依赖的package包/类
/**
* @see org.newdawn.slick.opengl.Texture#bind()
*/
public void bind() {
if (lastBind != this) {
lastBind = this;
GL.glEnable(SGL.GL_TEXTURE_2D);
GL.glBindTexture(target, textureID);
}
}