Advertisement
PaleoCrafter

Untitled

May 16th, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1. //drawRectangleRepeated(int x, int y, float u, float v, float uMax, float vMax, int width, int height, int tileWidth, int tileHeight, int zLevel)
  2. loadShaders();
  3. glUseProgram(program);
  4. glUniform1i(texLocation, 0);
  5. glUniform2f(iconOffsetLocation, u, v);
  6. glUniform2f(iconSizeLocation, uMax - u, vMax - v);
  7. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  8. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  9. drawRectangleStretched(x, y, 0, 0, width, height, 2F, 2F, zLevel);
  10. glUseProgram(0);
  11.  
  12. private static int fragShader, texLocation, iconOffsetLocation, iconSizeLocation = 0;
  13.  
  14. private static int program = 0;
  15.  
  16. public static void loadShaders()
  17. {
  18. if (program == 0)
  19.     try
  20.     {
  21.         program = glCreateProgram();
  22.         fragShader = createShader(new ResourceLocation("malisiscore", "shaders/repeat_frag.glsl"), GL_FRAGMENT_SHADER);
  23.         glAttachShader(program, fragShader);
  24.         glLinkProgram(program);
  25.         glValidateProgram(program);
  26.         texLocation = glGetUniformLocation(program, "tex");
  27.         iconOffsetLocation = glGetUniformLocation(program, "iconOffset");
  28.         iconSizeLocation = glGetUniformLocation(program, "iconSize");
  29.         IntBuffer iVal = BufferUtils.createIntBuffer(1);
  30.         glGetProgram(program, GL_INFO_LOG_LENGTH, iVal);
  31.  
  32.         int length = iVal.get();
  33.         if (length > 1)
  34.         {
  35.             System.err.println("true");
  36.         }
  37.     }
  38.     catch (Exception e)
  39.     {
  40.         e.printStackTrace();
  41.     }
  42. }
  43.  
  44. private static int createShader(ResourceLocation file, int shaderType) throws Exception
  45. {
  46. int shader = 0;
  47. try
  48. {
  49.     shader = glCreateShader(shaderType);
  50.  
  51.     if (shader == 0)
  52.         return 0;
  53.  
  54.     glShaderSource(shader, readFileAsString(getMC().getResourceManager().getResource(file).getInputStream()));
  55.     glCompileShader(shader);
  56.  
  57.     return shader;
  58. }
  59. catch (Exception exc)
  60. {
  61.     glDeleteShader(shader);
  62.     throw exc;
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement