SHARE
TWEET

Untitled

a guest Mar 19th, 2012 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package space.engine.test;
  2.  
  3. import org.newdawn.slick.AppGameContainer;
  4. import org.newdawn.slick.BasicGame;
  5. import org.newdawn.slick.GameContainer;
  6. import org.newdawn.slick.Graphics;
  7. import org.newdawn.slick.Image;
  8. import org.newdawn.slick.Input;
  9. import org.newdawn.slick.SlickException;
  10.  
  11. import space.engine.ShaderProgram;
  12.  
  13. public class SimpleShaderTest extends BasicGame {
  14.        
  15.         public static void main(String[] args) throws SlickException {
  16.                 new AppGameContainer(new SimpleShaderTest(), 800, 600, false).start();
  17.         }
  18.        
  19.         public SimpleShaderTest() {
  20.                 super("shader test");
  21.         }
  22.  
  23.         Image clouds;
  24.         ShaderProgram program;
  25.        
  26.         private boolean shaderWorks, useShader=true;
  27.        
  28.         @Override
  29.         public void init(GameContainer container) throws SlickException {
  30.                 clouds = new Image("res/clouds.jpg");
  31.                
  32.                 // We can disable 'strict' mode which means that trying to change a
  33.                 // non-active uniform won't throw a runtime exception
  34.                 //ShaderProgram.setStrictMode(false);
  35.                
  36.                 //often its wise to hard-code the shader... but for now we'll use a file
  37.                 program = ShaderProgram.loadProgram("res/hellovert.shader", "res/hellofrag.shader");
  38.                 shaderWorks = program.valid();
  39.                 if (shaderWorks) {
  40.                         //set up our uniforms...
  41.                         program.bind();
  42.                         program.setUniform1i("tex", 0); //texture 0
  43.                         program.unbind();
  44.                 } else {
  45.                         System.out.println("Error loading shader... "+program.getLog());
  46.                 }
  47.         }
  48.        
  49.         //@Override
  50.         public void render(GameContainer container, Graphics g) throws SlickException {
  51.                 if (shaderWorks && useShader)
  52.                         program.bind();
  53.                
  54.                 g.drawImage(clouds, 100, 100);
  55.                
  56.                 if (shaderWorks && useShader)
  57.                         program.unbind();
  58.                
  59.                 if (shaderWorks)
  60.                         g.drawString("Space to toggle shader", 10, 20);
  61.                 else
  62.                         g.drawString("Shader didn't load: "+program.getLog(), 10, 20);
  63.         }
  64.  
  65.         @Override
  66.         public void update(GameContainer container, int delta) throws SlickException {
  67.                 if (container.getInput().isKeyPressed(Input.KEY_SPACE))
  68.                         useShader = !useShader;
  69.         }
  70.  
  71. }
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
Top