Guest User

TexturedEntityShader

a guest
Oct 18th, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.39 KB | None | 0 0
  1. package Engine.GraphicsEngine;
  2.  
  3. import org.lwjglx.util.vector.Matrix4f;
  4.  
  5. import Engine.ModelHandeling.TexturedModel;
  6.  
  7. /** This class contains a basic shader for textured models.
  8.  *
  9.  * @author Bram Steenbergen
  10.  * @version 1.0
  11.  * @since 1.0
  12.  * @see TexturedModel
  13.  * @see AbstractShader
  14.  */
  15. public class TexturedEntityShader extends AbstractShader{
  16.     /** Filename of the vertex shader.
  17.      */
  18.     private static final String VERTEX_FILE = "TexturedEntityShader.vs";
  19.     /** Filename of the fragment shader.
  20.      */
  21.     private static final String FRAGMENT_FILE = "TexturedEntityShader.fs";
  22.     /** The location for the TransformationMatrix.
  23.      */
  24.     private int transformationMatrixLocation;
  25.    
  26.     private int projectionMatrixLocation;
  27.    
  28.     private int useProjectionMatrixLocation;
  29.    
  30.     private boolean useProjectionMatrix;
  31.    
  32.     /** Create a new TexturedEntityShader
  33.      */
  34.     public TexturedEntityShader() {
  35.         super(VERTEX_FILE, FRAGMENT_FILE);
  36.         useProjectionMatrix = false;
  37.     }
  38.    
  39.     @Override
  40.     /** Bind the attributes of the shader.
  41.      */
  42.     protected void bindAttributes() {
  43.         //bind position.
  44.         super.bindAttribute(0, "position");
  45.         //bind textures.
  46.         super.bindAttribute(1, "textureCoordinate");
  47.     }
  48.  
  49.     @Override
  50.     /** Get all uniform locations.
  51.      */
  52.     protected void getAllUniformLocations() {
  53.         transformationMatrixLocation = super.getUniformLocation("transformationMatrix");
  54.         projectionMatrixLocation = super.getUniformLocation("projectionMatrix");
  55.         useProjectionMatrixLocation = super.getUniformLocation("useProjectionMatrix");
  56.         System.out.println(projectionMatrixLocation + "    " + useProjectionMatrixLocation    +    "    " + transformationMatrixLocation);
  57.        
  58.     }
  59.    
  60.     /** Load the transformationMatrix.
  61.      *
  62.      * @param matrix the transformationMatrix to load
  63.      */
  64.     public void loadTransformationMatrix(Matrix4f matrix) {
  65.         super.loadMatrix(transformationMatrixLocation, matrix);
  66.     }
  67.    
  68.     public void loadProjectionMatrix(Matrix4f matrix) {
  69.         super.start();
  70.         super.loadMatrix(projectionMatrixLocation, matrix);
  71.         super.stop();
  72.         useProjectionMatrix = true;
  73.         System.out.println("loade: " + matrix);
  74.     }
  75.    
  76.     public void loadUseProjectionMatrix() {
  77.         super.loadBoolean(useProjectionMatrixLocation, useProjectionMatrix);
  78.         System.out.println("loaded: " + useProjectionMatrix);
  79.     }
  80.      
  81. }
Add Comment
Please, Sign In to add comment