Jump to content

[SOLVED] Getting correct RGB values


Jedispencer21

Recommended Posts

Right now what I am trying to do is in my mod I have an element that gets rendered into the world and onto a Gui, instead of specifying the color of it, I would like to color it based on rgb values entered with a slider. right now I have the sliders working but it doesn't give the correct color.

 

This is the code:

 

 

public int red;

public int green;

public int blue;

 

public Point(int red, int green, int blue)

{

this.red = red;

this.green = green;

this.blue = blue;

}

 

// Renders the element into the world

public void drawIconInWorld(WorldRenderer worldrenderer, Tessellator tessellator)

{

int i = this.red >> 16 & 255;

int i1 = this.green >> 8 & 255;

int i2 = this.blue & 255;

 

GlStateManager.disableTexture2D();

worldrenderer.startDrawingQuads();

worldrenderer.setColorRGBA(i, i1, i2, 120);

worldrenderer.addVertex(-5.0D, -9.0D, 0.0D);

worldrenderer.addVertex(-5.0D, 0.0D, 0.0D);

worldrenderer.addVertex(4.0D, 0.0D, 0.0D);

worldrenderer.addVertex(4.0D, -9.0D, 0.0D);

tessellator.draw();

GlStateManager.enableTexture2D();

}

 

// Renders the element onto the GUI

public void drawIconOnGui(int drawX, int drawY)

{

int rectX2 = drawX + 9;

int rectY2 = drawY + 9;

Gui.drawRect(drawX, drawY, rectX2, rectY2, this.red >> 16 & 255 | this.green >> 8 & 255 | this.blue & 255);

}

 

 

Link to comment
Share on other sites

Or more accurately, because of math, it's 0 (you start with 0 and start adding things together, and none of the values added end up in the set of bits used by alpha, so its 0).

 

Also, drop the & 255 bit.  That's setting all of your color values to 0.

 

red = 128; //red is 128
red = red << 16; //red is 8388608
red = red & 255; //red is 0
/*
  100000000000000000000000
&                 11111111
==========================
  000000000000000000000000
*/

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Complete the next item in the series:  0, 8, 16...

 

 

24.

 

this.alpha << 24

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Then the color might be oriented in RGBA instead of ARGB

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

tried

int color = (this.red << 16 | this.green << 8 | this.blue);

Gui.drawRect(drawX, drawY, rectX2, rectY2, color << 24 | color);

and

int color = (this.red << 16 | this.green << 8 | this.blue);

Gui.drawRect(drawX, drawY, rectX2, rectY2, color | color << 24);

but it made no difference.

Holy smokes dude!

 

If the bit shifting is causing you that much grief, perhaps try this class instead-

Java.awt.Color

 

Color myColour = new Color(red, green, blue);

Gui.drawRect(drawX, drawY, rectX2, rectY2, myColour.getRGB());

 

-TGG

 

 

 

Link to comment
Share on other sites

*facepalm*

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I'm not exactly great with the colors, how would I add the alpha value to the: this.red << 16 | this.green << 8 | this.blue

You do the same as with red, green and blue, with an alpha value of 255, and bitshifted 24 to the left.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.