OSDN Git Service

Javadoc
[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, 1 , 1);
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                 
38                 screenCap = ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
39                 screenCapTex = new Texture(screenCap);
40                 System.out.println("size: " + size);
41                 System.out.println(Integer.toHexString(screenCap.getPixel(0, 0)));
42                 System.out.println(Integer.toHexString(screenCap.getPixel(1, 1)));
43                 System.out.println(Integer.toHexString(screenCap.getPixel(256, 256)));
44                 System.out.println(Integer.toHexString(screenCap.getPixel(257, 257)));
45         }
46
47         public void render () {
48                 Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
49                 Gdx.gl.glClearColor(0, 0, 0, 1);
50                 batch.begin();
51                 batch.draw(screenCapTex, 0, 0);
52                 batch.end();
53         }
54
55         public static void main (String[] args) {
56                 LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
57                 config.useGL20 = true;
58                 new LwjglApplication(new Test2(), config);
59         }
60 }