Jump to content

Including an image and drawing it


NomNuggetNom

Recommended Posts

I am trying to render an image on a HUD. My main problem is storing and referencing my image.

 

From what I've seen, I reference my image like this:

private static final ResourceLocation resource = new ResourceLocation("modid", "textures/image.png");

But where am I actually putting "image.png"? In "src/main/resources/textures/"?

 

Then to draw, I bind the texture and draw a rectangle. I think I can handle that part.

Link to comment
Share on other sites

What exactly do you mean? Are you talking about a texture, or an animated texture for a item/block to use?

Being a little less vague can help a lot. ;)

 

I just mean a 2D image. It's not really a texture, as in it won't be used for an block or item. Just imagine drawing a Google logo or something on the screen. No animation or anything, nothing on a block, etc.

Link to comment
Share on other sites

So a HUD item? look at this tutorial once it gets to the GUI:

 

http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/1571567-1-7-2-1-6-4-eventhandler-and

 

scroll to extended entity properties

I was trying not to use the word item. I don't want to add an item to the game, I just want to draw a simple image on the HUD. The tutorial requires creating an entity and such, I was hoping to do it without all that.

Link to comment
Share on other sites

You can use the RenderGameOverlayEvent, in which you can draw a ResourceLocation location to your image file.

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

You can use the RenderGameOverlayEvent, in which you can draw a ResourceLocation location to your image file.

Yes yes, but.. how?! Where do I put my image, how do I reference it, how do I draw it?

 

Fromw hat I've seen, I reference it like this:

private static final ResourceLocation resource = new ResourceLocation("modid", "textures/image.png");

But where am I actually putting "image.png"? In "src/main/resources/textures/"?

 

Then to draw, I bind the texture and draw a rectangle. I think I can handle that part.

 

Link to comment
Share on other sites

There are two terms you want to google for -- HUD (heads up display, meaning anything annotated on top of the game display) and GUI (something that comes up in the game that is graphical, like the crafting interface).  It sounds like you need more of a HUD.

 

In all these cases, graphics are "rendered".  In any video game there is some code running that does all the logic (figures out health and hitpoints and spawning, and then another bunch of code that keeps the display up to date rendering some number of "frames per second" (fps).

 

Most items, entities and blocks have a rendering method that gets called every render cycle, so for custom items, entities and blocks you simply overwrite or register your rendering stuff.

 

Alternatively, there are a bunch of events called when things are rendered. There is for example an event for rendering the player's hand that you see when in 1st person view, and so on.  For something like what you're doing, you probably want to use an event. If you're not familiar with event handling you can check out my tutorial, which also lists all the rendering related events: http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-event-handling.html

 

I don't do a lot of rendering mods myself, so others can help you better, but I think the RenderGameOverlayEvent (which has Pre and Post sub-events) is probably useful for this.

 

You may want to look at any open source minimap mod, which does similar thing.

 

Inside the rendering, you use OpenGL which is a graphics engine language.  You will see GL11 type commands that do things like create vertices, scale, blend, etc.  Look at some of the Renderer classes in Minecraft source.  You'll probably need to look up a seperate tutorial on this, but it is standard Java so there is plenty of info, especially for simply rendering a flat image.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

There are two terms you want to google for -- HUD (heads up display, meaning anything annotated on top of the game display) and GUI (something that comes up in the game that is graphical, like the crafting interface).  It sounds like you need more of a HUD.

 

In all these cases, graphics are "rendered".  In any video game there is some code running that does all the logic (figures out health and hitpoints and spawning, and then another bunch of code that keeps the display up to date rendering some number of "frames per second" (fps).

 

Most items, entities and blocks have a rendering method that gets called every render cycle, so for custom items, entities and blocks you simply overwrite or register your rendering stuff.

 

Alternatively, there are a bunch of events called when things are rendered. There is for example an event for rendering the player's hand that you see when in 1st person view, and so on.  For something like what you're doing, you probably want to use an event. If you're not familiar with event handling you can check out my tutorial, which also lists all the rendering related events: http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-event-handling.html

 

I don't do a lot of rendering mods myself, so others can help you better, but I think the RenderGameOverlayEvent (which has Pre and Post sub-events) is probably useful for this.

 

You may want to look at any open source minimap mod, which does similar thing.

 

Inside the rendering, you use OpenGL which is a graphics engine language.  You will see GL11 type commands that do things like create vertices, scale, blend, etc.  Look at some of the Renderer classes in Minecraft source.  You'll probably need to look up a seperate tutorial on this, but it is standard Java so there is plenty of info, especially for simply rendering a flat image.

 

Thank you for your post. Yes, I am trying to render an image on a HUD (I already have lots of text and other info displaying, mind you). My main problem is storing and referencing my image.

 

From what I've seen, I reference my image like this:

private static final ResourceLocation resource = new ResourceLocation("modid", "textures/image.png");

But where am I actually putting "image.png"? In "src/main/resources/textures/"?

 

Then to draw, I bind the texture and draw a rectangle. I think I can handle that part.

 

Link to comment
Share on other sites

First parameter to the resource location is the "resource domain". This is usually your ModID. The 2nd part is the actual file path.

The resolved path is:

assets/*domain*/*path*

 

In the dev env the root folder is src/main/resources, in the normal minecraft it is the root of your mod jar.

 

So, in Eclipse, the resulting path would be "src/main/resources/assets/modid/image.png", and the resulting code would be:

 

new ResourceLocation("modid", "image.png")

 

Correct?

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.