SHARE
TWEET

Untitled

a guest Sep 16th, 2014 170 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package screen.game;
  8.  
  9. import com.badlogic.gdx.Gdx;
  10. import com.badlogic.gdx.Input.Keys;
  11. import com.badlogic.gdx.InputAdapter;
  12. import com.badlogic.gdx.InputMultiplexer;
  13. import com.badlogic.gdx.assets.AssetManager;
  14. import com.badlogic.gdx.graphics.GL20;
  15. import com.badlogic.gdx.graphics.Mesh;
  16. import com.badlogic.gdx.graphics.Texture;
  17. import com.badlogic.gdx.graphics.VertexAttribute;
  18. import com.badlogic.gdx.graphics.VertexAttributes.Usage;
  19. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  20. import com.badlogic.gdx.graphics.g3d.Material;
  21. import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute;
  22. import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader;
  23. import com.badlogic.gdx.graphics.glutils.ShaderProgram;
  24. import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
  25. import com.badlogic.gdx.math.Matrix4;
  26. import phoenixgameclient.PhoenixGame;
  27. import screen.BaseScreen;
  28. import screen.menu.MenuScreen;
  29.  
  30. /**
  31.  *
  32.  * @author Alex
  33.  */
  34. public class FreeplayGameScreen extends BaseScreen {
  35.     AssetManager assetManager;
  36.     ShapeRenderer shapeRenderer;
  37.    
  38.     InputMultiplexer inputMultiplexer = new InputMultiplexer();
  39.    
  40.     private Mesh mesh;
  41.     private ShaderProgram defaultShader;
  42.         Matrix4 projectionMatrix;
  43.        
  44.     public FreeplayGameScreen(PhoenixGame game) {
  45.         super(game);
  46.         assetManager = game.getAssetManager();
  47.         shapeRenderer = new ShapeRenderer();
  48.        
  49.         Gdx.input.setInputProcessor(inputMultiplexer);
  50.         inputMultiplexer.addProcessor( new MyInputAdapter() );
  51.        
  52.         /*mesh = new Mesh(true, 3, 3,
  53.                     new VertexAttribute(Usage.Position, 3, "a_position"),
  54.                     new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));  */
  55.        
  56.                 mesh = new Mesh(true, 3, 3,
  57.                 VertexAttribute.Position(),
  58.                 VertexAttribute.TexCoords(0));
  59.  
  60.             mesh.setVertices(new float[] { -0.5f, -0.5f, 0,  0, 1,
  61.                                            0.5f, -0.5f, 0,  1, 1,
  62.                                            0, 0.5f, 0,  0.5f, 0 });  
  63.             mesh.setIndices(new short[] { 0, 1, 2 });  
  64.            
  65.         //defaultShader = new ShaderProgram(DefaultShader.getDefaultVertexShader(), DefaultShader.getDefaultFragmentShader());
  66.         defaultShader = SpriteBatch.createDefaultShader();  
  67.         Material mat = new Material();
  68.         mat.set(TextureAttribute.createDiffuse(assetManager.get("ground/ground.png", Texture.class)));
  69.        
  70.         projectionMatrix = new Matrix4(); // Create a Matrix4 that we will use for our projection matrix
  71.         projectionMatrix.setToOrtho(-1, 1, -1, 1, 0, 1);
  72.     }
  73.  
  74.     class MyInputAdapter extends InputAdapter {
  75.         @Override
  76.         public boolean scrolled(int amount) {
  77.             return false;
  78.         }
  79.     }
  80.    
  81.     private void update(float delta) {
  82.         game.setDeltaTime(delta);
  83.     }
  84.    
  85.     @Override
  86.     public void render(float delta) {
  87.         update(delta);
  88.        
  89.         clearScreen();
  90.         //Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
  91.         //assetManager.get("ground/ground.png", Texture.class).bind();
  92.         //defaultShader.setUniformi("u_diffuseTexture", 0);
  93.         //mesh.render(defaultShader, 4, 0, 3);
  94.        
  95.         defaultShader.begin(); // Begin our shader
  96.         defaultShader.setUniformMatrix("u_projTrans", projectionMatrix);    
  97.         defaultShader.setUniformi("u_texture", 0); // Pass in our texture uniform to our shader. Uniform name "u_texture".
  98.  
  99.         assetManager.get("ground/ground.png", Texture.class).bind(); // Bind the texture
  100.         mesh.render(defaultShader, GL20.GL_TRIANGLES); // Render our mesh with the shader, and primitive type GL_TRIANGLES
  101.         defaultShader.end();
  102.  
  103.         /*batch.begin();
  104.         batch.end();
  105.        
  106.         shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
  107.        
  108.         shapeRenderer.end();*/
  109.  
  110.         handleInput();
  111.     }
  112.    
  113.     protected void handleInput() {
  114.         if(Gdx.input.isKeyPressed(Keys.ESCAPE))
  115.             game.setScreen(new MenuScreen(game));
  116.     }
  117.  
  118.     @Override
  119.     public void resize(int width, int height) {
  120.     }
  121.  
  122.     @Override
  123.     public void show() {
  124.     }
  125.  
  126.     @Override
  127.     public void hide() {
  128.     }
  129.  
  130.     @Override
  131.     public void pause() {
  132.     }
  133.  
  134.     @Override
  135.     public void resume() {
  136.     }
  137. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top