Skip to content

Commit

Permalink
🔧 Improving stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
XyperCode committed Jan 11, 2024
1 parent 73030ea commit c77aba1
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 57 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.idea/.name
.idea/runConfigurations
.idea/modules
.idea/sonarlint
!.idea/discord.xml

*.iml
Expand Down
6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.1-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.4-SNAPSHOT" apply false
}

architectury {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.utils.GdxNativesLoader;
import com.mojang.blaze3d.platform.Window;
import io.github.ultreon.gdxminecraft.api.ModLoader;
import io.github.ultreon.gdxminecraft.impl.MinecraftApplication;
Expand Down Expand Up @@ -51,7 +52,7 @@ public class GdxMinecraft implements ApplicationListener {
public GdxMinecraft() {
instance = this;
try {
Lwjgl3NativesLoader.load();
GdxNativesLoader.load();
GdxMinecraft.app = new MinecraftApplication(this, Minecraft.getInstance());
} catch (Throwable e) {
CrashReport libGDXCrash = new CrashReport("LibGDX failed to initialize", e);
Expand All @@ -72,7 +73,7 @@ public static void init() {

public static void initialize() {
batch = new SpriteBatch();
Pixmap whitePix = new Pixmap(1, 1, Pixmap.Format.RGB888);
Pixmap whitePix = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
whitePix.drawPixel(0, 0, 0xffffffff);
Texture white = new Texture(whitePix, true);
shapeRenderer = new ShapeDrawer(batch, new TextureRegion(white));
Expand All @@ -88,15 +89,15 @@ public void create() {
}

public void resize0(int width, int height) {
LOGGER.info("Resizing to " + width + "x" + height);
Gdx.app.log("GDX-Minecraft", "Resizing to " + width + "x" + height);

batch.setProjectionMatrix(batch.getProjectionMatrix().setToOrtho(0, width, height, 0, -1000000, 1000000));

this.width = width;
this.height = height;

long windowHandle = window.getHandle();
if (Configuration.GLFW_CHECK_THREAD0.get(true)) {
if (Boolean.TRUE.equals(Configuration.GLFW_CHECK_THREAD0.get(true))) {
this.renderWindow(windowHandle, width, height);
} else {
if (posted) return;
Expand Down Expand Up @@ -130,17 +131,17 @@ public void render() {

@Override
public void pause() {

// Nothing
}

@Override
public void resume() {

// Nothing
}

@Override
public void dispose() {

batch.dispose();
}

public ApplicationLogger getApplicationLogger() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.utils.ScreenUtils;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.Lighting;
import com.mojang.blaze3d.systems.RenderSystem;
import io.github.ultreon.gdxminecraft.GdxMinecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.ApiStatus;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL20;
import space.earlygrey.shapedrawer.ShapeDrawer;

@SuppressWarnings("unused")
public class GdxScreen extends Screen {
private final GdxMinecraft gdx;
private GuiGraphics mcGfx;
private ShapeDrawer shapeRenderer;
private ShapeDrawer shapes;
private Batch batch;
private Exception failure;
protected BitmapFont font;
Expand Down Expand Up @@ -51,22 +57,38 @@ public final void render(GuiGraphics guiGraphics, int i, int j, float f) {

this.mcGfx = guiGraphics;

this.shapeRenderer = gdx.getShapeDrawer();
// this.shapeRenderer.getBatch().flush();
// Matrix4 matrix41 = this.shapeRenderer.getBatch().getProjectionMatrix().setToOrtho(0, this.width, this.height, 0, 0, 1000000);
// this.shapeRenderer.getBatch().setProjectionMatrix(matrix41);
this.shapeRenderer.setPixelSize(2.0f);
this.mcGfx.pose().pushPose();
this.mcGfx.pose().translate(0, 0, 1000000);

ScreenUtils.clear(0, 0, 0, 0);

GlStateManager._disableDepthTest();
GlStateManager._disableCull();
GlStateManager._disableBlend();

RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
for (int tex = GL20.GL_TEXTURE0; tex <= GL20.GL_TEXTURE31; tex++) {
RenderSystem.setShaderTexture(tex, GL20.GL_NONE);
}

this.shapes = gdx.getShapeDrawer();
this.shapes.getBatch().flush();
this.shapes.setPixelSize(2.0f);

this.batch = gdx.getBatch();
// var matrix4 = this.batch.getProjectionMatrix().cpy().setToOrtho(0, this.width, this.height, 0, -1000000, 1000000).scale(0, 0, -1);
// this.batch.setProjectionMatrix(matrix4);

try {
this.render(this.shapeRenderer, this.batch, i, j, f);
this.render(this.shapes, this.batch, i, j, f);
} catch (Exception e) {
this.failure = e;
GdxMinecraft.LOGGER.error("Failed to render LibGDX screen.", e);
}

this.mcGfx.pose().popPose();

GlStateManager._enableBlend();
GlStateManager._enableCull();
GlStateManager._enableDepthTest();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
package io.github.ultreon.gdxminecraft.mixin;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.backends.lwjgl3.DefaultLwjgl3Input;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationBase;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window;
import com.badlogic.gdx.utils.Disposable;
import org.lwjgl.glfw.*;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(DefaultLwjgl3Input.class)
public abstract class DefaultLwjgl3InputMixin implements Disposable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window;
import com.badlogic.gdx.utils.Disposable;
import com.mojang.blaze3d.platform.Window;
import io.github.ultreon.gdxminecraft.GdxMinecraft;
import io.github.ultreon.gdxminecraft.impl.MinecraftGdxLogger;
import io.github.ultreon.gdxminecraft.impl.MinecraftWindow;
import net.minecraft.client.Minecraft;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL11;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -29,7 +26,7 @@ public abstract class Lwjgl3ApplicationMixin implements Disposable {

@Redirect(method = "<init>*", at = @At(value = "INVOKE", target = "Lcom/badlogic/gdx/backends/lwjgl3/Lwjgl3Application;initializeGlfw()V"))
private void gdx_minecraft$redirectInit$initializeGLFW(ApplicationListener listener, Lwjgl3ApplicationConfiguration config) {

GdxMinecraft.LOGGER.error("Cleanup called on Lwjgl3Application, this is unsupported behavior!");
}

@Redirect(method = "<init>*", at = @At(value = "INVOKE", target = "Lcom/badlogic/gdx/backends/lwjgl3/Lwjgl3Application;setApplicationLogger(Lcom/badlogic/gdx/ApplicationLogger;)V"))
Expand All @@ -39,29 +36,27 @@ public abstract class Lwjgl3ApplicationMixin implements Disposable {

@Redirect(method = "<init>*", at = @At(value = "INVOKE", target = "Lcom/badlogic/gdx/backends/lwjgl3/Lwjgl3Application;cleanup()V"))
private void gdx_minecraft$redirectInit$cleanup(Lwjgl3Application instance) {

GdxMinecraft.LOGGER.error("cleanup() called on Lwjgl3Application, this is unsupported behavior!");
}

@Redirect(method = "<init>*", at = @At(value = "INVOKE", target = "Lcom/badlogic/gdx/backends/lwjgl3/Lwjgl3Application;cleanupWindows()V"))
private void gdx_minecraft$redirectInit$cleanupWindows(Lwjgl3Application instance) {

GdxMinecraft.LOGGER.error("cleanupWindows() called on Lwjgl3Application, this is unsupported behavior!");
}

/**
* @author XyperCode
* @author <a href="https://github.com/XyperCode">XyperCode</a>
* @reason Minecraft initializes the window already. Need to make it wrapped instead.
*/
@Overwrite(remap = false)
void createWindow(Lwjgl3Window window, Lwjgl3ApplicationConfiguration config, long sharedContext) {
// long windowHandle = createGlfwWindow(config, sharedContext);
if (GdxMinecraft.window == null) return;
if (this.gdx_minecraft$window != null) throw new UnsupportedOperationException("Window already created!");

this.gdx_minecraft$window = window;
GdxMinecraft.window.setGdxWindow(window);
GdxMinecraft.LOGGER.info("Created new window: " + window);
((Lwjgl3WindowAccessor)window).invokeCreate(GdxMinecraft.window.getHandle());
// window.setVisible(config.initialVisible);

for (int i = 0; i < 2; i++) {
GL11.glClearColor(0, 0, 0, 1);
Expand All @@ -71,8 +66,8 @@ void createWindow(Lwjgl3Window window, Lwjgl3ApplicationConfiguration config, lo
}

/**
* @author XyperCode
* @reason Minecraft already initializes the GLFW window.
* @author <a href="https://github.com/XyperCode">XyperCode</a>
* @reason Minecraft already initializes the GLFW window, and creating multiple windows is unsupported behavior.
*/
@Overwrite(remap = false)
static long createGlfwWindow(Lwjgl3ApplicationConfiguration config, long sharedContextWindow) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,18 @@ public GdxTestScreen(Screen screen) {
public void render(ShapeDrawer shapeDrawer, Batch batch, int i, int j, float f) {
super.render(shapeDrawer, batch, i, j, f);

// Gdx.gl.glFlush();
// batch.begin();

// Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE0);
// shapeDrawer.setColor(1, 0, 0, 1);
// shapeDrawer.filledRectangle(-50, -50, width + 100, height + 100);
// Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE0);
// batch.end();
// Always call begin() at the beginning of a batch.
batch.begin();
this.font.draw(batch, "Hello World!", 10, 10);
// batch.draw(texture, 0, 0, width, height, 0, 0, 1, 1);
batch.end();

// Draw a rectangle using the shape drawer.
shapeDrawer.setColor(1, 1, 3, 8);
shapeDrawer.filledCircle(0, 0, 250, Color.SCARLET);

// texture.bind(0);
// MESH.render(SHADER, GL20.GL_TRIANGLES);
// Gdx.gl.glFlush();
// Draw hello world text using font.
this.font.draw(batch, "Hello World!", 10, 10);

// Always call end() at the end of a batch.
batch.end();
}
public static Mesh createFullScreenQuad() {
MeshBuilder builder = new MeshBuilder();
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip

0 comments on commit c77aba1

Please sign in to comment.