-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
224 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
odinmain/src/main/kotlin/me/odinmain/lwjgl/LWJGLFunctionProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package me.odinmain.lwjgl | ||
|
||
import org.lwjgl.opengl.GLContext | ||
import org.lwjgl.system.FunctionProvider | ||
import java.lang.reflect.Method | ||
import java.nio.ByteBuffer | ||
|
||
class LWJGLFunctionProvider : FunctionProvider { | ||
|
||
private var getFunctionAddress: Method? = null | ||
|
||
init { | ||
try { | ||
getFunctionAddress = GLContext::class.java.getDeclaredMethod("getFunctionAddress", String::class.java) | ||
getFunctionAddress?.isAccessible = true | ||
} catch (e: Exception) { | ||
throw RuntimeException(e) | ||
} | ||
} | ||
|
||
override fun getFunctionAddress(functionName: CharSequence): Long { | ||
try { | ||
return getFunctionAddress!!.invoke(null, functionName.toString()) as Long | ||
} catch (e: Exception) { | ||
throw RuntimeException(e) | ||
} | ||
} | ||
|
||
override fun getFunctionAddress(byteBuffer: ByteBuffer?): Long { | ||
throw UnsupportedOperationException() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package me.odinmain.lwjgl | ||
|
||
import net.minecraft.client.Minecraft | ||
import net.minecraft.client.gui.GuiScreen | ||
import net.minecraft.client.renderer.GlStateManager | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent | ||
import net.minecraftforge.fml.common.gameevent.TickEvent | ||
import org.lwjgl.nanovg.NVGColor | ||
import org.lwjgl.nanovg.NanoVG.* | ||
import org.lwjgl.nanovg.NanoVGGL2.NVG_ANTIALIAS | ||
import org.lwjgl.nanovg.NanoVGGL2.nvgCreate | ||
import org.lwjgl.opengl.Display | ||
import org.lwjgl.opengl.GL11 | ||
|
||
|
||
class LWJGLTest : GuiScreen() { | ||
|
||
var vg: Long = 0 | ||
|
||
override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) { | ||
super.drawScreen(mouseX, mouseY, partialTicks) | ||
|
||
if (vg == 0L) { | ||
vg = nvgCreate(NVG_ANTIALIAS) | ||
if (vg == 0L) { | ||
throw RuntimeException("Failed to create nvg context") | ||
} | ||
} | ||
|
||
val fb = Minecraft.getMinecraft().framebuffer | ||
if (!fb.isStencilEnabled) { | ||
fb.enableStencil() | ||
} | ||
|
||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS) | ||
|
||
nvgBeginFrame(vg, Display.getWidth().toFloat(), Display.getHeight().toFloat(), 1f) | ||
|
||
nvgBeginPath(vg) | ||
nvgRect(vg, 100f, 100f, 120f, 30f) | ||
nvgCircle(vg, 120f, 120f, 5f) | ||
nvgPathWinding(vg, NVG_HOLE) | ||
val color = NVGColor.create() | ||
nvgRGBA(255.toByte(), 192.toByte(), 0.toByte(), 255.toByte(), color) | ||
nvgFillColor(vg, color) | ||
nvgFill(vg) | ||
|
||
nvgEndFrame(vg) | ||
|
||
GlStateManager.popAttrib() | ||
} | ||
|
||
var gui: GuiScreen = LWJGLTest() | ||
|
||
@SubscribeEvent | ||
fun onTick(event: TickEvent.ClientTickEvent) { | ||
if (mc.thePlayer != null && mc.thePlayer != null) { | ||
Minecraft.getMinecraft().displayGuiScreen(gui) | ||
} | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
odinmain/src/main/kotlin/me/odinmain/lwjgl/plugin/LWJGLClassTransformer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package me.odinmain.lwjgl.plugin | ||
|
||
import net.minecraft.launchwrapper.IClassTransformer | ||
import org.objectweb.asm.ClassReader | ||
import org.objectweb.asm.ClassWriter | ||
import org.objectweb.asm.Opcodes | ||
import org.objectweb.asm.tree.* | ||
|
||
|
||
class LWJGLClassTransformer : IClassTransformer { | ||
|
||
override fun transform(name: String, transformedName: String, basicClass: ByteArray): ByteArray { | ||
if (name == "org.lwjgl.nanovg.NanoVGGLConfig") { | ||
val reader = ClassReader(basicClass) | ||
val node = ClassNode() | ||
reader.accept(node, ClassReader.EXPAND_FRAMES) | ||
|
||
for (method in node.methods) { | ||
if (method.name == "configGL") { | ||
val list = InsnList() | ||
|
||
list.add(VarInsnNode(Opcodes.LLOAD, 0)) | ||
list.add(TypeInsnNode(Opcodes.NEW, "me/odinmain/lwjgl/LWJGLFunctionProvider")) | ||
list.add(InsnNode(Opcodes.DUP)) | ||
list.add( | ||
MethodInsnNode( | ||
Opcodes.INVOKESPECIAL, | ||
"me/main/lwjgl/FunctionProvider", | ||
"<init>", | ||
"()V", | ||
false | ||
) | ||
) | ||
list.add( | ||
MethodInsnNode( | ||
Opcodes.INVOKESTATIC, | ||
"org/lwjgl/nanovg/NanoVGGLConfig", | ||
"config", | ||
"(JLorg/lwjgl/system/FunctionProvider;)V", | ||
false | ||
) | ||
) | ||
list.add(InsnNode(Opcodes.RETURN)) | ||
|
||
method.instructions.clear() | ||
method.instructions.insert(list) | ||
} | ||
} | ||
|
||
val cw = ClassWriter(ClassWriter.COMPUTE_FRAMES) | ||
node.accept(cw) | ||
return cw.toByteArray() | ||
} | ||
return basicClass | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
odinmain/src/main/kotlin/me/odinmain/lwjgl/plugin/LWJGLLoadingPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package me.odinmain.lwjgl.plugin | ||
|
||
import net.minecraft.launchwrapper.Launch | ||
import net.minecraft.launchwrapper.LaunchClassLoader | ||
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin | ||
|
||
|
||
class LWJGLLoadingPlugin : IFMLLoadingPlugin { | ||
|
||
init { | ||
try { | ||
val exceptionsField = LaunchClassLoader::class.java.getDeclaredField("classLoaderExceptions") | ||
exceptionsField.isAccessible = true | ||
val exceptions = exceptionsField[Launch.classLoader] as MutableSet<*> | ||
exceptions.remove("org.lwjgl.") | ||
} catch (e: Exception) { | ||
throw RuntimeException("e") | ||
} | ||
} | ||
|
||
override fun getASMTransformerClass(): Array<String> { | ||
return arrayOf("me.odinmain.lwjgl.plugin.LWJGLClassTransformer") | ||
} | ||
|
||
override fun getModContainerClass(): String? { | ||
return null | ||
} | ||
|
||
override fun getSetupClass(): String? { | ||
return null | ||
} | ||
|
||
override fun injectData(data: Map<String, Any>) { | ||
} | ||
|
||
override fun getAccessTransformerClass(): String? { | ||
return null | ||
} | ||
|
||
} |