简体   繁体   中英

How do I make scaled images look better in Java/OpenGL?

Here are two pictures of the same image:

this is what it looks like when viewed in preview...

and this is how it looks in my game...

在此输入图像描述

Obviously the character is scaled down in my game, however, when I scale down the sprite in preview or pixelmator, it is still smooth. Even when the image is at a 1:1 scale it still has the jagged edges.

This is my render method

public void render(Camera camera, List<Entity> entities) {
    shader.loadViewMatrix(Main.createViewMatrix(camera));

    //per textured model
    GL30.glBindVertexArray(((RenderComponent) entities.get(0).getComponent(EntityComponentType.RENDER)).texturedModel.getRawModel().getVaoID());
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);

    for(Entity e : entities) {
        RenderComponent render = (RenderComponent) e.getComponent(EntityComponentType.RENDER);

        //load transformation matrix per entity
        shader.loadTransformationMatrix(Main.createTransformationMatrix(render.position, render.rx, render.ry, render.getScaleX(), render.getScaleY()));
        shader.loadSprite((AnimationComponentContainer) e.getComponent(EntityComponentType.ANIMATION));

        //activate texture for each entity
        GL13.glActiveTexture(GL13.GL_TEXTURE0);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, render.getTexturedModel().getTexture().getTextureID());

        //render entity
        GL11.glDrawElements(GL11.GL_TRIANGLES, render.getTexturedModel().getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
    }

    //per textured model
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL30.glBindVertexArray(0);
}

And in my fragment shader I sample the image

vec4 color = texture(sampler, pass_TextureCoords);

and remove transparency

if(color.a < 0.5) discard;
out_Color = vec4(totalDiffuse, 1) * color;

My question is, how do I prevent the jagged edges from occurring (they are most prominent around his pants)? Or how do I smooth them out? The image itself if 512x1024

确保游戏的内部渲染分辨率对于完整图像来说足够大,并确保游戏没有将任何光线投射到精灵本身上,因为它看起来像角色正在与那里的那个绿灯相互作用而且它是在裤子上造成一些渐变问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM