Fixed flat render depth and added a test crosshair
This commit is contained in:
parent
1ed8f93af4
commit
3b2621c82b
@ -46,11 +46,11 @@ public abstract class Layer {
|
|||||||
|
|
||||||
protected abstract void doRender();
|
protected abstract void doRender();
|
||||||
|
|
||||||
protected float getWidth() {
|
protected int getWidth() {
|
||||||
return GraphicsInterface.getFramebufferWidth();
|
return GraphicsInterface.getFramebufferWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected float getHeight() {
|
protected int getHeight() {
|
||||||
return GraphicsInterface.getFramebufferHeight();
|
return GraphicsInterface.getFramebufferHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@ import ru.windcorp.optica.client.graphics.model.ShapeRenderHelper;
|
|||||||
|
|
||||||
public class FlatRenderHelper extends ShapeRenderHelper {
|
public class FlatRenderHelper extends ShapeRenderHelper {
|
||||||
|
|
||||||
|
private static final float MAX_DEPTH = 1 << 16;
|
||||||
|
|
||||||
private final Mask mask = new Mask();
|
private final Mask mask = new Mask();
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -58,8 +60,9 @@ public class FlatRenderHelper extends ShapeRenderHelper {
|
|||||||
private void setupScreenTransform() {
|
private void setupScreenTransform() {
|
||||||
float width = GraphicsInterface.getFramebufferWidth();
|
float width = GraphicsInterface.getFramebufferWidth();
|
||||||
float height = GraphicsInterface.getFramebufferHeight();
|
float height = GraphicsInterface.getFramebufferHeight();
|
||||||
|
|
||||||
getTransform().translate(-1, +1, 0).scale(2 / width, -2 / height, 1);
|
getTransform().translate(-1, +1, 0)
|
||||||
|
.scale(2 / width, -2 / height, 1 / MAX_DEPTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,16 +25,16 @@ public class LayerTestUI extends AssembledFlatLayer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void assemble(RenderTarget target) {
|
protected void assemble(RenderTarget target) {
|
||||||
final float width = 512 + 256;
|
final int width = 512 + 256;
|
||||||
final float height = 64;
|
final int height = 64;
|
||||||
final float border = 5;
|
final int border = 5;
|
||||||
|
|
||||||
final int boxColor = flag ? 0xEE8888 : 0xEEEE88;
|
final int boxColor = flag ? 0xEE8888 : 0xEEEE88;
|
||||||
final int borderColor = flag ? 0xAA4444 : 0xAAAA44;
|
final int borderColor = flag ? 0xAA4444 : 0xAAAA44;
|
||||||
final int boxShadowColor = flag ? 0x440000 : 0x444400;
|
final int boxShadowColor = flag ? 0x440000 : 0x444400;
|
||||||
|
|
||||||
float x = (getWidth() - width) / 2;
|
int x = (getWidth() - width) / 2;
|
||||||
float y = getHeight() - height;
|
int y = getHeight() - height;
|
||||||
|
|
||||||
y -= 2*border;
|
y -= 2*border;
|
||||||
|
|
||||||
@ -43,13 +43,58 @@ public class LayerTestUI extends AssembledFlatLayer {
|
|||||||
target.fill(x, y, width, height, borderColor);
|
target.fill(x, y, width, height, borderColor);
|
||||||
target.fill(x + border, y + border, width - 2*border, height - 2*border, boxColor);
|
target.fill(x + border, y + border, width - 2*border, height - 2*border, boxColor);
|
||||||
|
|
||||||
final float texShadow = 2;
|
final int texShadow = 2;
|
||||||
final float texSize = height - 4*border;
|
final int texSize = height - 4*border;
|
||||||
|
|
||||||
target.fill(x + 2*border + texShadow, y + 2*border + texShadow, texSize, texSize, Colors.BLACK);
|
target.fill(x + 2*border + texShadow, y + 2*border + texShadow, texSize, texSize, Colors.BLACK);
|
||||||
target.drawTexture(x + 2*border, y + 2*border, texSize, texSize, qtex("compass"));
|
target.drawTexture(x + 2*border, y + 2*border, texSize, texSize, qtex("compass"));
|
||||||
|
|
||||||
|
drawCross(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void drawCross(RenderTarget target) {
|
||||||
|
int cx = getWidth() / 2;
|
||||||
|
int cy = getHeight() / 2;
|
||||||
|
|
||||||
|
final int length = 15;
|
||||||
|
final int thickness = 5;
|
||||||
|
final int borderSize = 1;
|
||||||
|
final int borderColor = Colors.BLACK;
|
||||||
|
final int fillColor = Colors.WHITE;
|
||||||
|
|
||||||
|
target.fill(
|
||||||
|
cx - length - thickness / 2,
|
||||||
|
cy - thickness / 2,
|
||||||
|
2*length + thickness,
|
||||||
|
thickness,
|
||||||
|
borderColor
|
||||||
|
);
|
||||||
|
|
||||||
|
target.fill(
|
||||||
|
cx - thickness / 2,
|
||||||
|
cy - length - thickness / 2,
|
||||||
|
thickness,
|
||||||
|
2*length + thickness,
|
||||||
|
borderColor
|
||||||
|
);
|
||||||
|
|
||||||
|
target.fill(
|
||||||
|
cx - length - thickness / 2 + borderSize,
|
||||||
|
cy - thickness / 2 + borderSize,
|
||||||
|
2*length + thickness - 2*borderSize,
|
||||||
|
thickness - 2*borderSize,
|
||||||
|
fillColor
|
||||||
|
);
|
||||||
|
|
||||||
|
target.fill(
|
||||||
|
cx - thickness / 2 + borderSize,
|
||||||
|
cy - length - thickness / 2 + borderSize,
|
||||||
|
thickness - 2*borderSize,
|
||||||
|
2*length + thickness - 2*borderSize,
|
||||||
|
fillColor
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onKeyEvent(KeyEvent event) {
|
public void onKeyEvent(KeyEvent event) {
|
||||||
if (event.isRepeat() || event.getKey() != GLFW.GLFW_KEY_LEFT_CONTROL) {
|
if (event.isRepeat() || event.getKey() != GLFW.GLFW_KEY_LEFT_CONTROL) {
|
||||||
|
@ -16,8 +16,6 @@ import ru.windcorp.optica.client.graphics.texture.Texture;
|
|||||||
|
|
||||||
public class RenderTarget {
|
public class RenderTarget {
|
||||||
|
|
||||||
private static final int MAX_DEPTH = 1 << 16;
|
|
||||||
|
|
||||||
private final List<AssembledFlatLayer.Clip> assembled = new ArrayList<>();
|
private final List<AssembledFlatLayer.Clip> assembled = new ArrayList<>();
|
||||||
|
|
||||||
private final Deque<Mask> maskStack = new LinkedList<>();
|
private final Deque<Mask> maskStack = new LinkedList<>();
|
||||||
@ -126,30 +124,30 @@ public class RenderTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void drawTexture(
|
public void drawTexture(
|
||||||
float x, float y, float width, float height,
|
int x, int y, int width, int height,
|
||||||
int color, Texture texture
|
int color, Texture texture
|
||||||
) {
|
) {
|
||||||
float depth = this.depth-- / (float) MAX_DEPTH;
|
float depth = this.depth--;
|
||||||
|
|
||||||
addFaceToCurrentClip(Faces.createRectangle(
|
addFaceToCurrentClip(Faces.createRectangle(
|
||||||
FlatRenderProgram.getDefault(),
|
FlatRenderProgram.getDefault(),
|
||||||
texture,
|
texture,
|
||||||
createVectorFromRGBInt(color),
|
createVectorFromRGBInt(color),
|
||||||
new Vec3(x, y + height, depth), // Flip
|
new Vec3(x, y + height, depth), // Flip
|
||||||
new Vec3(width, 0, depth),
|
new Vec3(width, 0, 0),
|
||||||
new Vec3(0, -height, depth)
|
new Vec3(0, -height, 0)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawTexture(
|
public void drawTexture(
|
||||||
float x, float y, float width, float height,
|
int x, int y, int width, int height,
|
||||||
Texture texture
|
Texture texture
|
||||||
) {
|
) {
|
||||||
drawTexture(x, y, width, height, Colors.WHITE, texture);
|
drawTexture(x, y, width, height, Colors.WHITE, texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fill(
|
public void fill(
|
||||||
float x, float y, float width, float height,
|
int x, int y, int width, int height,
|
||||||
int color
|
int color
|
||||||
) {
|
) {
|
||||||
drawTexture(x, y, width, height, color, null);
|
drawTexture(x, y, width, height, color, null);
|
||||||
|
Reference in New Issue
Block a user