From 7d17d28a35f66befee28a94dc601b3f4558c425d Mon Sep 17 00:00:00 2001 From: austin Date: Fri, 5 Nov 2021 22:17:01 -0400 Subject: [PATCH] Fixing more bitmapchar bugs --- src/main/java/electrosphere/main/Globals.java | 4 +++ .../electrosphere/renderer/ModelUtils.java | 12 +++---- .../renderer/RenderingEngine.java | 33 +++++++++++++++++++ .../renderer/ui/WidgetUtils.java | 2 +- .../ui/font/bitmapchar/BitmapCharacter.java | 6 +++- 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/main/java/electrosphere/main/Globals.java b/src/main/java/electrosphere/main/Globals.java index 6b3a2b31..2391d02a 100644 --- a/src/main/java/electrosphere/main/Globals.java +++ b/src/main/java/electrosphere/main/Globals.java @@ -162,6 +162,10 @@ public class Globals { public static int WINDOW_WIDTH = 1920; public static int WINDOW_HEIGHT = 1080; + + //title bar dimensions + public static int WINDOW_TITLE_BAR_HEIGHT = 0; + public static float FOV = 90; //matrices for drawing models diff --git a/src/main/java/electrosphere/renderer/ModelUtils.java b/src/main/java/electrosphere/renderer/ModelUtils.java index 039625b8..07e74233 100644 --- a/src/main/java/electrosphere/renderer/ModelUtils.java +++ b/src/main/java/electrosphere/renderer/ModelUtils.java @@ -703,20 +703,20 @@ public class ModelUtils { glBindVertexArray(m.vertexArrayObject); //vertices FloatBuffer VertexArrayBufferData = BufferUtils.createFloatBuffer(12); - VertexArrayBufferData.put( 0); + VertexArrayBufferData.put(-1); VertexArrayBufferData.put( 1); - VertexArrayBufferData.put( 0); - VertexArrayBufferData.put( 0); + VertexArrayBufferData.put(-1); + VertexArrayBufferData.put(-1); VertexArrayBufferData.put( 1); - VertexArrayBufferData.put( 0); + VertexArrayBufferData.put(-1); - VertexArrayBufferData.put( 0); + VertexArrayBufferData.put(-1); VertexArrayBufferData.put( 1); VertexArrayBufferData.put( 1); - VertexArrayBufferData.put( 0); + VertexArrayBufferData.put(-1); VertexArrayBufferData.put( 1); VertexArrayBufferData.put( 1); diff --git a/src/main/java/electrosphere/renderer/RenderingEngine.java b/src/main/java/electrosphere/renderer/RenderingEngine.java index 31151310..f2e05b23 100644 --- a/src/main/java/electrosphere/renderer/RenderingEngine.java +++ b/src/main/java/electrosphere/renderer/RenderingEngine.java @@ -21,10 +21,12 @@ import electrosphere.renderer.framebuffer.Renderbuffer; import electrosphere.renderer.texture.Texture; import electrosphere.renderer.ui.Widget; import java.nio.FloatBuffer; +import java.nio.IntBuffer; import org.joml.Matrix4f; import org.joml.Quaternionf; import org.joml.Vector3d; import org.joml.Vector3f; +import org.lwjgl.BufferUtils; import org.lwjgl.glfw.GLFW; import static org.lwjgl.glfw.GLFW.GLFW_CONTEXT_VERSION_MAJOR; import static org.lwjgl.glfw.GLFW.GLFW_CONTEXT_VERSION_MINOR; @@ -136,6 +138,25 @@ public class RenderingEngine { glfwMakeContextCurrent(Globals.window); //Maximize it glfwMaximizeWindow(Globals.window); + //grab actual framebuffer + IntBuffer xBuffer = BufferUtils.createIntBuffer(1); + IntBuffer yBuffer = BufferUtils.createIntBuffer(1); + GLFW.glfwGetFramebufferSize(Globals.window, xBuffer, yBuffer); + + int bufferWidth = xBuffer.get(); + int bufferHeight = yBuffer.get(); + + //get title bar size + Globals.WINDOW_TITLE_BAR_HEIGHT = Globals.WINDOW_HEIGHT - bufferHeight; + + System.out.println(Globals.WINDOW_TITLE_BAR_HEIGHT); + + Globals.WINDOW_WIDTH = bufferWidth; + Globals.WINDOW_HEIGHT = bufferHeight; + + //get title bar dimensions +// setTitleBarDimensions(); + //Creates the OpenGL capabilities for the program. GL.createCapabilities(); @@ -665,4 +686,16 @@ public class RenderingEngine { glViewport(0, 0, width, height); } + public void setTitleBarDimensions(){ + IntBuffer tLeft = BufferUtils.createIntBuffer(1); + IntBuffer tTop = BufferUtils.createIntBuffer(1); + IntBuffer tRight = BufferUtils.createIntBuffer(1); + IntBuffer tBottom = BufferUtils.createIntBuffer(1); + + // Get the title bar dims + GLFW.glfwGetWindowFrameSize(Globals.window, tLeft, tTop, tRight, tBottom); + Globals.WINDOW_TITLE_BAR_HEIGHT = tTop.get(); +// System.out.println(tLeft.get() + " " + tTop.get() + " " + tRight.get() + " " + tBottom.get()); + } + } diff --git a/src/main/java/electrosphere/renderer/ui/WidgetUtils.java b/src/main/java/electrosphere/renderer/ui/WidgetUtils.java index a8c0e058..2f801276 100644 --- a/src/main/java/electrosphere/renderer/ui/WidgetUtils.java +++ b/src/main/java/electrosphere/renderer/ui/WidgetUtils.java @@ -95,7 +95,7 @@ public class WidgetUtils { // rVal.addWidget(textInput); - BitmapCharacter characterDisp = new BitmapCharacter(0,-50,500,500,'A'); + BitmapCharacter characterDisp = new BitmapCharacter(0,0,500,500,'A'); rVal.addWidget(characterDisp); // TextInput textInput2 = new TextInput(); diff --git a/src/main/java/electrosphere/renderer/ui/font/bitmapchar/BitmapCharacter.java b/src/main/java/electrosphere/renderer/ui/font/bitmapchar/BitmapCharacter.java index f471e95d..edfd0555 100644 --- a/src/main/java/electrosphere/renderer/ui/font/bitmapchar/BitmapCharacter.java +++ b/src/main/java/electrosphere/renderer/ui/font/bitmapchar/BitmapCharacter.java @@ -51,7 +51,7 @@ public class BitmapCharacter extends Widget { Globals.renderingEngine.bindFramebuffer(parentFramebufferPointer); Globals.renderingEngine.setViewportSize(parentWidth, parentHeight); float ndcX = (float)positionX/parentWidth; - float ndcY = (float)positionY/parentHeight; + float ndcY = (float)positionY/parentHeight + (float)Globals.WINDOW_TITLE_BAR_HEIGHT/parentHeight; float ndcWidth = (float)width/parentWidth; float ndcHeight = (float)height/parentHeight; // System.out.println(ndcX + " " + ndcY + " " + ndcWidth + " " + ndcHeight); @@ -63,6 +63,10 @@ public class BitmapCharacter extends Widget { Vector3f characterDimensions = new Vector3f(ndcWidth,ndcHeight,0); Vector3f bitMapPosition = FontUtils.getPositionOfCharacter(toDraw); Vector3f bitMapDimension = FontUtils.getDimensionOfCharacter(toDraw); +// bitMapDimension.y = 1; +// System.out.println(bitMapPosition); +// System.out.println(bitMapDimension); +// System.out.println("\n\n"); Model charModel = Globals.assetManager.fetchModel(AssetDataStrings.BITMAP_CHARACTER_MODEL); if(charModel != null && toDraw != ' '){ charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "mPosition", characterPosition);