|
|
@ -36,7 +36,7 @@ import org.lwjgl.opengl.GL11; |
|
|
|
* @author MightyPork |
|
|
|
* @author MightyPork |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class LwjglGraphicsModule extends GraphicsModule { |
|
|
|
public class LwjglGraphicsModule extends GraphicsModule { |
|
|
|
|
|
|
|
|
|
|
|
/** Currently binded color */ |
|
|
|
/** Currently binded color */ |
|
|
|
private Color activeColor = null; |
|
|
|
private Color activeColor = null; |
|
|
|
/** Currently binded color's alpha multiplier */ |
|
|
|
/** Currently binded color's alpha multiplier */ |
|
|
@ -45,187 +45,187 @@ public class LwjglGraphicsModule extends GraphicsModule { |
|
|
|
private final Stack<Color> colorPushStack = new Stack<>(); |
|
|
|
private final Stack<Color> colorPushStack = new Stack<>(); |
|
|
|
/** Currently binded texture */ |
|
|
|
/** Currently binded texture */ |
|
|
|
private SlickTexture activeTexture; |
|
|
|
private SlickTexture activeTexture; |
|
|
|
|
|
|
|
|
|
|
|
/** Display mode used currently for the window */ |
|
|
|
/** Display mode used currently for the window */ |
|
|
|
private DisplayMode windowDisplayMode; |
|
|
|
private DisplayMode windowDisplayMode; |
|
|
|
/** FPS the user wants */ |
|
|
|
/** FPS the user wants */ |
|
|
|
private int targetFps; |
|
|
|
private int targetFps; |
|
|
|
/** FPS meter used for measuring actual FPS */ |
|
|
|
/** FPS meter used for measuring actual FPS */ |
|
|
|
private final FpsMeter fpsMeter = new FpsMeter(); |
|
|
|
private final FpsMeter fpsMeter = new FpsMeter(); |
|
|
|
|
|
|
|
|
|
|
|
/** Flag that at the end of frame, fullscreen should be toggled. */ |
|
|
|
/** Flag that at the end of frame, fullscreen should be toggled. */ |
|
|
|
private boolean fullscreenToggleRequested; |
|
|
|
private boolean fullscreenToggleRequested; |
|
|
|
/** Flag that at the end of frame, fullscreen should be set. */ |
|
|
|
/** Flag that at the end of frame, fullscreen should be set. */ |
|
|
|
private boolean fullscreenSetRequested; |
|
|
|
private boolean fullscreenSetRequested; |
|
|
|
/** State to which fullscreen should be set. */ |
|
|
|
/** State to which fullscreen should be set. */ |
|
|
|
private boolean fullscreenSetState; |
|
|
|
private boolean fullscreenSetState; |
|
|
|
|
|
|
|
|
|
|
|
/** Current screen size */ |
|
|
|
/** Current screen size */ |
|
|
|
private static final Vect screenSize = new Vect() { |
|
|
|
private static final Vect screenSize = new Vect() { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double y() |
|
|
|
public double y() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Display.getHeight(); |
|
|
|
return Display.getHeight(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double x() |
|
|
|
public double x() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Display.getWidth(); |
|
|
|
return Display.getWidth(); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** Current screen rectangle */ |
|
|
|
/** Current screen rectangle */ |
|
|
|
private static final Rect rect = Rect.make(screenSize); |
|
|
|
private static final Rect rect = Rect.make(screenSize); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void init() |
|
|
|
public void init() |
|
|
|
{ |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void createDisplay() |
|
|
|
public void createDisplay() |
|
|
|
{ |
|
|
|
{ |
|
|
|
try { |
|
|
|
try { |
|
|
|
Display.create(); |
|
|
|
Display.create(); |
|
|
|
|
|
|
|
|
|
|
|
} catch (final Exception e) { |
|
|
|
} catch (final Exception e) { |
|
|
|
throw new RuntimeException("Could not initialize display.", e); |
|
|
|
throw new RuntimeException("Could not initialize display.", e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setColor(Color color) |
|
|
|
public void setColor(Color color) |
|
|
|
{ |
|
|
|
{ |
|
|
|
setColor(color, 1); |
|
|
|
setColor(color, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setColor(Color color, double alpha) |
|
|
|
public void setColor(Color color, double alpha) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (color == null) color = RGB.WHITE; |
|
|
|
if (color == null) color = RGB.WHITE; |
|
|
|
|
|
|
|
|
|
|
|
// color components can change over time - must use equals()
|
|
|
|
// color components can change over time - must use equals()
|
|
|
|
if (activeColorAlpha == alpha && color.equals(activeColor)) return; |
|
|
|
if (activeColorAlpha == alpha && color.equals(activeColor)) return; |
|
|
|
|
|
|
|
|
|
|
|
activeColor = color; |
|
|
|
activeColor = color; |
|
|
|
activeColorAlpha = alpha; |
|
|
|
activeColorAlpha = alpha; |
|
|
|
GL11.glColor4d(color.r(), color.g(), color.b(), alpha * color.a()); |
|
|
|
GL11.glColor4d(color.r(), color.g(), color.b(), alpha * color.a()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void translate(double x, double y) |
|
|
|
public void translate(double x, double y) |
|
|
|
{ |
|
|
|
{ |
|
|
|
glTranslated(x, y, 0); |
|
|
|
glTranslated(x, y, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void translate(double x, double y, double z) |
|
|
|
public void translate(double x, double y, double z) |
|
|
|
{ |
|
|
|
{ |
|
|
|
glTranslated(x, y, z); |
|
|
|
glTranslated(x, y, z); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void translate(Vect offset) |
|
|
|
public void translate(Vect offset) |
|
|
|
{ |
|
|
|
{ |
|
|
|
glTranslated(offset.x(), offset.y(), offset.z()); |
|
|
|
glTranslated(offset.x(), offset.y(), offset.z()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void translateXY(Vect offset) |
|
|
|
public void translateXY(Vect offset) |
|
|
|
{ |
|
|
|
{ |
|
|
|
glTranslated(offset.x(), offset.y(), 0); |
|
|
|
glTranslated(offset.x(), offset.y(), 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void scale(double x, double y) |
|
|
|
public void scale(double x, double y) |
|
|
|
{ |
|
|
|
{ |
|
|
|
glScaled(x, y, 0); |
|
|
|
glScaled(x, y, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void scale(double x, double y, double z) |
|
|
|
public void scale(double x, double y, double z) |
|
|
|
{ |
|
|
|
{ |
|
|
|
glScaled(x, y, z); |
|
|
|
glScaled(x, y, z); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void scale(Vect scale) |
|
|
|
public void scale(Vect scale) |
|
|
|
{ |
|
|
|
{ |
|
|
|
glScaled(scale.x(), scale.y(), scale.z()); |
|
|
|
glScaled(scale.x(), scale.y(), scale.z()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void scaleXY(double scale) |
|
|
|
public void scaleXY(double scale) |
|
|
|
{ |
|
|
|
{ |
|
|
|
glScaled(scale, scale, 1); |
|
|
|
glScaled(scale, scale, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void scaleX(double scale) |
|
|
|
public void scaleX(double scale) |
|
|
|
{ |
|
|
|
{ |
|
|
|
glScaled(scale, 1, 1); |
|
|
|
glScaled(scale, 1, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void scaleY(double scale) |
|
|
|
public void scaleY(double scale) |
|
|
|
{ |
|
|
|
{ |
|
|
|
glScaled(1, scale, 1); |
|
|
|
glScaled(1, scale, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void scaleZ(double scale) |
|
|
|
public void scaleZ(double scale) |
|
|
|
{ |
|
|
|
{ |
|
|
|
glScaled(1, 1, scale); |
|
|
|
glScaled(1, 1, scale); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void rotateX(double angle) |
|
|
|
public void rotateX(double angle) |
|
|
|
{ |
|
|
|
{ |
|
|
|
rotate(angle, AXIS_X); |
|
|
|
rotate(angle, AXIS_X); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void rotateY(double angle) |
|
|
|
public void rotateY(double angle) |
|
|
|
{ |
|
|
|
{ |
|
|
|
rotate(angle, AXIS_Y); |
|
|
|
rotate(angle, AXIS_Y); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void rotateZ(double angle) |
|
|
|
public void rotateZ(double angle) |
|
|
|
{ |
|
|
|
{ |
|
|
|
rotate(angle, AXIS_Z); |
|
|
|
rotate(angle, AXIS_Z); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void rotate(double angle, Vect axis) |
|
|
|
public void rotate(double angle, Vect axis) |
|
|
|
{ |
|
|
|
{ |
|
|
|
final Vect vec = axis.norm(1); |
|
|
|
final Vect vec = axis.norm(1); |
|
|
|
glRotated(angle, vec.x(), vec.y(), vec.z()); |
|
|
|
glRotated(angle, vec.x(), vec.y(), vec.z()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void pushState() |
|
|
|
public void pushState() |
|
|
|
{ |
|
|
|
{ |
|
|
@ -233,8 +233,8 @@ public class LwjglGraphicsModule extends GraphicsModule { |
|
|
|
GL11.glPushClientAttrib(GL11.GL_ALL_CLIENT_ATTRIB_BITS); |
|
|
|
GL11.glPushClientAttrib(GL11.GL_ALL_CLIENT_ATTRIB_BITS); |
|
|
|
GL11.glPushMatrix(); |
|
|
|
GL11.glPushMatrix(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void popState() |
|
|
|
public void popState() |
|
|
|
{ |
|
|
|
{ |
|
|
@ -242,47 +242,47 @@ public class LwjglGraphicsModule extends GraphicsModule { |
|
|
|
GL11.glPopClientAttrib(); |
|
|
|
GL11.glPopClientAttrib(); |
|
|
|
GL11.glPopAttrib(); |
|
|
|
GL11.glPopAttrib(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void pushGeometry() |
|
|
|
public void pushGeometry() |
|
|
|
{ |
|
|
|
{ |
|
|
|
GL11.glPushMatrix(); |
|
|
|
GL11.glPushMatrix(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void popGeometry() |
|
|
|
public void popGeometry() |
|
|
|
{ |
|
|
|
{ |
|
|
|
GL11.glPopMatrix(); |
|
|
|
GL11.glPopMatrix(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void pushColor() |
|
|
|
public void pushColor() |
|
|
|
{ |
|
|
|
{ |
|
|
|
colorPushStack.push(activeColor); |
|
|
|
colorPushStack.push(activeColor); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void popColor() |
|
|
|
public void popColor() |
|
|
|
{ |
|
|
|
{ |
|
|
|
setColor(colorPushStack.pop()); |
|
|
|
setColor(colorPushStack.pop()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void quad(Rect rect) |
|
|
|
public void quad(Rect rect) |
|
|
|
{ |
|
|
|
{ |
|
|
|
final RectDigest q = rect.digest(); |
|
|
|
final RectDigest q = rect.digest(); |
|
|
|
|
|
|
|
|
|
|
|
// disable texture
|
|
|
|
// disable texture
|
|
|
|
if (activeTexture != null) { |
|
|
|
if (activeTexture != null) { |
|
|
|
activeTexture = null; |
|
|
|
activeTexture = null; |
|
|
|
glDisable(GL_TEXTURE_2D); |
|
|
|
glDisable(GL_TEXTURE_2D); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// quad
|
|
|
|
// quad
|
|
|
|
glBegin(GL_QUADS); |
|
|
|
glBegin(GL_QUADS); |
|
|
|
glVertex2d(q.left, q.bottom); |
|
|
|
glVertex2d(q.left, q.bottom); |
|
|
@ -291,51 +291,51 @@ public class LwjglGraphicsModule extends GraphicsModule { |
|
|
|
glVertex2d(q.left, q.top); |
|
|
|
glVertex2d(q.left, q.top); |
|
|
|
glEnd(); |
|
|
|
glEnd(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void quad(Rect rect, Color color) |
|
|
|
public void quad(Rect rect, Color color) |
|
|
|
{ |
|
|
|
{ |
|
|
|
setColor(color); |
|
|
|
setColor(color); |
|
|
|
quad(rect); |
|
|
|
quad(rect); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void quad(Rect rect, Grad grad) |
|
|
|
public void quad(Rect rect, Grad grad) |
|
|
|
{ |
|
|
|
{ |
|
|
|
final RectDigest r = rect.digest(); |
|
|
|
final RectDigest r = rect.digest(); |
|
|
|
|
|
|
|
|
|
|
|
// disable texture
|
|
|
|
// disable texture
|
|
|
|
if (activeTexture != null) { |
|
|
|
if (activeTexture != null) { |
|
|
|
activeTexture = null; |
|
|
|
activeTexture = null; |
|
|
|
glDisable(GL_TEXTURE_2D); |
|
|
|
glDisable(GL_TEXTURE_2D); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// quad
|
|
|
|
// quad
|
|
|
|
glBegin(GL_QUADS); |
|
|
|
glBegin(GL_QUADS); |
|
|
|
setColor(grad.leftBottom); |
|
|
|
setColor(grad.leftBottom); |
|
|
|
glVertex2d(r.left, r.bottom); |
|
|
|
glVertex2d(r.left, r.bottom); |
|
|
|
|
|
|
|
|
|
|
|
setColor(grad.rightBottom); |
|
|
|
setColor(grad.rightBottom); |
|
|
|
glVertex2d(r.right, r.bottom); |
|
|
|
glVertex2d(r.right, r.bottom); |
|
|
|
|
|
|
|
|
|
|
|
setColor(grad.rightTop); |
|
|
|
setColor(grad.rightTop); |
|
|
|
glVertex2d(r.right, r.top); |
|
|
|
glVertex2d(r.right, r.top); |
|
|
|
|
|
|
|
|
|
|
|
setColor(grad.leftTop); |
|
|
|
setColor(grad.leftTop); |
|
|
|
glVertex2d(r.left, r.top); |
|
|
|
glVertex2d(r.left, r.top); |
|
|
|
glEnd(); |
|
|
|
glEnd(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void quad(Rect rect, TxQuad txquad) |
|
|
|
public void quad(Rect rect, TxQuad txquad) |
|
|
|
{ |
|
|
|
{ |
|
|
|
quad(rect, txquad, RGB.WHITE); |
|
|
|
quad(rect, txquad, RGB.WHITE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void quad(Rect rect, TxQuad txquad, Color color) |
|
|
|
public void quad(Rect rect, TxQuad txquad, Color color) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -345,150 +345,150 @@ public class LwjglGraphicsModule extends GraphicsModule { |
|
|
|
activeTexture = (SlickTexture) txquad.tx; |
|
|
|
activeTexture = (SlickTexture) txquad.tx; |
|
|
|
activeTexture.bind(); |
|
|
|
activeTexture.bind(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
glBegin(GL_QUADS); |
|
|
|
glBegin(GL_QUADS); |
|
|
|
setColor(color); |
|
|
|
setColor(color); |
|
|
|
|
|
|
|
|
|
|
|
final RectDigest q = rect.digest(); |
|
|
|
final RectDigest q = rect.digest(); |
|
|
|
final RectDigest u = txquad.uvs.digest(); |
|
|
|
final RectDigest u = txquad.uvs.digest(); |
|
|
|
|
|
|
|
|
|
|
|
final double offs = 0.0001;// hack to avoid white stitching
|
|
|
|
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; |
|
|
|
double tL = u.left + offs, tR = u.right - offs, tT = u.top + offs, tB = u.bottom - offs; |
|
|
|
|
|
|
|
|
|
|
|
// handle flip
|
|
|
|
// handle flip
|
|
|
|
if (txquad.isFlippedY()) { |
|
|
|
if (txquad.isFlippedY()) { |
|
|
|
final double swap = tT; |
|
|
|
final double swap = tT; |
|
|
|
tT = tB; |
|
|
|
tT = tB; |
|
|
|
tB = swap; |
|
|
|
tB = swap; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (txquad.isFlippedX()) { |
|
|
|
if (txquad.isFlippedX()) { |
|
|
|
final double swap = tL; |
|
|
|
final double swap = tL; |
|
|
|
tL = tR; |
|
|
|
tL = tR; |
|
|
|
tR = swap; |
|
|
|
tR = swap; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final double w = activeTexture.getWidth01(); |
|
|
|
final double w = activeTexture.getWidth01(); |
|
|
|
final double h = activeTexture.getHeight01(); |
|
|
|
final double h = activeTexture.getHeight01(); |
|
|
|
|
|
|
|
|
|
|
|
// quad with texture
|
|
|
|
// quad with texture
|
|
|
|
glTexCoord2d(tL * w, tB * h); |
|
|
|
glTexCoord2d(tL * w, tB * h); |
|
|
|
glVertex2d(q.left, q.bottom); |
|
|
|
glVertex2d(q.left, q.bottom); |
|
|
|
|
|
|
|
|
|
|
|
glTexCoord2d(tR * w, tB * h); |
|
|
|
glTexCoord2d(tR * w, tB * h); |
|
|
|
glVertex2d(q.right, q.bottom); |
|
|
|
glVertex2d(q.right, q.bottom); |
|
|
|
|
|
|
|
|
|
|
|
glTexCoord2d(tR * w, tT * h); |
|
|
|
glTexCoord2d(tR * w, tT * h); |
|
|
|
glVertex2d(q.right, q.top); |
|
|
|
glVertex2d(q.right, q.top); |
|
|
|
|
|
|
|
|
|
|
|
glTexCoord2d(tL * w, tT * h); |
|
|
|
glTexCoord2d(tL * w, tT * h); |
|
|
|
glVertex2d(q.left, q.top); |
|
|
|
glVertex2d(q.left, q.top); |
|
|
|
|
|
|
|
|
|
|
|
glEnd(); |
|
|
|
glEnd(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setupProjection() |
|
|
|
public void setupProjection() |
|
|
|
{ |
|
|
|
{ |
|
|
|
// fix projection for changed size
|
|
|
|
// fix projection for changed size
|
|
|
|
glMatrixMode(GL_PROJECTION); |
|
|
|
glMatrixMode(GL_PROJECTION); |
|
|
|
glLoadIdentity(); |
|
|
|
glLoadIdentity(); |
|
|
|
|
|
|
|
|
|
|
|
final int w = Display.getWidth(); |
|
|
|
final int w = Display.getWidth(); |
|
|
|
final int h = Display.getHeight(); |
|
|
|
final int h = Display.getHeight(); |
|
|
|
|
|
|
|
|
|
|
|
glViewport(0, 0, w, h); |
|
|
|
glViewport(0, 0, w, h); |
|
|
|
glOrtho(0, w, h, 0, -1000, 1000); |
|
|
|
glOrtho(0, w, h, 0, -1000, 1000); |
|
|
|
|
|
|
|
|
|
|
|
// back to modelview
|
|
|
|
// back to modelview
|
|
|
|
glMatrixMode(GL_MODELVIEW); |
|
|
|
glMatrixMode(GL_MODELVIEW); |
|
|
|
|
|
|
|
|
|
|
|
glLoadIdentity(); |
|
|
|
glLoadIdentity(); |
|
|
|
|
|
|
|
|
|
|
|
glDisable(GL_LIGHTING); |
|
|
|
glDisable(GL_LIGHTING); |
|
|
|
|
|
|
|
|
|
|
|
glClearDepth(1f); |
|
|
|
glClearDepth(1f); |
|
|
|
glEnable(GL_DEPTH_TEST); |
|
|
|
glEnable(GL_DEPTH_TEST); |
|
|
|
glDepthFunc(GL_LEQUAL); |
|
|
|
glDepthFunc(GL_LEQUAL); |
|
|
|
|
|
|
|
|
|
|
|
glEnable(GL_NORMALIZE); |
|
|
|
glEnable(GL_NORMALIZE); |
|
|
|
|
|
|
|
|
|
|
|
glShadeModel(GL_SMOOTH); |
|
|
|
glShadeModel(GL_SMOOTH); |
|
|
|
|
|
|
|
|
|
|
|
glEnable(GL_BLEND); |
|
|
|
glEnable(GL_BLEND); |
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public DeferredTexture createTextureResource(String path) |
|
|
|
public DeferredTexture createTextureResource(String path) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return new SlickTexture(path); |
|
|
|
return new SlickTexture(path); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public DeferredFont createFontResource(String path) |
|
|
|
public DeferredFont createFontResource(String path) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return new LwjglFont(path); |
|
|
|
return new LwjglFont(path); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void destroy() |
|
|
|
public void destroy() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Display.destroy(); |
|
|
|
Display.destroy(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setTargetFps(int fps) |
|
|
|
public void setTargetFps(int fps) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.targetFps = fps; |
|
|
|
this.targetFps = fps; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setFullscreen(boolean fs) |
|
|
|
public void setFullscreen(boolean fs) |
|
|
|
{ |
|
|
|
{ |
|
|
|
fullscreenSetRequested = true; |
|
|
|
fullscreenSetRequested = true; |
|
|
|
fullscreenSetState = fs; |
|
|
|
fullscreenSetState = fs; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void switchFullscreen() |
|
|
|
public void switchFullscreen() |
|
|
|
{ |
|
|
|
{ |
|
|
|
fullscreenToggleRequested = true; |
|
|
|
fullscreenToggleRequested = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean isFullscreen() |
|
|
|
public boolean isFullscreen() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Display.isFullscreen(); |
|
|
|
return Display.isFullscreen(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void doToggleFullscreen() |
|
|
|
private void doToggleFullscreen() |
|
|
|
{ |
|
|
|
{ |
|
|
|
doSetFullscreen(!Display.isFullscreen()); |
|
|
|
doSetFullscreen(!Display.isFullscreen()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void doSetFullscreen(boolean fs) |
|
|
|
private void doSetFullscreen(boolean fs) |
|
|
|
{ |
|
|
|
{ |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
if (Display.isFullscreen() == fs) return; // no work
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Display.isFullscreen() == fs) return; // no work
|
|
|
|
|
|
|
|
|
|
|
|
if (fs) { |
|
|
|
if (fs) { |
|
|
|
Log.f3("Entering fullscreen."); |
|
|
|
Log.f3("Entering fullscreen."); |
|
|
|
// save window resize
|
|
|
|
// save window resize
|
|
|
|
windowDisplayMode = new DisplayMode(Display.getWidth(), Display.getHeight()); |
|
|
|
windowDisplayMode = new DisplayMode(Display.getWidth(), Display.getHeight()); |
|
|
|
|
|
|
|
|
|
|
|
Display.setDisplayMode(Display.getDesktopDisplayMode()); |
|
|
|
Display.setDisplayMode(Display.getDesktopDisplayMode()); |
|
|
|
Display.setFullscreen(true); |
|
|
|
Display.setFullscreen(true); |
|
|
|
Display.update(); |
|
|
|
Display.update(); |
|
|
@ -497,9 +497,9 @@ public class LwjglGraphicsModule extends GraphicsModule { |
|
|
|
Display.setDisplayMode(windowDisplayMode); |
|
|
|
Display.setDisplayMode(windowDisplayMode); |
|
|
|
Display.update(); |
|
|
|
Display.update(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
App.bus().send(new ViewportChangeEvent(getSize())); |
|
|
|
App.bus().send(new ViewportChangeEvent(getSize())); |
|
|
|
|
|
|
|
|
|
|
|
} catch (final Throwable t) { |
|
|
|
} catch (final Throwable t) { |
|
|
|
Log.e("Failed to change fullscreen mode.", t); |
|
|
|
Log.e("Failed to change fullscreen mode.", t); |
|
|
|
try { |
|
|
|
try { |
|
|
@ -510,8 +510,8 @@ public class LwjglGraphicsModule extends GraphicsModule { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Screenshot takeScreenshot() |
|
|
|
public Screenshot takeScreenshot() |
|
|
|
{ |
|
|
|
{ |
|
|
@ -521,13 +521,13 @@ public class LwjglGraphicsModule extends GraphicsModule { |
|
|
|
final int bpp = 4; |
|
|
|
final int bpp = 4; |
|
|
|
final ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp); |
|
|
|
final ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp); |
|
|
|
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); |
|
|
|
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); |
|
|
|
|
|
|
|
|
|
|
|
final AwtScreenshot sc = new AwtScreenshot(width, height, bpp, buffer); |
|
|
|
final AwtScreenshot sc = new AwtScreenshot(width, height, bpp, buffer); |
|
|
|
|
|
|
|
|
|
|
|
return sc; |
|
|
|
return sc; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void beginFrame() |
|
|
|
public void beginFrame() |
|
|
|
{ |
|
|
|
{ |
|
|
@ -535,31 +535,31 @@ public class LwjglGraphicsModule extends GraphicsModule { |
|
|
|
if (Display.wasResized()) { |
|
|
|
if (Display.wasResized()) { |
|
|
|
App.bus().send(new ViewportChangeEvent(getSize())); |
|
|
|
App.bus().send(new ViewportChangeEvent(getSize())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (fullscreenToggleRequested) { |
|
|
|
if (fullscreenToggleRequested) { |
|
|
|
fullscreenToggleRequested = false; |
|
|
|
fullscreenToggleRequested = false; |
|
|
|
doToggleFullscreen(); |
|
|
|
doToggleFullscreen(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (fullscreenSetRequested) { |
|
|
|
if (fullscreenSetRequested) { |
|
|
|
fullscreenSetRequested = false; |
|
|
|
fullscreenSetRequested = false; |
|
|
|
doSetFullscreen(fullscreenSetState); |
|
|
|
doSetFullscreen(fullscreenSetState); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
glLoadIdentity(); |
|
|
|
glLoadIdentity(); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
fpsMeter.frame(); |
|
|
|
fpsMeter.frame(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void endFrame() |
|
|
|
public void endFrame() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Display.update(false); // don't poll input devices
|
|
|
|
Display.update(false); // don't poll input devices
|
|
|
|
Display.sync(targetFps); |
|
|
|
Display.sync(targetFps); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setSize(int width, int height) |
|
|
|
public void setSize(int width, int height) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -569,68 +569,68 @@ public class LwjglGraphicsModule extends GraphicsModule { |
|
|
|
throw new RuntimeException(e); |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setTitle(String title) |
|
|
|
public void setTitle(String title) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Display.setTitle(title); |
|
|
|
Display.setTitle(title); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setVSync(boolean vsync) |
|
|
|
public void setVSync(boolean vsync) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Display.setVSyncEnabled(vsync); |
|
|
|
Display.setVSyncEnabled(vsync); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setResizable(boolean resizable) |
|
|
|
public void setResizable(boolean resizable) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Display.setResizable(resizable); |
|
|
|
Display.setResizable(resizable); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Rect getRect() |
|
|
|
public Rect getRect() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return rect; |
|
|
|
return rect; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public long getFps() |
|
|
|
public long getFps() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return fpsMeter.getFPS(); |
|
|
|
return fpsMeter.getFPS(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Vect getCenter() |
|
|
|
public Vect getCenter() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return rect.center(); |
|
|
|
return rect.center(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public int getWidth() |
|
|
|
public int getWidth() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Display.getWidth(); |
|
|
|
return Display.getWidth(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public int getHeight() |
|
|
|
public int getHeight() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Display.getHeight(); |
|
|
|
return Display.getHeight(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Vect getSize() |
|
|
|
public Vect getSize() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return screenSize; |
|
|
|
return screenSize; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|