Jump to content

[1.7.10] Drawing Player in Front View on GUI


DemRat

Recommended Posts

Hello Forums,

 

As you already know if you read the title, I'm trying to draw the Player in a Front view onto a GUI.

I don't want/need it to be 3D and therefore dont really want to use the code from the Player Inventory.

 

Can anyone explain to me or post a link to a tutorial how i could do that?

Thanks in advance.

Link to comment
Share on other sites

Draw quads that form the players body (head, legs, arms) and then use the players skin to bind the texture.

First, thank you for that, you at least gave me a starting point to begin with.

But I'm still struggling with this.

 

This Code:

 

public CyberneticsMonitorGui(EntityPlayer player, World world, int x, int y, int z) {
	this.x = x;
	this.y = y;
	this.z = z;
	this.player = player;
	this.world = world;
	this.xSize = 176;
	this.ySize = 192;
}

@Override
public void drawScreen(int mouseX, int mouseY, float renderPartialTicks) {
	this.mc.getTextureManager().bindTexture(image);
	int x = (this.width - xSize) / 2;
	int y = (this.height - ySize) / 2;
	drawTexturedModalRect(x, y, 0, 0, xSize,  ySize);

	drawPlayer(x, y);
}

private void drawPlayer(int x, int y){
	this.mc.getTextureManager().bindTexture(AbstractClientPlayer.locationStevePng);
	int scale = 3;

	//The Coordinates of the panel to draw the player on on the gui
	int panelCornerX = 122;
	int panelCornerY = 11;

	//modify x and y to reduce lenght of drawing call
	x = x + panelCornerX;
	y = y + panelCornerY;

	//Define the sizes and places of the body parts.
	int Uhead = 8;
	int Vhead = 8;
	int Hhead = 8;
	int Whead = 8;
	int Xhead = 4;
	int Yhead = 0;

	int Utorso = 20;
	int Vtorso = 20;
	int Htorso = 12;
	int Wtorso = 4;
	int Xtorso = 4;
	int Ytorso = 8;

	int Uarm = 44;
	int Varm = 20;
	int Harm = 12;
	int Warm = 4;
	int Xarm1 = 0;
	int Yarm1 = 8;
	int Xarm2 = 12;
	int Yarm2 = 8;

	int Uleg = 4;
	int Vleg = 20;
	int Hleg = 12;
	int Wleg = 4;
	int Xleg1 = 4;
	int Yleg1 = 20;
	int Xleg2 = 8;
	int Yleg2 = 20;

	drawPixels(x + Xhead, y + Yhead, Uhead, Vhead, Whead, Hhead, scale);
	drawPixels(x + Xtorso, y + Ytorso, Utorso, Vtorso, Wtorso, Htorso, scale);
	drawPixels(x + Xarm1, y + Yarm1, Uarm, Varm, Warm, Harm, scale);
	drawPixels(x + Xarm2, y + Yarm2, Uarm, Varm, Warm, Harm, scale);
	drawPixels(x + Xleg1, y + Yleg1, Uleg, Vleg, Wleg, Hleg, scale);
	drawPixels(x + Xleg2, y + Yleg2, Uleg, Vleg, Wleg, Hleg, scale);
}

/**
 * Draws the Specified Rectangle on the last binded texture at thrice the size.
 * @param times The factor to scale with
 */
private void drawPixels(int x, int y, int u, int v, int width, int height, int times){
	for(int cu = u; cu < u + width; cu++){
		for(int cv = v; cv < v + height; cv++){
			for(int factor = 0; factor < times; factor++){
				drawTexturedModalRect(x + (cu*3) + factor, y + (cv*3) + factor, cu + u, cv + v, 1, 1);
			}
		}
	}
}

 

Results in:

 

a8a326e3e5.jpg

 

Link to comment
Share on other sites

Hello Forums,

 

As you already know if you read the title, I'm trying to draw the Player in a Front view onto a GUI.

I don't want/need it to be 3D and therefore dont really want to use the code from the Player Inventory.

 

Can anyone explain to me or post a link to a tutorial how i could do that?

Thanks in advance.

 

If you are actually drying the draw the player itself onto the screen then try this. This is some OLD code (1.5.2) so it very well may not work.

public static int rotate = 0;
public static void drawPlayerOnGui(Minecraft mc, int par1, int par2, int par3, float par4, float par5)
{
	rotate ++;
	if(rotate >= 360){
		rotate = 0;
	}
	GL11.glEnable(GL11.GL_COLOR_MATERIAL);
	GL11.glPushMatrix();
	GL11.glTranslatef((float)35, (float)120, 50.0F);
	GL11.glScalef((float)(-30), (float)30, (float)30);
	GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F);
	RenderHelper.enableStandardItemLighting();
	GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);
	GL11.glRotatef(-((float)Math.atan((double)(par5 / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F);

	GL11.glTranslatef(0.0F, mc.thePlayer.yOffset, 0.0F);
	RenderManager.instance.playerViewY = 180.0F;
	GL11.glPushMatrix();
	GL11.glRotatef(180, 0, 0, 1);
	GL11.glRotatef(rotate, 0, 1, 0);

	RenderManager.instance.renderEntityWithPosYaw(mc.thePlayer, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
	GL11.glPopMatrix();
	GL11.glPopMatrix();
	RenderHelper.disableStandardItemLighting();
	GL11.glDisable(GL12.GL_RESCALE_NORMAL);
	OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
	GL11.glDisable(GL11.GL_TEXTURE_2D);
	OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
}

Link to comment
Share on other sites

If you are actually drying the draw the player itself onto the screen then try this. This is some OLD code (1.5.2) so it very well may not work.

//Some Code
}

 

I tried to avoid that because I don't udnerstand what exactly is happening and therefore can only modify it with trial and error.

I'm now using the version of that code used in the inventory until something other comes up, but the arms move and the Item the Player is holding is drawn too.

Any Idea how I can prevent that?

Link to comment
Share on other sites

If you are actually drying the draw the player itself onto the screen then try this. This is some OLD code (1.5.2) so it very well may not work.

//Some Code
}

 

I tried to avoid that because I don't udnerstand what exactly is happening and therefore can only modify it with trial and error.

I'm now using the version of that code used in the inventory until something other comes up, but the arms move and the Item the Player is holding is drawn too.

Any Idea how I can prevent that?

That IS the code that was used in the inventory. And you can't make the arms not move because you are directly calling upon the player's render. In order for that to work the way you want, you would have to create a new model and not bind it to an entity in order for that to work.

Link to comment
Share on other sites

@deadrecon98

You have weird way of helping ppl. Not that I am condemning that you want to help, but if you don't know how to make something, please don't say "you can't" or "you must do it that way". Don't take it as offense please.

 

But now back to thread:

Drawin player is quite simple. As long as you have players skin loaded it's even simplier.

// Only for Client-side!!!
ResourceLocation skin = ((AbstractClientPlayer) player).getLocationSkin();

This will give you read-to-use resource, if reffered player has cached skin on your client.

 

Next you can do whetever the hell you want with it.

this.mc.getTextureManager().bindTexture(skin); //bind texture to renderer
this.drawTexturedModalRect(xPos, yPos, xOffset, yOffset, width, height);

 

Edit: Start with drawTexturedModalRect(0, 0, 0, 0, 256, 256); - it should give the idea of how to move texture around.

 

You can render parts of resource few times to archive full player front-texture.

 

Quite simple.

 

As to code provided by deadrecon98 - this is very outdated code. in 1.7.10 you can find new one for rendering player (probably in GuiInventory, i don't remember) and in 1.8 there is even renderer for EntityLivingBase.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

@deadrecon98

You have weird way of helping ppl. Not that I am condemning that you want to help, but if you don't know how to make something, please don't say "you can't" or "you must do it that way". Don't take it as offense please.

 

But now back to thread:

Drawin player is quite simple. As long as you have players skin loaded it's even simplier.

// Only for Client-side!!!
ResourceLocation skin = ((AbstractClientPlayer) player).getLocationSkin();

This will give you read-to-use resource, if reffered player has cached skin on your client.

 

Next you can do whetever the hell you want with it.

this.mc.getTextureManager().bindTexture(skin); //bind texture to renderer
this.drawTexturedModalRect(xPos, yPos, xOffset, yOffset, width, height);

 

Edit: Start with drawTexturedModalRect(0, 0, 0, 0, 256, 256); - it should give the idea of how to move texture around.

 

You can render parts of resource few times to archive full player front-texture.

 

Quite simple.

 

As to code provided by deadrecon98 - this is very outdated code. in 1.7.10 you can find new one for rendering player (probably in GuiInventory, i don't remember) and in 1.8 there is even renderer for EntityLivingBase.

 

It works now, thanks!

 

There was one problem with the texture being cropped, but with a little google-fu I was able to find a solution for that:

GL11.glScaled(scale, scale/2, scale);

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.