Jump to content

Recommended Posts

Posted (edited)

I want to render image from server so I'm going to use glTexImage2D for render the image.

This is my code for GUI screen in 1.16.5

int texture = -1;

    void initializeGl() {
        texture = glGenTextures();
        glBindTexture(GL_TEXTURE_2D, texture);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, myImagePixelArray);

        glBindTexture(GL_TEXTURE_2D, 0);

    }

    @override 
      void render(MatrixStack mat, int mouseX, int mouseY, float partialTicks) {
        if(texture == -1)
            initializeGl();

        glBindTexture(GL_TEXTURE_2D, texture);
        RenderUtil.renderRect(0, 0, 10, 10);
        glBindTexture(GL_TEXTURE_2D, 0);
        super.render(matrixStack, mouseX, mouseY, partialTicks);
    }

Sometimes It works what I excepted but randomly it shows black texture or render only helf. What's wrong with my code?

I cached array so myImagePixelArray always has same data.

Edited by Dayo

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.