OSDN Git Service

pixmap screencap is now y-up
[mikumikustudio/libgdx-mikumikustudio.git] / tests / gdx-tests-lwjgl / src / com / badlogic / gdx / tests / lwjgl / Test2.java
1
2 package com.badlogic.gdx.tests.lwjgl;
3
4 import com.badlogic.gdx.ApplicationAdapter;
5 import com.badlogic.gdx.Gdx;
6 import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
7 import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
8 import com.badlogic.gdx.graphics.Color;
9 import com.badlogic.gdx.graphics.GL10;
10 import com.badlogic.gdx.graphics.Pixmap;
11 import com.badlogic.gdx.graphics.Pixmap.Format;
12 import com.badlogic.gdx.graphics.Texture;
13 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
14 import com.badlogic.gdx.graphics.g2d.TextureRegion;
15 import com.badlogic.gdx.utils.ScreenUtils;
16
17 public class Test2 extends ApplicationAdapter {
18         SpriteBatch batch;
19         TextureRegion region;
20         Pixmap screenCap;
21         Texture screenCapTex;
22         private int size = 2;
23
24         public void create () {
25
26                 batch = new SpriteBatch();
27                 Pixmap p = new Pixmap(64, 64, Format.RGBA8888);
28                 p.setColor(Color.RED);
29                 p.fillRectangle(32, 32, size , size );
30                 region = new TextureRegion(new Texture(p), 32, 32, size , size );
31
32                 Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
33                 Gdx.gl.glClearColor(0, 0, 0, 1);
34                 batch.begin();
35                 batch.draw(region, 1, 1, 256, 256);
36                 batch.end();
37                 screenCap = ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
38                 screenCapTex = new Texture(screenCap);
39                 System.out.println("size: " + size);
40                 System.out.println(Integer.toHexString(screenCap.getPixel(0, 0)));
41                 System.out.println(Integer.toHexString(screenCap.getPixel(1, 1)));
42                 System.out.println(Integer.toHexString(screenCap.getPixel(256, 256)));
43                 System.out.println(Integer.toHexString(screenCap.getPixel(257, 257)));
44         }
45
46         public void render () {
47                 Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
48                 Gdx.gl.glClearColor(0, 0, 0, 1);
49                 batch.begin();
50                 batch.draw(screenCapTex, 0, 0);
51                 batch.end();
52         }
53
54         public static void main (String[] args) {
55                 LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
56                 config.useGL20 = true;
57                 new LwjglApplication(new Test2(), config);
58         }
59 }