added aspect stretch and dumb stretch mode to window
This commit is contained in:
parent
87c6bd90e9
commit
bc706369d0
|
@ -8,9 +8,11 @@ import com.danitheskunk.skunkworks.gfx.font.IFont;
|
|||
|
||||
abstract public class BaseWindow implements IWindow {
|
||||
protected final Engine engine;
|
||||
protected WindowStretchMode stretchMode;
|
||||
|
||||
public BaseWindow(Engine engine) {
|
||||
this.engine = engine;
|
||||
this.stretchMode = WindowStretchMode.ASPECT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -121,4 +123,10 @@ abstract public class BaseWindow implements IWindow {
|
|||
return loadNineSlice(engine.loadImage(path));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStretchMode(WindowStretchMode mode) {
|
||||
this.stretchMode = mode;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -35,5 +35,7 @@ public interface IWindow {
|
|||
|
||||
boolean shouldClose();
|
||||
|
||||
void setStretchMode(WindowStretchMode mode);
|
||||
|
||||
void tick();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package com.danitheskunk.skunkworks;
|
||||
|
||||
public enum WindowStretchMode {
|
||||
STRETCH, ASPECT, INTEGER
|
||||
}
|
|
@ -8,7 +8,6 @@ import com.danitheskunk.skunkworks.gfx.IRenderContext;
|
|||
import com.danitheskunk.skunkworks.gfx.ITexture;
|
||||
import com.danitheskunk.skunkworks.gfx.Image;
|
||||
import org.lwjgl.glfw.GLFWErrorCallback;
|
||||
import org.lwjgl.glfw.GLFWWindowCloseCallbackI;
|
||||
import org.lwjgl.opengl.GL;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
|
@ -225,6 +224,34 @@ public class Window extends BaseWindow {
|
|||
windowSize.getY()
|
||||
);
|
||||
|
||||
int tlx1 = 0;
|
||||
int tly1 = 0;
|
||||
int tlx2 = 0;
|
||||
int tly2 = 0;
|
||||
|
||||
switch(this.stretchMode) {
|
||||
case STRETCH: {
|
||||
tlx1 = 0;
|
||||
tly1 = 0;
|
||||
tlx2 = windowSize.getX();
|
||||
tly2 = windowSize.getY();
|
||||
break;
|
||||
}
|
||||
case ASPECT: {
|
||||
float scalex = (float) windowSize.getX() / (float) size.getX();
|
||||
float scaley = (float) windowSize.getY() / (float) size.getY();
|
||||
float scale = Math.min(scalex, scaley);
|
||||
|
||||
int xoff = (int)((windowSize.getX() - size.getX() * scale) / 2);
|
||||
int yoff = (int)((windowSize.getY() - size.getY() * scale) / 2);
|
||||
|
||||
tlx1 = xoff;
|
||||
tly1 = yoff;
|
||||
tlx2 = (int)(xoff + size.getX() * scale);
|
||||
tly2 = (int)(yoff + size.getY() * scale);
|
||||
break;
|
||||
}
|
||||
case INTEGER: {
|
||||
int scalex = windowSize.getX() / size.getX();
|
||||
int scaley = windowSize.getY() / size.getY();
|
||||
int scale = Math.max(1, Math.min(scalex, scaley));
|
||||
|
@ -232,10 +259,13 @@ public class Window extends BaseWindow {
|
|||
int xoff = (windowSize.getX() - size.getX() * scale) / 2;
|
||||
int yoff = (windowSize.getY() - size.getY() * scale) / 2;
|
||||
|
||||
int tlx1 = xoff;
|
||||
int tly1 = yoff;
|
||||
int tlx2 = xoff + size.getX() * scale;
|
||||
int tly2 = yoff + size.getY() * scale;
|
||||
tlx1 = xoff;
|
||||
tly1 = yoff;
|
||||
tlx2 = xoff + size.getX() * scale;
|
||||
tly2 = yoff + size.getY() * scale;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var texCoordIndex = programScaler.getAttribLocation("texCoord");
|
||||
|
|
Loading…
Reference in New Issue