Jump to content

Draw an Icon in gui.


shucke

Recommended Posts

Im trying to draw an icon in a custom gui.

but it doesnt work properly.

instead of drawing the icon it draws a part of the gui.

this is the code that im using.

FontRenderer fontrenderer = par1Minecraft.fontRenderer;
            par1Minecraft.renderEngine.bindTexture("/mods/legendz/textures/gui/npcdialog.png");
            boolean var1 = par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height;
            this.drawTexturedModalRect(xPosition, yPosition, 144, 0, width, height);
            Icon var2 = reward.getIconIndex();
            System.out.println(var2.getIconName());
            GL11.glPushMatrix();
            this.drawTexturedModelRectFromIcon(0, 0, var2, 16, 16);
            GL11.glPopMatrix();

i cant figure out what is wrong with it.

some help would be greatly apreciated;

Link to comment
Share on other sites

Im trying to draw an icon in a custom gui.

but it doesnt work properly.

instead of drawing the icon it draws a part of the gui.

this is the code that im using.

FontRenderer fontrenderer = par1Minecraft.fontRenderer;
            par1Minecraft.renderEngine.bindTexture("/mods/legendz/textures/gui/npcdialog.png");
            boolean var1 = par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height;
            this.drawTexturedModalRect(xPosition, yPosition, 144, 0, width, height);
            Icon var2 = reward.getIconIndex();
            System.out.println(var2.getIconName());
            GL11.glPushMatrix();
            this.drawTexturedModelRectFromIcon(0, 0, var2, 16, 16);
            GL11.glPopMatrix();

i cant figure out what is wrong with it.

some help would be greatly apreciated;

Link to comment
Share on other sites

Any time I need to draw an icon, or anything really, I just draw it off of a sprite sheet. I bind the texture like you do and use drawTexturedModalRect(). You just specify where to draw it, and where on the sprite sheet the part you want to draw is and how big it is. Make sure the file is 256x256 or a multiple of that (E.g. 512x512.) The position and size is also assuming that your sheet is 256x256, so position (128, 0) is always the top middle.

 

If you don't want to do it that way (I'd recommend you do because you don't have to put your icons in the mods folder and you can put everything in one file.), you are probably just not getting the path right. I haven't done icons the way you tried, as I said, but I don't think you're supposed to put icon files in your mods folder. I'd recommend you make a gui folder right next to your code and reference it in there. A path like "/legendz/gui/npcdialog.png" should work fine.

width=336 height=83http://img836.imageshack.us/img836/1237/cooltext624963071.png[/img]

I make games, minecraft mods/plugins, and some graphic art.

 

Current Project: LoECraft - An industrial minecraft server with its own modpack and custom launcher.

Link to comment
Share on other sites

Any time I need to draw an icon, or anything really, I just draw it off of a sprite sheet. I bind the texture like you do and use drawTexturedModalRect(). You just specify where to draw it, and where on the sprite sheet the part you want to draw is and how big it is. Make sure the file is 256x256 or a multiple of that (E.g. 512x512.) The position and size is also assuming that your sheet is 256x256, so position (128, 0) is always the top middle.

 

If you don't want to do it that way (I'd recommend you do because you don't have to put your icons in the mods folder and you can put everything in one file.), you are probably just not getting the path right. I haven't done icons the way you tried, as I said, but I don't think you're supposed to put icon files in your mods folder. I'd recommend you make a gui folder right next to your code and reference it in there. A path like "/legendz/gui/npcdialog.png" should work fine.

width=336 height=83http://img836.imageshack.us/img836/1237/cooltext624963071.png[/img]

I make games, minecraft mods/plugins, and some graphic art.

 

Current Project: LoECraft - An industrial minecraft server with its own modpack and custom launcher.

Link to comment
Share on other sites

The way i handle my icons works fine for me.

and i want to draw a 18*18 image from the npcdialog.png and that works fine to.

The only problem i have is that the icon wont draw.

and since i want to draw the icon that is used by the ItemStack called reward on the screen i cant use a 256 by 256 texture.

that would be way to much work to do and unnessecary since there is a better way.

now the problem im experiencing is that something is drawn but not from the Icon given by the reward field.

i printed the icon name and it does give me the corresponding names for the icons.

my only guess is that it draws it from the texture binded by the minecraft render engine.

and i dont know how to bind the Icon to the render engine and if that is rigth a good solution to this problem.

Link to comment
Share on other sites

The way i handle my icons works fine for me.

and i want to draw a 18*18 image from the npcdialog.png and that works fine to.

The only problem i have is that the icon wont draw.

and since i want to draw the icon that is used by the ItemStack called reward on the screen i cant use a 256 by 256 texture.

that would be way to much work to do and unnessecary since there is a better way.

now the problem im experiencing is that something is drawn but not from the Icon given by the reward field.

i printed the icon name and it does give me the corresponding names for the icons.

my only guess is that it draws it from the texture binded by the minecraft render engine.

and i dont know how to bind the Icon to the render engine and if that is rigth a good solution to this problem.

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.