Jump to content

[solved] GUI rendering issue


Yagoki

Recommended Posts

OK guys, once more I need help..

 

Been working on this for a couple of days and I'm a bit stuck with a couple of bugs that I cant tell the source of.

When rendering the GUI for my alter structure There are two major bugs which I've come across.

 

1) There is always one element which does not render properly, from testing this normally seems to be the one which is first in the list. If this element is then moved off the screen the closest visible element to that side of the screen then renders in the same way, and so on:

 

quSZfKGl.png

then it is moved off the edge

WmguTu0l.png

 

 

2)If there are no elements being rendered on the GUI the whole GUI renders white

 

UvhjX3ml.png

 

 

The code for the GUI is here, it's mostly a ripoff of the achievements GUI, as I didn't want to go through the hassle of rewriting it for the same effect, so copied it, analysed it and played with it till I got to this point. Left my comments in, just to say what each part does, but if I got anything wrong please correct me, I'm still not very comfortable around lwjgl.

Link to comment
Share on other sites

//1 without looking at the code I'm guessing its binding the texture after each block is drawn, causing the first block to be rendered abnormally

edit: no it seems fine the bindtexture happens once before every time you render an background

 

just for a test you change

	//element render properties
if (dest.isPrivate())
drawTexturedModalRect(i5 - 2, l4 - 2, 26, 202, 26, 26);
else
drawTexturedModalRect(i5 - 2, l4 - 2, 0, 202, 26, 26);

to this

//element render properties
if (dest.isPrivate())
drawTexturedModalRect(i5 - 2, l4 - 2, 0, 202, 26, 26);//note that its now 0 at both place. this is jsut for testing purpose
else
drawTexturedModalRect(i5 - 2, l4 - 2, 0, 202, 26, 26);

 

 

2 im guessing notch code has a bug where if there is no achievement it will not even bother rendering. Which isn't technically a bug because obviously there's always achievement, but might be a problem in your code.

 

honestly it is a pain but if you want to add stuff to make it visually impressive (animation etc) you'll have to eventually change redo some part or the other

 

btw i can see where this is going ... and I to admit that I'm jealous of this ;)

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Thanks for the swift reply,

I tested this against the achievements GUI and you can reach a point where there are no achievements shown, it was one of my thoughts before I posted here.

 

4aTqkSXl.png

 

 

as for the change form 0 to 26, the 26 us just the horizontal UV coordinate of the texture which is the texture corresponding to the "pointy" achievement icon:

 

0ezMFndl.png

 

 

Tested it like that anyway, to see if there was any java oddness going on, but no fix.

 

Any other ideas before i spend the next week trying to find a different way to make the code?

Link to comment
Share on other sites

as the change for 0 to 26, my fear was that it was actually in that space on the texture where theres nothing, turn out its not.

 

I'm sorry i dont have any other idea other then hardcore debugging, but i would very much like to hear about the progress of this. Whats the name of the mod you're making and when do you think you'll be done ?

 

the last thing you could try is straight up duplicate EVERYTHING the achievement thigny use and change things ONE BY ONE, slowly but surely

 

-hydroflame, author FRev-

 

 

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

the last thing you could try is straight up duplicate EVERYTHING the achievement thigny use and change things ONE BY ONE, slowly but surely

 

hehe, that's mostly what I did when I made it, just not overly slowly (It was fairly obvious what wasn't needed in the code)

 

I think the problem is most likely to be with binding texture for the frame, given that it overlays the whole gui goes white, bar the button which is drawn just after this:

	GL11.glDisable(GL11.GL_DEPTH_TEST);
	GL11.glEnable(GL11.GL_BLEND);
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	mc.renderEngine.bindTexture("/achievement/bg.png");//gets the texture
	drawTexturedModalRect(i1, j1, 0, 0, guiPaneWidth, guiPaneHeight);//draws the relevant parts
	GL11.glPopMatrix();
	zLevel = 0.0F;
	GL11.glDepthFunc(GL11.GL_LEQUAL);
	GL11.glDisable(GL11.GL_DEPTH_TEST);
	GL11.glEnable(GL11.GL_TEXTURE_2D);

so the big problem is probably something in that lump of GL11, or something which should get called from the loop rendering the parts, but doesn't because there are no parts to be rendered.

Link to comment
Share on other sites

heu ..... i just noticed something

 

 

you said its always the first one to be renderer that fails to have a texture

1 in the case of having "destinations" (or wtv you called your achievement-like-element) the first one to get drawn doesnt have a texture

2 in the case of no "destination" the overlay is white.

 

is it possible that the first thing to get drawn will always be white....

 

 

if thats the case ... cant you just render anything in the background, somethign that will get drawn over by the gui ... this way youll pass over the "first thing drawn is white"

 

-hydroflame-

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Hi again, i found a way to bypass the bug. heuuuuu don't ask why, just know that the texture will render correctly after you draw at least 1 item with renderItem

 

this is a code i was playing around, it seems to render fine even with 0 item to render

 

package com.hydroflame.gui;

 

import java.io.ByteArrayOutputStream;

import java.io.DataOutputStream;

import java.io.IOException;

import java.util.LinkedList;

import java.util.Random;

 

 

import net.minecraft.block.Block;

import net.minecraft.client.gui.GuiButton;

import net.minecraft.client.gui.GuiScreen;

import net.minecraft.client.gui.GuiSmallButton;

import net.minecraft.client.renderer.RenderHelper;

import net.minecraft.client.renderer.Tessellator;

import net.minecraft.client.renderer.entity.RenderItem;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemStack;

import net.minecraft.network.packet.Packet250CustomPayload;

import net.minecraft.util.Icon;

import net.minecraft.util.MathHelper;

import net.minecraft.util.StatCollector;

 

import org.lwjgl.input.Mouse;

import org.lwjgl.opengl.GL11;

import org.lwjgl.opengl.GL12;

 

import cpw.mods.fml.common.network.PacketDispatcher;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public class tempGui extends GuiScreen {

public static final int GUI_ID = 6666115;

 

/** The top x coordinate of the achievement map */

private int guiMapTop = 0 - 112;

 

/** The left y coordinate of the achievement map */

private int guiMapLeft = 0 - 112;

 

/** The bottom x coordinate of the achievement map */

private int guiMapBottom = 100 - 77;

 

/** The right y coordinate of the achievement map */

private static int guiMapRight = 100 - 77;

private int guiPaneWidth = 256;

private int guiPaneHeight = 202;

 

/** The current mouse x coordinate */

private int mouseX = 0;

 

/** The current mouse y coordinate */

protected int mouseY = 0;

protected double field_74117_m;

protected double field_74115_n;

 

/** The x position of the achievement map */

protected double guiMapX;

 

/** The y position of the achievement map */

protected double guiMapY;

protected double field_74124_q;

protected double field_74123_r;

 

/** Whether the Mouse Button is down or not */

private int isMouseButtonDown = 0;

 

 

private final EntityPlayer player;

 

public tempGui(EntityPlayer player) {

short short1 = 141;

short short2 = 141;

field_74117_m = guiMapX = field_74124_q = 0 - short1 / 2 - 12;

field_74115_n = guiMapY = field_74123_r = 0 - short2 / 2;

 

this.player = player;

 

// Adds the achievements to its list

 

 

guiMapTop = 0 - 112;

guiMapLeft = 0 - 112;

guiMapBottom = 100 - 77;

guiMapRight = 100 - 77;

}

 

/**

* Adds the buttons (and other controls) to the screen in question.

*/

@Override

public void initGui() {

buttonList.clear();

// adds the exit button to the Gui

buttonList.add(new GuiSmallButton(1, width / 2 + 24, height / 2 + 74,

80, 20, StatCollector.translateToLocal("gui.done")));

}

 

/**

* Fired when a control is clicked. This is the equivalent of

* ActionListener.actionPerformed(ActionEvent e).

*/

@Override

protected void actionPerformed(GuiButton par1GuiButton) {

// has the exit button been pressed

if (par1GuiButton.id == 1) {

mc.displayGuiScreen((GuiScreen) null);

mc.setIngameFocus();

}

 

super.actionPerformed(par1GuiButton);

}

 

/**

* Fired when a key is typed. This is the equivalent of

* KeyListener.keyTyped(KeyEvent e).

*/

@Override

protected void keyTyped(char par1, int par2) {

// has E been pressed

if (par2 == mc.gameSettings.keyBindInventory.keyCode) {

mc.displayGuiScreen((GuiScreen) null);

mc.setIngameFocus();

} else

super.keyTyped(par1, par2);

}

 

/**

* Draws the screen and all the components in it.

*/

@Override

public void drawScreen(int par1, int par2, float par3) {

// is LMB down

if (Mouse.isButtonDown(0)) {

int k = (width - guiPaneWidth) / 2;

int l = (height - guiPaneHeight) / 2;

int i1 = k + 8;

int j1 = l + 17;

 

// Is the mouse within the Gui

if ((isMouseButtonDown == 0 || isMouseButtonDown == 1)

&& par1 >= i1 && par1 < i1 + 224 && par2 >= j1

&& par2 < j1 + 155) {

// was the mouse down last tick?

if (isMouseButtonDown == 0)

// sets the mouse variable to be read next tick

isMouseButtonDown = 1;

else {

// moves screen by the same as mouse

guiMapX -= par1 - mouseX;

guiMapY -= par2 - mouseY;

// these fields are all the same, I think render/screen

// bounds/position?

field_74124_q = field_74117_m = guiMapX;

field_74123_r = field_74115_n = guiMapY;

}

// sets the previous mouse positions

mouseX = par1;

mouseY = par2;

}

// Limits screen movement

if (field_74124_q < guiMapTop)

field_74124_q = guiMapTop;

 

if (field_74123_r < guiMapLeft)

field_74123_r = guiMapLeft;

 

if (field_74124_q >= guiMapBottom)

field_74124_q = guiMapBottom - 1;

 

if (field_74123_r >= guiMapRight)

field_74123_r = guiMapRight - 1;

} else

// if mouse is released then this is 0, Used to detect drag vs click

isMouseButtonDown = 0;

 

// Draws the screen background

drawDefaultBackground();

// draws the achievement page background (terrain type thing)

genAchievementBackground(par1, par2, par3);

// GL lighting stuff scares me :(

GL11.glDisable(GL11.GL_LIGHTING);

GL11.glDisable(GL11.GL_DEPTH_TEST);

// draws the title

drawTitle();

GL11.glEnable(GL11.GL_LIGHTING);

GL11.glEnable(GL11.GL_DEPTH_TEST);

}

 

/**

* Called from the main game loop to update the screen.

*/

@Override

public void updateScreen() {

// saves the current screen position

field_74117_m = guiMapX;

field_74115_n = guiMapY;

// the movement of the screen

double d0 = field_74124_q - guiMapX;

double d1 = field_74123_r - guiMapY;

 

// moved less than 2?

if (d0 * d0 + d1 * d1 < 4.0D) {

// x = field_74124_q

guiMapX += d0;

 

// y = field_74123_r

guiMapY += d1;

}

// if more than 2 move less

else {

guiMapX += d0 * 0.85D;

guiMapY += d1 * 0.85D;

}

}

 

/**

* Draws the "Achievements" title at the top of the GUI.

*/

protected void drawTitle() {

int i = (width - guiPaneWidth) / 2;

int j = (height - guiPaneHeight) / 2;

fontRenderer.drawString("Alters", i + 15, j + 5, 4210752);

}

 

protected void genAchievementBackground(int par1, int par2, float par3) {

// does something

int k = MathHelper.floor_double(field_74117_m

+ (guiMapX - field_74117_m) * par3);

int l = MathHelper.floor_double(field_74115_n

+ (guiMapY - field_74115_n) * par3);

 

// limits l and k to the screen boundary

if (k < guiMapTop)

k = guiMapTop;

 

if (l < guiMapLeft)

l = guiMapLeft;

 

if (k >= guiMapBottom)

k = guiMapBottom - 1;

 

if (l >= guiMapRight)

l = guiMapRight - 1;

 

// top and left bounds for the screen

int i1 = (width - guiPaneWidth) / 2;

int j1 = (height - guiPaneHeight) / 2;

// ummm... possibly bounds for achievement window

int k1 = i1 + 16;

int l1 = j1 + 17;

zLevel = 0.0F;

GL11.glDepthFunc(GL11.GL_GEQUAL);

GL11.glPushMatrix();

GL11.glTranslatef(0.0F, 0.0F, -200.0F);

GL11.glEnable(GL11.GL_TEXTURE_2D);

GL11.glDisable(GL11.GL_LIGHTING);

GL11.glEnable(GL12.GL_RESCALE_NORMAL);

GL11.glEnable(GL11.GL_COLOR_MATERIAL);

mc.renderEngine.bindTexture("/terrain.png");

int i2 = k + 288 >> 4;

int j2 = l + 288 >> 4;

int k2 = (k + 288) % 16;

int l2 = (l + 288) % 16;

Random random = new Random();

int i3;

int j3;

int k3;

 

 

// nested loop with texture stuff

for (i3 = 0; i3 * 16 - l2 < 155; ++i3) {

float f1 = 0.6F - (j2 + i3) / 25.0F * 0.3F;

GL11.glColor4f(f1, f1, f1, 1.0F);

 

// Background texture randomiser

for (k3 = 0; k3 * 16 - k2 < 224; ++k3) {

random.setSeed(1234 + i2 + k3);

random.nextInt();

j3 = random.nextInt(1 + j2 + i3) + (j2 + i3) / 2;

Icon icon = Block.sand.getBlockTextureFromSide(0);

 

drawTexturedModelRectFromIcon(k1 + k3 * 16 - k2, l1 + i3 * 16

- l2, icon, 16, 16);

}

}

 

GL11.glEnable(GL11.GL_DEPTH_TEST);

GL11.glDepthFunc(GL11.GL_LEQUAL);

GL11.glDisable(GL11.GL_TEXTURE_2D);

int l3;

int j4;

 

int par4 = 0, par5 = 0, par6 = 0;

float f1 = 0, f = 0;

Tessellator tessellator = Tessellator.instance;

        tessellator.startDrawingQuads();

        tessellator.addVertexWithUV((double)(par1 + 0), (double)(par2 + par6), (double)this.zLevel, (double)((float)(par3 + 0) * f), (double)((float)(par4 + par6) * f1));

        tessellator.addVertexWithUV((double)(par1 + par5), (double)(par2 + par6), (double)this.zLevel, (double)((float)(par3 + par5) * f), (double)((float)(par4 + par6) * f1));

        tessellator.addVertexWithUV((double)(par1 + par5), (double)(par2 + 0), (double)this.zLevel, (double)((float)(par3 + par5) * f), (double)((float)(par4 + 0) * f1));

        tessellator.addVertexWithUV((double)(par1 + 0), (double)(par2 + 0), (double)this.zLevel, (double)((float)(par3 + 0) * f), (double)((float)(par4 + 0) * f1));

        tessellator.draw();

 

 

// Achievement saved to this if mouse over

RenderHelper.enableGUIStandardItemLighting();

GL11.glDisable(GL11.GL_LIGHTING);

GL11.glEnable(GL12.GL_RESCALE_NORMAL);

GL11.glEnable(GL11.GL_COLOR_MATERIAL);

int l4;

int i5;

//NOTE THIS  \/

//renders somethign somewhere invisible, seems to fix the problem

RenderItem renderitem = new RenderItem();

renderitem.renderItemAndEffectIntoGUI(mc.fontRenderer,mc.renderEngine, new ItemStack(Block.dirt), 0 + 3,0 + 3);

 

 

// iterates over achievements and renders them

for (k3 = 0; k3 < 4; ++k3) {

// achievement being rendered

// position of element relative to screen

j4 = k3*50 - k;

l3 = 0 - l;

// is on page/is visible?

if (j4 >= -24 && l3 >= -24 && j4 <= 224 && l3 <= 155) {

// properties of element colour/shade for rendering

float f2;

f2 = 1.0F;

GL11.glColor4f(f2, f2, f2, 1.0F);

i5 = k1 + j4;

l4 = l1 + l3;

mc.renderEngine.bindTexture("/achievement/bg.png");

// element position relative to view-port

// element render properties

drawTexturedModalRect(i5 - 2, l4 - 2, 0, 202, 26, 26);

// renders an item on the gui

 

GL11.glEnable(GL11.GL_LIGHTING);

GL11.glEnable(GL11.GL_CULL_FACE);

renderitem.renderItemAndEffectIntoGUI(mc.fontRenderer,mc.renderEngine, new ItemStack(Block.dirt), i5 + 3,l4 + 3);

GL11.glDisable(GL11.GL_LIGHTING);

 

GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

// is mouse over

}

}

 

 

 

 

 

GL11.glDisable(GL11.GL_DEPTH_TEST);

GL11.glEnable(GL11.GL_BLEND);

GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

mc.renderEngine.bindTexture("/achievement/bg.png");

drawTexturedModalRect(i1, j1, 0, 0, guiPaneWidth, guiPaneHeight);

GL11.glPopMatrix();

zLevel = 0.0F;

GL11.glDepthFunc(GL11.GL_LEQUAL);

GL11.glDisable(GL11.GL_DEPTH_TEST);

GL11.glEnable(GL11.GL_TEXTURE_2D);

super.drawScreen(par1, par2, par3);

// renders the info of the mouse over element

 

 

GL11.glEnable(GL11.GL_DEPTH_TEST);

GL11.glEnable(GL11.GL_LIGHTING);

RenderHelper.disableStandardItemLighting();

}

 

/**

* Returns true if this GUI should pause the game when it is displayed in

* single-player

*/

@Override

public boolean doesGuiPauseGame() {

return true;

}

 

@Override

protected void mouseClicked(int par1, int par2, int par3) {

 

super.mouseClicked(par1, par2, par3);

}

}

 

 

 

i had to remove all "altars" related because i didn't have them, but it shouldn't affect the rendering code

 

Cheer,

 

-hydroflame, author FRev-

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

I fixed it at about 00:30 (GMT), and didn't have any internet at that time. Managed to identify it as being badly written vanilla code (in my opinion). There was this line "GL11.glDisable(GL11.GL_TEXTURE_2D);" in the vanilla code which I had to remove. This is (as far as I can tell) has no use in the original code as it then gets re-enabled in a method directly, after which draws the lines between achievements. Just had to remove this line and it's all good. (alternatively I could have put GL11.glEnable(GL11.GL_TEXTURE_2D))

 

Thanks for the help anyway.

 

By the looks of it you took a similar method to fixing it as I did, The Item render thingi calls GL11.glEnable(GL11.GL_TEXTURE_2D), which is why it fixed it.

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.