OSDN Git Service

Adjust UVs for 1x1 texture regions.
authorNathanSweet <nathan.sweet@gmail.com>
Sun, 6 Oct 2013 19:07:25 +0000 (21:07 +0200)
committerNathanSweet <nathan.sweet@gmail.com>
Sun, 6 Oct 2013 19:07:25 +0000 (21:07 +0200)
closes #802

gdx/src/com/badlogic/gdx/graphics/g2d/TextureRegion.java
tests/gdx-tests-lwjgl/src/com/badlogic/gdx/tests/lwjgl/Test2.java [deleted file]

index 532a372..6777bd9 100644 (file)
@@ -87,12 +87,22 @@ public class TextureRegion {
        }\r
 \r
        public void setRegion (float u, float v, float u2, float v2) {\r
+               int texWidth = texture.getWidth(), texHeight = texture.getHeight();\r
+               regionWidth = Math.round(Math.abs(u2 - u) * texWidth);\r
+               regionHeight = Math.round(Math.abs(v2 - v) * texHeight);\r
+\r
+               // For a 1x1 region, adjust UVs to pixel center to avoid filtering artifacts on AMD GPUs when drawing stretched.\r
+               if (regionWidth == 1 && regionHeight == 1) {\r
+                       u += 0.5f / texWidth;\r
+                       u2 = u;\r
+                       v += 0.5f / texHeight;\r
+                       v2 = v;\r
+               }\r
+\r
                this.u = u;\r
                this.v = v;\r
                this.u2 = u2;\r
                this.v2 = v2;\r
-               regionWidth = Math.round(Math.abs(u2 - u) * texture.getWidth());\r
-               regionHeight = Math.round(Math.abs(v2 - v) * texture.getHeight());\r
        }\r
 \r
        /** Sets the texture and coordinates to the specified region. */\r
diff --git a/tests/gdx-tests-lwjgl/src/com/badlogic/gdx/tests/lwjgl/Test2.java b/tests/gdx-tests-lwjgl/src/com/badlogic/gdx/tests/lwjgl/Test2.java
deleted file mode 100644 (file)
index fb2ad13..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-
-package com.badlogic.gdx.tests.lwjgl;
-
-import com.badlogic.gdx.ApplicationAdapter;
-import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
-import com.badlogic.gdx.graphics.Color;
-import com.badlogic.gdx.graphics.GL10;
-import com.badlogic.gdx.graphics.Pixmap;
-import com.badlogic.gdx.graphics.Pixmap.Format;
-import com.badlogic.gdx.graphics.Texture;
-import com.badlogic.gdx.graphics.g2d.SpriteBatch;
-import com.badlogic.gdx.graphics.g2d.TextureRegion;
-import com.badlogic.gdx.utils.ScreenUtils;
-
-public class Test2 extends ApplicationAdapter {
-       SpriteBatch batch;
-       TextureRegion region;
-       Pixmap screenCap;
-       Texture screenCapTex;
-       private int size = 2;
-
-       public void create () {
-
-               batch = new SpriteBatch();
-               Pixmap p = new Pixmap(64, 64, Format.RGBA8888);
-               p.setColor(Color.RED);
-               p.fillRectangle(32, 32, size , size );
-               region = new TextureRegion(new Texture(p), 32, 32, 1 , 1);
-
-               Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
-               Gdx.gl.glClearColor(0, 0, 0, 1);
-               batch.begin();
-               batch.draw(region, 1, 1, 256, 256);
-               batch.end();
-               
-               screenCap = ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
-               screenCapTex = new Texture(screenCap);
-               System.out.println("size: " + size);
-               System.out.println(Integer.toHexString(screenCap.getPixel(0, 0)));
-               System.out.println(Integer.toHexString(screenCap.getPixel(1, 1)));
-               System.out.println(Integer.toHexString(screenCap.getPixel(256, 256)));
-               System.out.println(Integer.toHexString(screenCap.getPixel(257, 257)));
-       }
-
-       public void render () {
-               Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
-               Gdx.gl.glClearColor(0, 0, 0, 1);
-               batch.begin();
-               batch.draw(screenCapTex, 0, 0);
-               batch.end();
-       }
-
-       public static void main (String[] args) {
-               LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
-               config.useGL20 = true;
-               new LwjglApplication(new Test2(), config);
-       }
-}