How to draw a gradient rect
Solved
ScriptAPI
-
How to draw a gradient rect?
Gui.drawGradientRect is 'protected'
-
its protected i cant access it
-
try { var method = Gui.class.getDeclaredMethod("drawGradientRect"); method.setAccessible(true); method.invoke(Gui.class, 10, 10, 10 + 50, 10 + 50, Color.RED.getRGB(), Color.BLUE.getRGB()); } catch (ex) { ex.printStackTrace(); }
What's wrong here?
-
@test-test2 Does it work
-
@test-test2 you invoke on instance and you have to put all args into an java array
the easiest way would be to use Core's Reflector
RGui = new Reflector(Gui) onrender: RGui.drawGradientRect(10, 10, 10 + 50, 10 + 50, Color.RED.getRGB(), Color.BLUE.getRGB())
also what about looking into logs or https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Method.html
-
onRender:
Result:
-
oh, how to include Core library?
-
render2d:
-
@test-test2 You might have to do some more open gl stuff which I have no idea about.
-
Solved, handwritten
-
-
A better way of not using reflection would be:
/** * @param color1 color in hex. * @param color2 color in hex. */ function drawSimpleVerticalGradientRect(x, y, x2, y2, color1, color2) { GL11.glBegin(GL11.GL_QUADS); glColor(color1); GL11.glVertex2d(x, y); GL11.glVertex2d(x, y2); glColor(color2); GL11.glVertex2d(x2, y2); GL11.glVertex2d(x2, y); GL11.glEnd(); } /** * @param color A color in hex. */ function glColor(color) { var a = (color >> 24) & 0xFF; var r = (color >> 16) & 0xFF; var g = (color >> 8) & 0xFF; var b = (color) & 0xFF; GL11.glColor4f(r / 255, g / 255, b / 255, a / 255); }
I would like to explain this, but i don't know if i could do it well
Example Usage:
GlStateManager.disableTexture2D(); GlStateManager.enableBlend(); GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); // Tells GL to transition between colors GlStateManager.shadeModel(GL11.GL_SMOOTH); drawSimpleVerticalGradientRect(10, 10, 390, 390, 0xffffffff, 0x00ffffff); // Tells GL to use the ONLY' last color GlStateManager.shadeModel(GL11.GL_FLAT); GlStateManager.disableBlend();