简体   繁体   English

如何在Java / OpenGL中使缩放图像看起来更好?

[英]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. 即使图像比例为1:1,它仍然具有锯齿状边缘。

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 图像本身,如果512x1024

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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