Beispiel #1
0
  private void drawPlayerIcons(final Player player, double elapsedMillis) {
    quadVao.bind();
    playerTexture.bind(0);
    uiShader.use();

    final FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(16);
    Matrix4f projectionMatrix = new Matrix4f().setOrtho(0, windowWidth, windowHeight, 0, -1, 1);

    for (int i = 0; i < player.numLives(); i++) {
      final Matrix4f mat = new Matrix4f();
      mat.identity();
      mat.translate((float) windowWidth - 100 - i * 60f, 60, 0);
      mat.translate(25, 25, 0);
      mat.scale(25, 25, 1);

      Matrix4f tmp = new Matrix4f(projectionMatrix).mul(mat);
      tmp.get(matrixBuffer);
      uiShader.setUniformMatrixF("projMatrix", matrixBuffer);

      GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 6);
    }

    playerTexture.unbind();
    quadVao.unbind();
  }
  @Deprecated
  public void renderUISprite(Rectangle rect, Texture image, boolean hFlip, boolean vFlip) {
    GL20.glUseProgram(spriteShaderProgram.getProgramId());

    // Remember to change this calculation when I change the size of the flatplane
    Matrix4f modelMatrix =
        Matrix4f.translation(rect.getX(), rect.getY(), 0)
            .multiply(Matrix4f.scale(rect.getWidth(), rect.getHeight(), 1f));

    spriteVAO.bind();

    image.bind();
    // GL30.glBindVertexArray(flatPlane.getVaoId());

    GL20.glUniformMatrix4fv(
        spriteShaderProgram.getUniform("mvpMatrix").getLocation(), false, modelMatrix.toBuffer());
    GL20.glUniform1i(
        spriteShaderProgram.getUniform("horizontalFlip").getLocation(),
        (hFlip) ? GL11.GL_TRUE : GL11.GL_FALSE);
    GL20.glUniform1i(
        spriteShaderProgram.getUniform("verticalFlip").getLocation(),
        (vFlip) ? GL11.GL_TRUE : GL11.GL_FALSE);
    GL20.glUniform1i(spriteShaderProgram.getUniform("sprite").getLocation(), 0);

    GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, SPRITE_NUM_VERTICES);
  }
  public void drawTriangleArray(Mesh.Mode mode, int count, int vertCount) {
    if (count > 1) {
      throw new UnsupportedOperationException();
    }

    glDrawArrays(convertElementMode(mode), 0, vertCount);
  }
  public void render(int mode) {
    if (vertices != null) glEnableClientState(GL_VERTEX_ARRAY);
    if (normals != null) glEnableClientState(GL_NORMAL_ARRAY);
    if (colors != null) glEnableClientState(GL_COLOR_ARRAY);
    if (texCoords != null) glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    bindVBO();

    if (vertices != null) glVertexPointer(sizeV, GL_FLOAT, stride * 4, offV * 4);
    if (normals != null) glNormalPointer(GL_FLOAT, stride * 4, offN * 4);
    if (colors != null) glColorPointer(sizeC, GL_FLOAT, stride * 4, offC * 4);
    if (texCoords != null) glTexCoordPointer(sizeT, GL_FLOAT, stride * 4, offT * 4);

    if (indices != null) {
      bindIND();
      glDrawRangeElements(mode, 0, indices.length, indices.length, GL_UNSIGNED_INT, 0);
    } else {
      glDrawArrays(mode, 0, vertices.length);
    }

    if (vertices != null) glDisableClientState(GL_VERTEX_ARRAY);
    if (normals != null) glDisableClientState(GL_NORMAL_ARRAY);
    if (colors != null) glDisableClientState(GL_COLOR_ARRAY);
    if (texCoords != null) glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  }
  public void renderAnimationFrame(
      Transform transform, int frame, Texture tex, boolean horizontalFlip) {
    GL20.glUseProgram(animSpriteShaderProgram.getProgramId());

    spriteVAO.bind();
    // GL30.glBindVertexArray(flatPlane.getVaoId());

    Matrix4f finalMatrix =
        rs.getCamera()
            .getProjectionMatrix()
            .multiply(rs.getCamera().getWorldMatrix().multiply(transform.toMatrix()));

    // Diffuse Texture
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, tex.getTextureId());

    GL20.glUniformMatrix4fv(
        animSpriteShaderProgram.getUniform("mvpMatrix").getLocation(),
        false,
        finalMatrix.toBuffer());
    GL20.glUniform1i(animSpriteShaderProgram.getUniform("diffuseTextureAtlas").getLocation(), 0);
    GL20.glUniform1i(animSpriteShaderProgram.getUniform("currentFrame").getLocation(), frame);
    GL20.glUniform1i(
        animSpriteShaderProgram.getUniform("horizontalFlip").getLocation(),
        (horizontalFlip) ? GL11.GL_TRUE : GL11.GL_FALSE);

    GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, SPRITE_NUM_VERTICES);
  }
Beispiel #6
0
  /** R_DrawParticles */
  void R_DrawParticles() {

    if (gl_ext_pointparameters.value != 0.0f && qglPointParameterfEXT) {

      // GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
      GL11.glVertexPointer(3, 0, particle_t.vertexArray);
      GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
      GL11.glColorPointer(4, true, 0, particle_t.getColorAsByteBuffer());

      GL11.glDepthMask(false);
      GL11.glEnable(GL11.GL_BLEND);
      GL11.glDisable(GL11.GL_TEXTURE_2D);
      GL11.glPointSize(gl_particle_size.value);

      GL11.glDrawArrays(GL11.GL_POINTS, 0, r_newrefdef.num_particles);

      GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
      // GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);

      GL11.glDisable(GL11.GL_BLEND);
      GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
      GL11.glDepthMask(true);
      GL11.glEnable(GL11.GL_TEXTURE_2D);

    } else {
      GL_DrawParticles(r_newrefdef.num_particles);
    }
  }
  public void renderSprite(Transform transform, Texture texture, boolean hFlip, boolean vFlip) {
    GL20.glUseProgram(spriteShaderProgram.getProgramId());

    spriteVAO.bind();

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureId());

    Matrix4f finalMatrix =
        rs.getCamera()
            .getProjectionMatrix()
            .multiply(rs.getCamera().getWorldMatrix().multiply(transform.toMatrix()));

    GL20.glUniformMatrix4fv(
        spriteShaderProgram.getUniform("mvpMatrix").getLocation(), false, finalMatrix.toBuffer());
    GL20.glUniform1i(
        spriteShaderProgram.getUniform("horizontalFlip").getLocation(),
        (hFlip) ? GL11.GL_TRUE : GL11.GL_FALSE);
    GL20.glUniform1i(
        spriteShaderProgram.getUniform("verticalFlip").getLocation(),
        (vFlip) ? GL11.GL_TRUE : GL11.GL_FALSE);
    GL20.glUniform1i(spriteShaderProgram.getUniform("sprite").getLocation(), 0);

    GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, SPRITE_NUM_VERTICES);
  }
  public void display(long deltaTime) {
    Display.sync(60);
    elapsedTime += deltaTime;

    if (Display.wasResized()) resize();

    float[] offsets = computePositionOffsets(0, 0, deltaTime);
    float xOffset = offsets[0];
    float yOffset = offsets[1];
    adjustVertexData(xOffset, yOffset);

    glClearColor(0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT);

    glUseProgram(program);

    glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 4, GL_FLOAT, false, 0, 0);

    glDrawArrays(GL_TRIANGLES, 0, 3);

    glDisableVertexAttribArray(0);
    glUseProgram(0);

    Display.update(); // calls (among other things) swapBuffers()
  }
Beispiel #9
0
  public void draw() {
    glEnableVertexAttribArray(0);

    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glVertexAttribPointer(0, 3, GL_FLOAT, false, Vertex.SIZE * 4, 0);

    glDrawArrays(GL_TRIANGLES, 0, size);

    glDisableVertexAttribArray(0);
  }
Beispiel #10
0
  @Override
  public void draw(Program program) {
    glBindVertexArray(vao);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);

    glDrawArrays(GL_TRIANGLES, 0, 6 * 2 * 3);

    glBindVertexArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
  }
 private static void render() {
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glLoadIdentity();
   camera.applyTranslations();
   glUseProgram(currentShaderProgram);
   glLight(
       GL_LIGHT0,
       GL_POSITION,
       BufferTools.asFlippedFloatBuffer(camera.x(), camera.y(), camera.z(), 1));
   glDrawArrays(GL_TRIANGLES, 0, model.faces.size() * 3);
 }
Beispiel #12
0
 public static void glDrawArraysWrapper(int mode, int first, int count, ShortBuffer shortBuffer) {
   if (entityAttrib >= 0) {
     ARBVertexProgram.glEnableVertexAttribArrayARB(entityAttrib);
     ARBVertexProgram.glVertexAttribPointerARB(
         entityAttrib, 2, false, false, 4, (ShortBuffer) shortBuffer.position(0));
   }
   GL11.glDrawArrays(mode, first, count);
   if (entityAttrib >= 0) {
     ARBVertexProgram.glDisableVertexAttribArrayARB(entityAttrib);
   }
 }
 public void render(Camera camera) {
   shader.start();
   shader.loadViewMatrix(camera);
   GL30.glBindVertexArray(cube.getVaoID());
   GL20.glEnableVertexAttribArray(0);
   GL13.glActiveTexture(GL13.GL_TEXTURE0);
   GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texture);
   GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, cube.getVertexCount());
   GL20.glDisableVertexAttribArray(0);
   GL30.glBindVertexArray(0);
   shader.stop();
 }
Beispiel #14
0
  public void render() {
    if (((ViewerContainer3D) v.getContainer()).getPbuffer() != currentPbuffer) {
      for (int i = 0; i < vbo.length; i++) {
        vbo[i] = -1;
        selectedVbo[i] = -1;
      }
      currentPbuffer = ((ViewerContainer3D) v.getContainer()).getPbuffer();
    }

    for (int i = 0; i < tubes.length; i++) {
      if (hidden[i]) continue;

      int vbo;
      if (!selected[i]) {
        if (this.vbo[i] == -1) {
          Color c = colors[i];
          GL15.glDeleteBuffers(this.vbo[i]);
          this.vbo[i] = createTubeVbo(i, colors[i]);
        }
        vbo = this.vbo[i];
      } else {
        if (this.selectedVbo[i] == -1) {
          Color c = selectedColors[i];
          GL15.glDeleteBuffers(this.selectedVbo[i]);
          this.selectedVbo[i] = createTubeVbo(i, selectedColors[i]);
        }
        vbo = this.selectedVbo[i];
      }

      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);

      GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
      GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
      GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);

      GL11.glColorMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT_AND_DIFFUSE);
      GL11.glEnable(GL11.GL_COLOR_MATERIAL);

      GL11.glColorPointer(3, GL11.GL_FLOAT, vertexStride, colorPointer);
      GL11.glVertexPointer(3, GL11.GL_FLOAT, vertexStride, vertexPointer);
      GL11.glNormalPointer(GL11.GL_FLOAT, vertexStride, normalPointer);

      GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, totalNumVerts[i]);

      GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
      GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
      GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY);
      GL11.glDisable(GL11.GL_COLOR_MATERIAL);

      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    }
  }
  public static void main(String[] args) {
    Window window = new Window(1024, 768, false);

    window.setTitle("Hello OpenGL!");

    window.setVisible(true);

    int vertexCount = 3;
    int floatSize = 4;

    FloatBuffer buffer = createFloatBuffer(vertexCount * 3 + vertexCount * 4);
    buffer.put(0).put(0.5f).put(0);
    buffer.put(1).put(0).put(0).put(1);

    buffer.put(-0.5f).put(-0.5f).put(0);
    buffer.put(0).put(1).put(0).put(1);

    buffer.put(0.5f).put(-0.5f).put(0);
    buffer.put(0).put(0).put(1).put(1);
    buffer.flip();

    /*IntBuffer indices = ByteBuffer.allocateDirect(3 * 4).order(ByteOrder.nativeOrder()).asIntBuffer();
    indices.put(0).put(1).put(2);
    indices.flip();*/

    int vbo = glGenBuffers();

    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);

    while (!window.isCloseRequested()) {
      window.pollEvents();

      glEnableClientState(GL_VERTEX_ARRAY);
      glEnableClientState(GL_COLOR_ARRAY);

      glBindBuffer(GL_ARRAY_BUFFER, vbo);

      glVertexPointer(3, GL_FLOAT, 7 * floatSize, 0);
      glColorPointer(4, GL_FLOAT, 7 * floatSize, 3 * floatSize);

      glDrawArrays(GL_TRIANGLES, 0, 3);

      window.swap();
      window.sleep(16);
    }

    window.destroy();
  }
Beispiel #16
0
  private void renderGL() {
    glClear(GL_COLOR_BUFFER_BIT);

    // draw slices

    if (!syncGLtoCL) {
      glWaitSync(glFenceFromCLEvent, 0, 0);
      glDeleteSync(glFenceFromCLEvent);
      glFenceFromCLEvent = NULL;

      int errcode = clReleaseEvent(clEvent);
      clEvent = NULL;
      checkCLError(errcode);
    }

    glBindTexture(GL_TEXTURE_2D, glTexture);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  }
Beispiel #17
0
  /**
   * Renders the various attributes on screen
   *
   * @param size
   * @param position
   * @param rotMat
   */
  public void render(
      final Vector3<Float> size, final Vector3<Float> position, final Quaternion rotation) {
    try {
      boolean recalculate = false;
      if (!size.equals(lastSize)) {
        this.lastSize.set(size);
        recalculate = true;
      }
      if (!this.lastPosition.equals(position)) {
        this.lastPosition.set(position);
        recalculate = true;
      }
      if (!this.lastRot.equals(rotation)) {
        this.lastRot.set(rotation);
        recalculate = true;
      }
      // Only do the calculations when it has been changed
      if (recalculate) {
        Matrix4x4 mat = Matrix4x4.identityMatrix();
        mat = Matrix4x4.scale(mat, size);
        Matrix4x4 pos = Matrix4x4.identityMatrix();
        pos.translate(position);
        mat = Matrix4x4.multiply(pos, mat);
        this.lastMat.set(Matrix4x4.multiply(mat, Quaternion.quaternionToMatrix(rotation)));
      }

      glUseProgram(AssetManager.getProgram(this.program));
      glBindVertexArray(AssetManager.getMeshVao(this.mesh));

      glEnableVertexAttribArray(0);

      glUniformMatrix4fv(this.glPos, true, this.lastMat.getRawData());
      if (this.texture != -1) {
        glBindTexture(GL_TEXTURE_2D, AssetManager.getTexture(this.texture));
      }

      glDrawArrays(GL_TRIANGLES, 0, AssetManager.getMeshSize(this.mesh));
      glDisableVertexAttribArray(0);
      glBindVertexArray(0);
    } catch (AssetManager.AssetNotFoundException ex) {
      Logger.getLogger(Renderer.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Beispiel #18
0
 public void render(List<GuiTexture> guis) {
   shader.start();
   GL30.glBindVertexArray(quad.getVaoID());
   GL20.glEnableVertexAttribArray(0);
   GL11.glEnable(GL11.GL_BLEND);
   GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
   GL11.glDisable(GL11.GL_DEPTH_TEST);
   for (GuiTexture gui : guis) {
     GL13.glActiveTexture(GL13.GL_TEXTURE0);
     GL11.glBindTexture(GL11.GL_TEXTURE_2D, gui.getTexture());
     Matrix4f matrix = Maths.createTransformationMatrix(gui.getPosition(), gui.getScale());
     shader.loadTransformation(matrix);
     GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, quad.getVertexCount());
   }
   GL11.glEnable(GL11.GL_DEPTH_TEST);
   GL11.glDisable(GL11.GL_BLEND);
   GL20.glDisableVertexAttribArray(0);
   GL30.glBindVertexArray(0);
   shader.stop();
 }
 private static void render() {
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glLoadIdentity();
   cam.applyTranslations();
   glUseProgram(shaderProgram);
   glLight(GL_LIGHT0, GL_POSITION, asFloatBuffer(cam.x(), cam.y(), cam.z(), 1));
   glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
   glVertexPointer(3, GL_FLOAT, 0, 0L);
   glBindBuffer(GL_ARRAY_BUFFER, vboNormalHandle);
   glNormalPointer(GL_FLOAT, 0, 0L);
   glEnableClientState(GL_VERTEX_ARRAY);
   glEnableClientState(GL_NORMAL_ARRAY);
   glColor3f(0.4f, 0.27f, 0.17f);
   glMaterialf(GL_FRONT, GL_SHININESS, 10f);
   glDrawArrays(GL_TRIANGLES, 0, model.faces.size() * 3);
   glDisableClientState(GL_VERTEX_ARRAY);
   glDisableClientState(GL_NORMAL_ARRAY);
   glBindBuffer(GL_ARRAY_BUFFER, 0);
   glUseProgram(0);
 }
  @Override
  public void render() {

    GL11.glPushMatrix();

    GL11.glTranslatef(transform[0], transform[1], 0.0f);
    GL11.glRotatef((float) Math.toDegrees(transform[2]), 0, 0, 1);

    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    ARBBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, verticesBufferID);
    GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);

    GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
    ARBBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, normalsBufferID);
    GL11.glNormalPointer(GL11.GL_FLOAT, 0, 0);

    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, triangleCount * 3);

    GL11.glPopMatrix();
  }
Beispiel #21
0
 public void draw() {
   if (vertexVBO != null) {
     GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
   }
   if (colourVBO != null) {
     GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
   }
   if (textureVBO != null) {
     GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
   }
   GL11.glDrawArrays(GL11.GL_QUADS, 0, getNumElements());
   if (vertexVBO != null) {
     GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
   }
   if (colourVBO != null) {
     GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
   }
   if (textureVBO != null) {
     GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
   }
 }
  private void renderMeshDefault(Mesh mesh, int lod, int count) {
    VertexBuffer indices = null;

    VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
    if (interleavedData != null && interleavedData.isUpdateNeeded()) {
      updateBufferData(interleavedData);
    }

    if (mesh.getNumLodLevels() > 0) {
      indices = mesh.getLodLevel(lod);
    } else {
      indices = mesh.getBuffer(Type.Index);
    }
    for (VertexBuffer vb : mesh.getBufferList().getArray()) {
      if (vb.getBufferType() == Type.InterleavedData
          || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
          || vb.getBufferType() == Type.Index) {
        continue;
      }

      if (vb.getStride() == 0) {
        // not interleaved
        setVertexAttrib(vb);
      } else {
        // interleaved
        setVertexAttrib(vb, interleavedData);
      }
    }

    if (indices != null) {
      drawTriangleList(indices, mesh, count);
    } else {
      glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
    }

    // TODO: Fix these to use IDList??
    clearVertexAttribs();
    clearTextureUnits();
    resetFixedFuncBindings();
  }
Beispiel #23
0
  /** @Info fait le rendu du vbo */
  public void renderVBO() {
    glBindBuffer(GL_ARRAY_BUFFER, vboID);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);

    glVertexPointer(3, GL_FLOAT, (3 + 4) * FLOAT_SIZE, 0);
    glColorPointer(4, GL_FLOAT, (3 + 4) * FLOAT_SIZE, 3 * FLOAT_SIZE);

    // x,y,z,r,g,b,a,nx,ny,nz
    // glVertexPointer(3, GL_FLOAT, (3 + 4 + 3) * FLOAT_SIZE, 0);
    // glColorPointer(4, GL_FLOAT, (3 + 4 + 3) * FLOAT_SIZE, 3 * FLOAT_SIZE);
    // glNormalPointer(4, GL_FLOAT, (3 + 4 + 3) * FLOAT_SIZE, (3 + 4) * FLOAT_SIZE);

    //		glVertexAttribPointer(0,3,GL_FLOAT,false,7 * 4,0);
    //		glVertexAttribPointer(1,4,GL_FLOAT,false,7 * 4,12);

    glDrawArrays(GL_QUADS, 0, bufferSize);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
  }
Beispiel #24
0
 public void glDrawArrays(int mode, int first, int count) {
   GL11.glDrawArrays(mode, first, count);
 }
Beispiel #25
0
  public int draw() {
    if (!this.isDrawing) {
      throw new IllegalStateException("Not tesselating!");
    } else {
      this.isDrawing = false;
      if (this.vertexCount > 0) {
        this.intBuffer.clear();
        this.intBuffer.put(this.rawBuffer, 0, this.rawBufferIndex);
        this.byteBuffer.position(0);
        this.byteBuffer.limit(this.rawBufferIndex * 4);
        if (this.useVBO) {
          this.vboIndex = (this.vboIndex + 1) % this.vboCount;
          ARBVertexBufferObject.glBindBufferARB(
              ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, this.vertexBuffers.get(this.vboIndex));
          ARBVertexBufferObject.glBufferDataARB(
              ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB,
              this.byteBuffer,
              ARBVertexBufferObject.GL_STREAM_DRAW_ARB);
        }

        if (this.hasTexture) {
          if (this.useVBO) {
            GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 32, 12L);
          } else {
            this.floatBuffer.position(3);
            GL11.glTexCoordPointer(2, 32, this.floatBuffer);
          }

          GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);

          // Spout Start
          if (textureOverride > 0) GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureOverride);
          // Spout End
        }

        if (this.hasBrightness) {
          OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapEnabled);
          if (this.useVBO) {
            GL11.glTexCoordPointer(2, GL11.GL_SHORT, 32, 28L);
          } else {
            this.shortBuffer.position(14);
            GL11.glTexCoordPointer(2, 32, this.shortBuffer);
          }

          GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
          OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapDisabled);
        }

        if (this.hasColor) {
          if (this.useVBO) {
            GL11.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 32, 20L);
          } else {
            this.byteBuffer.position(20);
            GL11.glColorPointer(4, true, 32, this.byteBuffer);
          }

          GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
        }

        if (this.hasNormals) {
          if (this.useVBO) {
            GL11.glNormalPointer(GL11.GL_UNSIGNED_BYTE, 32, 24L);
          } else {
            this.byteBuffer.position(24);
            GL11.glNormalPointer(32, this.byteBuffer);
          }

          GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
        }

        if (this.useVBO) {
          GL11.glVertexPointer(3, GL11.GL_FLOAT, 32, 0L);
        } else {
          this.floatBuffer.position(0);
          GL11.glVertexPointer(3, 32, this.floatBuffer);
        }

        GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
        if (this.drawMode == 7 && convertQuadsToTriangles) {
          GL11.glDrawArrays(4, 0, this.vertexCount);
        } else {
          GL11.glDrawArrays(this.drawMode, 0, this.vertexCount);
        }

        GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
        if (this.hasTexture) {
          GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
        }

        if (this.hasBrightness) {
          OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapEnabled);
          GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
          OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapDisabled);
        }

        if (this.hasColor) {
          GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
        }

        if (this.hasNormals) {
          GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY);
        }
      }

      int var1 = this.rawBufferIndex * 4;
      this.reset();
      return var1;
    }
  }
  /** Draws the data set up in this tessellator and resets the state to prepare for new drawing. */
  public int draw() {
    if (!isDrawing) {
      throw new IllegalStateException("Not tesselating!");
    }

    isDrawing = false;

    if (vertexCount > 0) {
      intBuffer.clear();
      intBuffer.put(rawBuffer, 0, rawBufferIndex);
      byteBuffer.position(0);
      byteBuffer.limit(rawBufferIndex * 4);

      if (useVBO) {
        vboIndex = (vboIndex + 1) % vboCount;
        ARBVertexBufferObject.glBindBufferARB(
            ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vertexBuffers.get(vboIndex));
        ARBVertexBufferObject.glBufferDataARB(
            ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB,
            byteBuffer,
            ARBVertexBufferObject.GL_STREAM_DRAW_ARB);
      }

      if (hasTexture) {
        if (useVBO) {
          GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 32, 12L);
        } else {
          floatBuffer.position(3);
          GL11.glTexCoordPointer(2, 32, floatBuffer);
        }

        GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
      }

      if (hasBrightness) {
        OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapTexUnit);

        if (useVBO) {
          GL11.glTexCoordPointer(2, GL11.GL_SHORT, 32, 28L);
        } else {
          shortBuffer.position(14);
          GL11.glTexCoordPointer(2, 32, shortBuffer);
        }

        GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
        OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit);
      }

      if (hasColor) {
        if (useVBO) {
          GL11.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 32, 20L);
        } else {
          byteBuffer.position(20);
          GL11.glColorPointer(4, true, 32, byteBuffer);
        }

        GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
      }

      if (hasNormals) {
        if (useVBO) {
          GL11.glNormalPointer(GL11.GL_UNSIGNED_BYTE, 32, 24L);
        } else {
          byteBuffer.position(24);
          GL11.glNormalPointer(32, byteBuffer);
        }

        GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
      }

      if (useVBO) {
        GL11.glVertexPointer(3, GL11.GL_FLOAT, 32, 0L);
      } else {
        floatBuffer.position(0);
        GL11.glVertexPointer(3, 32, floatBuffer);
      }

      GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);

      if (drawMode == 7 && convertQuadsToTriangles) {
        GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertexCount);
      } else {
        GL11.glDrawArrays(drawMode, 0, vertexCount);
      }

      GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);

      if (hasTexture) {
        GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
      }

      if (hasBrightness) {
        OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapTexUnit);
        GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
        OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit);
      }

      if (hasColor) {
        GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
      }

      if (hasNormals) {
        GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY);
      }
    }

    int i = rawBufferIndex * 4;
    reset();
    return i;
  }
Beispiel #27
0
 public void draw() {
   if (ibo > 0) glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_BYTE, 0);
   else glDrawArrays(GL_TRIANGLES, 0, count);
 }
Beispiel #28
0
  public int func_982_a() {
    if (!field_1488_w) {
      throw new IllegalStateException("Not tesselating!");
    }
    if (renderingChunk && subTessellators.length > 0) {
      boolean flag = false;
      for (int j = 0; j < subTessellators.length; j++) {
        int k = subTextures[j];
        if (k <= 0) {
          break;
        }
        Tessellator tessellator = subTessellators[j];
        if (tessellator.field_1488_w) {
          GL11.glBindTexture(3553, k);
          tessellator.func_982_a();
          flag = true;
        }
      }

      if (flag) {
        GL11.glBindTexture(3553, getTerrainTexture());
      }
    }
    field_1488_w = false;
    if (field_1505_h > 0) {
      field_1508_e.clear();
      field_1508_e.put(field_1506_g, 0, field_1498_o);
      field_1509_d.position(0);
      field_1509_d.limit(field_1498_o * 4);
      if (field_1487_x) {
        field_1485_z = (field_1485_z + 1) % field_1496_A;
        ARBVertexBufferObject.glBindBufferARB(34962, field_1486_y.get(field_1485_z));
        ARBVertexBufferObject.glBufferDataARB(34962, field_1509_d, 35040);
      }
      if (field_1500_m) {
        if (field_1487_x) {
          GL11.glTexCoordPointer(2, 5126, 32, 12L);
        } else {
          field_1507_f.position(3);
          GL11.glTexCoordPointer(2, 32, field_1507_f);
        }
        GL11.glEnableClientState(32888);
      }
      if (field_35838_p) {
        OpenGlHelper.func_40451_b(OpenGlHelper.field_40455_b);
        if (field_1487_x) {
          GL11.glTexCoordPointer(2, 5122, 32, 28L);
        } else {
          field_35836_g.position(14);
          GL11.glTexCoordPointer(2, 32, field_35836_g);
        }
        GL11.glEnableClientState(32888);
        OpenGlHelper.func_40451_b(OpenGlHelper.field_40457_a);
      }
      if (field_1501_l) {
        if (field_1487_x) {
          GL11.glColorPointer(4, 5121, 32, 20L);
        } else {
          field_1509_d.position(20);
          GL11.glColorPointer(4, true, 32, field_1509_d);
        }
        GL11.glEnableClientState(32886);
      }
      if (field_1499_n) {
        if (field_1487_x) {
          GL11.glNormalPointer(5121, 32, 24L);
        } else {
          field_1509_d.position(24);
          GL11.glNormalPointer(32, field_1509_d);
        }
        GL11.glEnableClientState(32885);
      }
      if (field_1487_x) {
        GL11.glVertexPointer(3, 5126, 32, 0L);
      } else {
        field_1507_f.position(0);
        GL11.glVertexPointer(3, 32, field_1507_f);
      }
      GL11.glEnableClientState(32884);
      if (field_1493_r == 7 && field_1511_b) {
        GL11.glDrawArrays(4, 0, field_1505_h);
      } else {
        GL11.glDrawArrays(field_1493_r, 0, field_1505_h);
      }
      GL11.glDisableClientState(32884);
      if (field_1500_m) {
        GL11.glDisableClientState(32888);
      }
      if (field_35838_p) {
        OpenGlHelper.func_40451_b(OpenGlHelper.field_40455_b);
        GL11.glDisableClientState(32888);
        OpenGlHelper.func_40451_b(OpenGlHelper.field_40457_a);
      }
      if (field_1501_l) {
        GL11.glDisableClientState(32886);
      }
      if (field_1499_n) {
        GL11.glDisableClientState(32885);
      }
    }
    int i = field_1498_o * 4;
    func_985_d();
    return i;
  }