|
|
@ -18,7 +18,6 @@ import mightypork.util.math.color.Color; |
|
|
|
|
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11; |
|
|
|
import org.lwjgl.opengl.GL11; |
|
|
|
import org.newdawn.slick.opengl.Texture; |
|
|
|
import org.newdawn.slick.opengl.Texture; |
|
|
|
import org.newdawn.slick.opengl.TextureImpl; |
|
|
|
|
|
|
|
import org.newdawn.slick.opengl.TextureLoader; |
|
|
|
import org.newdawn.slick.opengl.TextureLoader; |
|
|
|
import org.newdawn.slick.util.ResourceLoader; |
|
|
|
import org.newdawn.slick.util.ResourceLoader; |
|
|
|
|
|
|
|
|
|
|
@ -299,7 +298,7 @@ public class Render { |
|
|
|
* @param filtering filtering mode to use while loading. |
|
|
|
* @param filtering filtering mode to use while loading. |
|
|
|
* @return the loaded texture |
|
|
|
* @return the loaded texture |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public synchronized static Texture loadTexture(String resourcePath, FilterMode filtering) |
|
|
|
public synchronized static Texture loadSlickTexture(String resourcePath, FilterMode filtering) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
@ -322,29 +321,6 @@ public class Render { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Bind texture |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param texture the texture |
|
|
|
|
|
|
|
* @throws RuntimeException if not loaded yet |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private static void bindTexture(GLTexture texture) throws RuntimeException |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
texture.bind(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Unbind all |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private static void unbindTexture() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (TextureImpl.getLastBind() != null) { |
|
|
|
|
|
|
|
TextureImpl.bindNone(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Render quad 2D |
|
|
|
* Render quad 2D |
|
|
|
* |
|
|
|
* |
|
|
@ -368,7 +344,7 @@ public class Render { |
|
|
|
final RectDigest q = quad.digest(); |
|
|
|
final RectDigest q = quad.digest(); |
|
|
|
|
|
|
|
|
|
|
|
// draw with color
|
|
|
|
// draw with color
|
|
|
|
|
|
|
|
|
|
|
|
glDisable(GL_TEXTURE_2D); |
|
|
|
glDisable(GL_TEXTURE_2D); |
|
|
|
|
|
|
|
|
|
|
|
// quad
|
|
|
|
// quad
|
|
|
@ -381,47 +357,6 @@ public class Render { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Render textured rect (texture must be binded already) |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param quad rectangle (px) |
|
|
|
|
|
|
|
* @param uvs texture coords (0-1) |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static void quadUV(Rect quad, Rect uvs) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
glBegin(GL_QUADS); |
|
|
|
|
|
|
|
quadUV_nobound(quad, uvs); |
|
|
|
|
|
|
|
glEnd(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Draw quad without glBegin and glEnd. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param quad rectangle (px) |
|
|
|
|
|
|
|
* @param uvs texture coords (0-1) |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static void quadUV_nobound(Rect quad, Rect uvs) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
final RectDigest q = quad.digest(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final RectDigest u = uvs.digest(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// quad with texture
|
|
|
|
|
|
|
|
glTexCoord2d(u.left, u.bottom); |
|
|
|
|
|
|
|
glVertex2d(q.left, q.bottom); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glTexCoord2d(u.right, u.bottom); |
|
|
|
|
|
|
|
glVertex2d(q.right, q.bottom); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glTexCoord2d(u.right, u.top); |
|
|
|
|
|
|
|
glVertex2d(q.right, q.top); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glTexCoord2d(u.left, u.top); |
|
|
|
|
|
|
|
glVertex2d(q.left, q.top); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Draw quad with horizontal gradient |
|
|
|
* Draw quad with horizontal gradient |
|
|
|
* |
|
|
|
* |
|
|
@ -455,7 +390,7 @@ public class Render { |
|
|
|
final RectDigest r = quad.digest(); |
|
|
|
final RectDigest r = quad.digest(); |
|
|
|
|
|
|
|
|
|
|
|
// draw with color
|
|
|
|
// draw with color
|
|
|
|
|
|
|
|
|
|
|
|
glDisable(GL_TEXTURE_2D); |
|
|
|
glDisable(GL_TEXTURE_2D); |
|
|
|
|
|
|
|
|
|
|
|
glBegin(GL_QUADS); |
|
|
|
glBegin(GL_QUADS); |
|
|
@ -498,10 +433,32 @@ public class Render { |
|
|
|
public static void quadTextured(Rect quad, Rect uvs, GLTexture texture, Color tint) |
|
|
|
public static void quadTextured(Rect quad, Rect uvs, GLTexture texture, Color tint) |
|
|
|
{ |
|
|
|
{ |
|
|
|
glEnable(GL_TEXTURE_2D); |
|
|
|
glEnable(GL_TEXTURE_2D); |
|
|
|
bindTexture(texture); |
|
|
|
|
|
|
|
|
|
|
|
texture.bind(); |
|
|
|
|
|
|
|
|
|
|
|
setColor(tint); |
|
|
|
setColor(tint); |
|
|
|
quadUV(quad, uvs); |
|
|
|
|
|
|
|
unbindTexture(); |
|
|
|
glBegin(GL_QUADS); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final RectDigest q = quad.digest(); |
|
|
|
|
|
|
|
final RectDigest u = uvs.digest(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final double w = texture.getWidth01(); |
|
|
|
|
|
|
|
final double h = texture.getHeight01(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// quad with texture
|
|
|
|
|
|
|
|
glTexCoord2d(u.x * w, u.bottom * h); |
|
|
|
|
|
|
|
glVertex2d(q.left, q.bottom); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glTexCoord2d(u.right * w, u.bottom * h); |
|
|
|
|
|
|
|
glVertex2d(q.right, q.bottom); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glTexCoord2d(u.right * w, u.top * h); |
|
|
|
|
|
|
|
glVertex2d(q.right, q.top); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glTexCoord2d(u.left * w, u.top * h); |
|
|
|
|
|
|
|
glVertex2d(q.left, q.top); |
|
|
|
|
|
|
|
glEnd(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|