Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I'm using glScissor to render some things on a gui, but when I resize the window, it doesn't scale automatically.

 

How would I go about scaling the arguments inside of the glScissor method?

 

package flappyworld.gui;

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.init.Blocks;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;

import tlhpoeCore.ReferenceT;
import tlhpoeCore.TLHPoE;
import tlhpoeCore.UtilT;
import flappyworld.ReferenceFW;
import flappyworld.UtilFW;
import flappyworld.game.ClientGameSessionFW;
import flappyworld.game.PipeFW;
import flappyworld.game.SteveFW;
import flappyworld.network.PacketPlayerJumpFW;

public class GuiGameFW extends GuiScreen {
public static final ResourceLocation TEXTURES = new ResourceLocation(ReferenceFW.ID + ":textures/gui/textureSheet.png");
public static final ResourceLocation locationCreeperPng = new ResourceLocation("textures/entity/creeper/creeper.png");
public boolean canJump = true;

@Override
public void drawScreen(int par1, int par2, float par3) {
	this.drawDefaultBackground();
	super.drawScreen(par1, par2, par3);
	Minecraft mc = UtilT.getMC();

	GL11.glPushMatrix();
	GL11.glScissor(311, 74, 231, 1000); //SCISSOR
	GL11.glEnable(GL11.GL_SCISSOR_TEST); //ENABLE SCISSOR

	drawGround();

	ClientGameSessionFW clientSession;
	if(ReferenceFW.clientSession != null) {
		clientSession = ReferenceFW.clientSession;
	} else {
		return;
	}

	int x = (this.width / 2) - 58;
	int y = (int) ((this.height / 2) + 51);

	GL11.glPushMatrix();
	GL11.glTranslated(x, y, 0);

	drawPipes(clientSession);

	drawPlayer(clientSession);

	GL11.glPopMatrix();
	GL11.glDisable(GL11.GL_SCISSOR_TEST); //DISABLE SCISSOR
	GL11.glPopMatrix();

	drawPhone();

	String score = "" + clientSession.score;
	x = this.width / 2;
	y = this.height / 2;

	GL11.glPushMatrix();

	GL11.glScaled(2, 2, 1);
	UtilT.drawOutlinedString(score, (x / 2) - (mc.fontRenderer.getStringWidth(score) / 2), y - 94, 0xFFE600, 0);

	GL11.glPopMatrix();

	UtilT.drawOutlinedString("High Score: " + clientSession.highScore, 4, 4, 0xFFFFFF, 0);
}

public void drawGround() {
	int x = this.width / 2;
	int y = (this.height / 2) + 67;
	mc.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
	IIcon icon = Blocks.grass.getIcon(3, 0);
	for(int i = 0; i < 8; i++) {
		this.drawTexturedModelRectFromIcon((x - 64) + (16 * i), y, icon, 16, 16);
	}
}

public void drawPhone() {
	int width = 128;
	int height = 224;
	int x = (this.width - width) / 2;
	int y = (this.height - height) / 2;
	mc.renderEngine.bindTexture(TEXTURES);
	this.drawTexturedModalRect(x, y, 0, 0, width, height);
	width = height = 16;
}

public void drawPipes(ClientGameSessionFW clientSession) {
	if(clientSession.pipes != null) {
		for(int i = 0; i < clientSession.pipes.length; i++) {
			PipeFW pipe = clientSession.pipes[i];
			int pipeHeight = pipe.height;
			int pipeX = (int) pipe.posX;
			mc.renderEngine.bindTexture(locationCreeperPng);
			UtilFW.drawTexturedQuad(pipeX + 4, -pipeHeight, 16, 16, 16, 8, 8, 8, 64, 32, 0);
			UtilFW.drawTexturedQuad(pipeX + 8, (-pipeHeight + 16), 8, pipeHeight - 12, 28, 20, 4, 12, 64, 32, 0);
			UtilFW.drawTexturedQuad(pipeX + 16, 4, 8, 12, 8, 20, 4, 6, 64, 32, 0);
			UtilFW.drawTexturedQuad(pipeX, 4, 8, 12, 8, 20, 4, 6, 64, 32, 0);
		}
	}
}

public void drawPlayer(ClientGameSessionFW clientSession) {
	mc.renderEngine.bindTexture(AbstractClientPlayer.locationStevePng);
	GL11.glPushMatrix();
	GL11.glTranslated(20, (-clientSession.posY) + 8, 0);
	GL11.glRotatef((float) (SteveFW.getRotation(clientSession.motionY)) / -1F, 0.0F, 0.0F, 1.0F);
	UtilFW.drawTexturedQuad(-8, -8, 16, 16, 8, 8, 8, 8, 64, 32, 0);
	GL11.glPopMatrix();
}

@Override
public void handleKeyboardInput() {
	if(Keyboard.getEventKey() == Keyboard.KEY_SPACE) {
		if(Keyboard.getEventKeyState()) {
			if(canJump) {
				TLHPoE.packetHandler.sendToServer(new PacketPlayerJumpFW());
				canJump = false;
			}
		} else {
			canJump = true;
		}
	}
	super.handleKeyboardInput();
}

@Override
public boolean doesGuiPauseGame() {
	return false;
}
}

Kain

  • Author

I'm almost there I think. The region gets out of scale if sX and sY aren't equal though. :(

double sX = (double) mc.displayWidth / ReferenceT.DEFAULT_WIDTH;
double sY = (double) mc.displayHeight / ReferenceT.DEFAULT_HEIGHT;
System.err.println("SX:" + sX + "|SY:" + sY);
GL11.glScissor((int) (298 * sX), (int) (20 * sY), (int) (256 * sX), (int) (438 * sY));

Kain

  • Author

Ok, it's not working.

 

Expected Outcome:

Apovs7C.png

 

Outcome:

JlitBk6.png

 

Here's my code:

ScaledResolutionT sr = new ScaledResolutionT(mc.gameSettings, this.width, this.height);
GL11.glScissor((int) sr.getScaledX(298), (int) sr.getScaledY(20), (int) sr.getScaledX(256), (int) sr.getScaledY(438));

 

And here's the custom class I use:

package tlhpoeCore;

import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.settings.GameSettings;

public class ScaledResolutionT extends ScaledResolution {
public ScaledResolutionT(GameSettings gameSettings, int width, int height) {
	super(gameSettings, width, height);
}

public double getScaledX(double x) {
	return (x / ReferenceT.DEFAULT_WIDTH) * getScaledWidth_double();
}

public double getScaledY(double y) {
	return (y / ReferenceT.DEFAULT_HEIGHT) * getScaledHeight_double();
}
}

Kain

  • Author

Ok, how would I scale the x position though?

ScaledResolutionT sr = new ScaledResolutionT(mc.gameSettings, this.width, this.height);
int scale = sr.getScaleFactor(), scissorX = 298, scissorY = 20, scissorWidth = 256, scissorHeight = 438;
GL11.glScissor(0, mc.displayHeight - (scissorY + scissorHeight) * scale, (scissorWidth + scissorX) * scale, scissorHeight * scale);

Kain

  • Author

In your code, your beginning x position is 0, but mine starts at 298. How would I go about scaling 298?

Kain

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.