How to draw a gradient rect
-
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?
-
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
-
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 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:


-




render2d:


@test-test2 You might have to do some more open gl stuff which I have no idea about.
-
Solved, handwritten
-
T test test2 has marked this topic as solved on
-
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();
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login