Jump to content

How to create a simple single texture gui


Slit_bodmod

Recommended Posts

Hi, I was looking for a solution for this seemingly straightforward task but it requires a lot of bits of knowledge in parts of the game I'm not super familiar with.

I have an algorithm for generating a 128 * 128 grid of float values from an algorithm of mine.

I would like a simple GUI that will simply plonk this (as a texture) on to the screen, and also ideally display the players position in the corner.

How this gui is opened and closed is not important to me, a command, or a keystroke, whichever would be simplest.

Ideally for performance I imagine the texture should only be generated once and then saved but I could be wrong.

How might I go about doing this, both in terms of creating and placing the texture on to a gui and to somehow get the gui appearing in game.

Link to comment
Share on other sites

Have a look at DynamicTexture/NativeImage for creating dynamic textures.

You can see how to register the result (give it a ResourceLocation) with the TextureManager in for example PackSelectionScreen.loadPackIcon()

Once that is done, you can blit() it onto the screen like any other texture.

Look at for example BookViewScreen.render() for the some blit() code, which also renders some text - font.draw().

 

From your description, it sounds like the code for minecraft Map items would be more relevant, e.g. MapRenderer?

But that is more complex since it handles rendering the map in the player's hand.

 

How to show screens is a question that has been asked a million times in these forums. So you can use search for all the alternatives.

But it is basically Minecraft.getInstance().setScreen() from your chosen interaction method.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Ok thankyou very much, a few questions.

From a brief look around I assume that NativeImage is essentially a representation of raw pixel data and DynamicTexture is essentially a class that wraps this into a minecraft usable texture.

Would my process then to when my GUI is rendered for the first time, create a new DynamicTexture from a new NativeImage of the width and height I want, fill it in and then store the result it to my gui's class? kinda like this?

(how do you make it be code again)

public class SpecialRendererGui extends Screen {

DynamicTexture TEXTURE = new DynamicTexture( new NativeImage( 128,128, true ));

protected SpecialRendererGui(ITextComponent text) {

super(text); //what is this text component for

//for x,y in range 128... bla bla bla

}

public void render(PoseStack render_buffer) {

//I'm struggling to figure out what to do here?

} }

I am having difficulty deciphering the blit function and how it's exactly getting ahold of the necessary data?

Also do you know what the boolean in the NativeImage constructor does, it doesn't have a parameter name and seems to be used to differentiate a Malloc or Calloc which I didn't know java had? Is that about whether I want to set my data to black by default?

Also from personal experience what do you think will be the simplest and easiest way to implement the screen popping up? through a command? a key? an item?

Also pure curiosity questions, in digging through the client code I came across a package insider of client.renderer.debug, do you know what they are they look interesting and maybe kinda useful.

Link to comment
Share on other sites

You need to do more research by looking at how vanilla does things. And as I said before, you will find many answers to some of your questions already in these forums.A

Also BookViewScreen is just one example of a vanilla screen you can look at. Pick one that most closely resembles what you are trying to do.

I am not going to spoon feed the code to you. It is your responsibility to write your mod.

 

I will tell you (since it is probably not obvious if you haven't seen it before) that blit() like other render methods gets some of its "parameters" from the static RenderSystem calls that change the opengl rendering state. e.g. RenderSystem.setShaderTexture() specifies which texture to use in later calls.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

whoa dude, not asking you to spoon feed code to me. Asking some about some specific functionality of some classes because you seem more experienced and knowledgeable. Mostly pure curiosity questions cos I wanna learn more about how the system works.

The exact functionality of blit is a little mysterious as like you said, information was being passed from other places and I can't seem to find other classes that use it along with DynamicTextures much (I was thinking maybe the debug screen but I've been looking for that for a while and can't find it anywhere). I tend to find all the render functions a bit abstract and I'm not that familiar with the set up of openGL nor Minecraft's abstractions of it so I was just trying to grasp what the underlying methodology was.

My questions about the texture allocation and the client.renderer.debug package were pure curiosity questions that were related but not directly relevant. In both cases I feel like there's not really enough in the minecraft source code alone for me to go off of so If you can shed any light that wld be amazing but if not that's cool, they're more curiosities.

As for my question about the simplest and easiest way to get this rendering in game. That was more of a request for a personal recomendation of which would be easiest. I could implement all 3 by digging through the source code, and I will if I have to, but I don't want all 3, am just curious which would be easiest in your opinion.

I realise that my request to open a gui in the simplest way possible is a little weird but cos it's for a debugging tool, again it's not the means that's important to me but the simplicity and tho I don't know the minecraft code that well I know it can sometimes be very difficult to do straightforward things so thought you might be able to give your opinion.

 

 

Link to comment
Share on other sites

For future people curious about this.

The debug screen is called DebugScreenOverlay and is not itself a screen rather than a GuiComponent (I'm still figuring out the functional difference). 

The system I managed to use I think worked like this:

RenderSystem.setShader(GameRenderer::getPositionTexShader);

this tells minecraft you want to use a shader that draws textures, idk what the difference between this and other methods in GameRenderer are but this works

RenderSystem.setShaderColor( _red, _green, _blue, _alpha);

I guess you can colour textures as you render them if you need?

RenderSystem.setShaderTexture(0, TEXTURE_LOCATION);

 

register the texture you want, idk what that 0 does. It doesn't seem to be the gl texture id so who knows.

this.blit(render_buffer, x, y, U, V, RESOLOUTION, RESOLOUTION);

draw the texture to the appropriate place.

I ended up going with a command which was super straightforward.

I'm yet to figure out what that debug package is about, it seems to mostly seems to be classes that are never used, I assume for the devs but I wonder if there's a cool way to get it working properly.

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.



×
×
  • Create New...

Important Information

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