Jump to content

[SOLVED][1.10.2]Direct use GL11.glRect in GUI not work.


bxzsj

Recommended Posts

Try to use GL11.glRect to draw rectangles.

But it don't work.

    @Override
    public void drawScreen(int mouseX, int mouseY, float partialTicks)
    {
        super.drawScreen(mouseX, mouseY, partialTicks);
        GlStateManager.disableTexture2D();
        GL11.glColor4f(1.0f,0,0,1.0f);
        GL11.glRecti(10,10,50,50);
        GL11.glPushMatrix();
        GL11.glLoadIdentity();
        GL11.glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
        GL11.glPopMatrix();
        GlStateManager.enableTexture2D();
        GL11.glRecti(10,10,50,50);
        GL11.glPushMatrix();
        GL11.glLoadIdentity();
        GL11.glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
        GL11.glPopMatrix();
    }

image.png.04273efb62cb47f834ebee7502ef8322.png

But if I try this:

        glBegin(GL_POLYGON);
        glVertex2i(10,10);
        glVertex2i(10,50);
        glVertex2i(50,50);
        glVertex2i(50,10);
        glEnd();

It works.

I find that the difference between GL11.glRect and the above code  is

glRect(x1, y1, x2, y2) equal

glBegin(GL_POLYGON);
glVertex2(x1, y1);
glVertex2(x2, y1);
glVertex2(x2, y2);
glVertex2(x1, y2);
glEnd( );

but the work one is:

glBegin(GL_POLYGON);
glVertex2(x1, y1);
glVertex2(x1, y2);
glVertex2(x2, y2);
glVertex2(x2, y1);
glEnd( );


The difference between them is that the order of the vertices is different.

I don't understand why this is happening. I hope someone can answer. Thank you!

Edited by bxzsj
solved
Link to comment
Share on other sites

Well, first of all Don't use GL directly. Whatever you are doing can be achieved by different means. In this case a BufferBuilder will do the trick just fine. In other cases use GlStateManager.

Secondly, MC expects vertices to be specified CCW, but glRect specifies them CW. You can most likely disable culling(or change the cull method) and see everything working just fine regardless of the order.

Also 1.10.x is outdated and you should update to the latest version(1.12.2).

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.