Ejemplo n.º 1
0
  @Override
  protected void render() {
    glClearColor(0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT);
    glRotatef(1, 1, 0, 0);

    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glDrawElements(GL_QUAD_STRIP, brickIndices);
    glPolygonMode(GL_FRONT, GL_FILL);
    glDrawElements(GL_QUADS, paintedWall);
  }
Ejemplo n.º 2
0
 public void glDrawElements(int mode, int count, int type, Buffer indices) {
   if (indices instanceof ShortBuffer && type == GL_UNSIGNED_SHORT)
     GL11.glDrawElements(mode, (ShortBuffer) indices);
   else if (indices instanceof ByteBuffer && type == GL_UNSIGNED_SHORT)
     GL11.glDrawElements(mode, ((ByteBuffer) indices).asShortBuffer()); // FIXME yay...
   else if (indices instanceof ByteBuffer && type == GL_UNSIGNED_BYTE)
     GL11.glDrawElements(mode, (ByteBuffer) indices);
   else
     throw new GdxRuntimeException(
         "Can't use "
             + indices.getClass().getName()
             + " with this method. Use ShortBuffer or ByteBuffer instead. Blame LWJGL");
 }
Ejemplo n.º 3
0
 private void drawElements(int mode, int format, Buffer data) {
   switch (format) {
     case GL_UNSIGNED_BYTE:
       glDrawElements(mode, (ByteBuffer) data);
       break;
     case GL_UNSIGNED_SHORT:
       glDrawElements(mode, (ShortBuffer) data);
       break;
     case GL_UNSIGNED_INT:
       glDrawElements(mode, (IntBuffer) data);
       break;
     default:
       throw new UnsupportedOperationException();
   }
 }
Ejemplo n.º 4
0
 @Override
 public void draw() {
   checkCreated();
   // Bind the vao and enable all attributes
   GL30.glBindVertexArray(id);
   for (int i = 0; i < attributeBufferIDs.length; i++) {
     GL20.glEnableVertexAttribArray(i);
   }
   // Bind the indices buffer
   GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBufferID);
   // Draw all indices with the provided mode
   GL11.glDrawElements(
       drawingMode.getGLConstant(),
       indicesCount,
       GL11.GL_UNSIGNED_INT,
       indicesOffset * DataType.INT.getByteSize());
   // Unbind the indices buffer
   GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
   // Disable all attributes and unbind the vao
   for (int i = 0; i < attributeBufferIDs.length; i++) {
     GL20.glDisableVertexAttribArray(i);
   }
   GL30.glBindVertexArray(0);
   // Check for errors
   LWJGLUtil.checkForGLError();
 }
Ejemplo n.º 5
0
  public void render(int x, int y, float extra) {
    setExtraLevel(extra);
    glPushMatrix();
    shader.bind();
    glBindVertexArray(vao);
    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);
    {
      glTranslatef(x, y, 0);
      glActiveTexture(GL_TEXTURE1);
      glBindTexture(GL_TEXTURE_2D, texture);
      glActiveTexture(GL_TEXTURE2);
      glBindTexture(GL_TEXTURE_2D, Texture.Lava);
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vio);
      glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, 0);
      glActiveTexture(GL_TEXTURE1);
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
      glBindTexture(GL_TEXTURE_2D, 0);

      /*
       * glTranslatef(x, y, 0); glBindTexture(GL_TEXTURE_2D, texture); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vio); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindTexture(GL_TEXTURE_2D, 0);
       */
    }
    glDisableVertexAttribArray(1);
    glDisableVertexAttribArray(0);
    glBindVertexArray(0);
    shader.release();
    glPopMatrix();
  }
  @Override
  protected void update(double time) {
    glClear(GL_COLOR_BUFFER_BIT);

    program.activate();

    // Bind to the VAO that has all the information about the vertices
    glBindVertexArray(vaoId);
    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);

    // Bind to the index VBO that has all the information about the order of the vertices
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboiId);

    // Draw the vertices
    glDrawElements(GL_TRIANGLES, indicesCount, GL_UNSIGNED_BYTE, 0);

    // Put everything back to default (deselect)
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    glDisableVertexAttribArray(0);
    glDisableVertexAttribArray(1);
    glBindVertexArray(0);

    Program.deactivate();
  }
 public void render(List<Terrain> terrains, Matrix4f toShadowSpace) {
   shader.loadToShadowSpaceMatrix(toShadowSpace);
   for (Terrain t : terrains) {
     prepareTerrain(t);
     loadModelMatrix(t);
     GL11.glDrawElements(
         GL11.GL_TRIANGLES, t.getModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
     unbindShtuffs();
   }
 }
Ejemplo n.º 8
0
 public void render(Map<TexturedModel, List<Entity>> entities, Matrix4f toShadowMap) {
   shader.loadToShadowSpaceMatrix(toShadowMap);
   for (TexturedModel model : entities.keySet()) {
     prepareTexturedModel(model);
     List<Entity> batch = entities.get(model);
     for (Entity entity : batch) {
       if (entity.isRenderable()) {
         prepareInstance(entity);
         if (SettingHolder.get("cg_debug_polygons").getValueB()) {
           GL11.glDrawElements(
               GL11.GL_LINE_STRIP, model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
         } else {
           GL11.glDrawElements(
               GL11.GL_TRIANGLES, model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
         }
       }
     }
     unbindTexturedModel();
   }
 }
Ejemplo n.º 9
0
 public void render(Map<TexturedModel, List<Entity>> entities) {
   for (TexturedModel model : entities.keySet()) {
     prepareTexturedModel(model);
     List<Entity> batch = entities.get(model);
     for (Entity entity : batch) {
       prepareInstance(entity);
       GL11.glDrawElements(
           GL11.GL_TRIANGLES, model.getModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
     }
     unbindTexturedModel();
   }
 }
Ejemplo n.º 10
0
  public void draw() {

    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
    glDrawElements(GL_TRIANGLES, indices.length, GL_UNSIGNED_INT, 0);

    glDisableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  }
Ejemplo n.º 11
0
  @Override
  public void flush() {
    if (vertexOffset == 0) {
      return;
    }
    ctx.checkGLError("Shader.flush");

    vertexData.position(0);
    glBufferData(GL_ARRAY_BUFFER, vertexData, GL_STREAM_DRAW);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementData, GL_STREAM_DRAW);
    ctx.checkGLError("Shader.flush BufferData");

    glDrawElements(GL_TRIANGLES, elementOffset, GL_UNSIGNED_SHORT, 0);
    vertexOffset = elementOffset = 0;
    ctx.checkGLError("Shader.flush DrawElements");
  }
Ejemplo n.º 12
0
  @Override
  public void draw(GameTime gameTime) {
    GL11.glClearColor(0, 0, 0, 0);
    GL11.glClearDepth(1.0);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    RasterizerState.CULL_CLOCKWISE.set();
    BlendState.OPAQUE.set();
    DepthState.DEFAULT.set();

    program.use();
    texture.use(TextureUnit.Texture0, program.getUniform("Texture"));
    vb.useAsAttrib(fxsi);
    ib.bind();
    GL11.glDrawElements(PrimitiveType.Triangles, 6, GLType.UnsignedInt, 0);
    ib.unbind();
    texture.unuse();
    GLProgram.unuse();

    if (!savedImage) {
      int sw = game.getWidth();
      int sh = game.getHeight();
      ByteBuffer pb = NativeMem.createByteBuffer(sw * sh * 4);
      GL11.glReadPixels(0, 0, sw, sh, PixelFormat.Rgba, GLType.UnsignedByte, pb);
      pb.position(0);
      pb.limit(sw * sh * 4);

      byte[] cb = new byte[4];
      BufferedImage im = new BufferedImage(sw, sh, BufferedImage.TYPE_INT_ARGB);
      for (int y = sh - 1; y >= 0; y--) {
        for (int x = 0; x < sw; x++) {
          pb.get(cb);
          im.setRGB(
              x, y, (cb[2] & 0xFF) | ((cb[1] & 0xFF) << 8) | ((cb[0] & 0xFF) << 16) | 0xFF000000);
        }
      }

      try {
        ImageIO.write(im, "png", new File("Diag.png"));
        System.out.println("Image Has Been Saved");
      } catch (IOException e) {
        System.out.println(e.getMessage());
      }

      savedImage = true;
    }
  }
Ejemplo n.º 13
0
  public void render() {
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glNormalPointer(0, normals);
    glVertexPointer(3, 0, vertices);
    glTexCoordPointer(2, 0, texCoords);
    // glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    glDrawElements(GL_TRIANGLES, indices);

    // glDrawElements(GL_TRIANGLES, indices);
    // indices.flip();
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
  }
  /**
   * Renders entieis to the shadow map. Each model is first bound and then all of the entities using
   * that model are rendered to the shadow map.
   *
   * @param entities - the entities to be rendered to the shadow map.
   */
  protected void render(Map<TexturedModel, List<Entity>> entities) {
    for (TexturedModel model : entities.keySet()) {
      RawModel rawModel = model.getRawModel();
      bindModel(rawModel);
      GL13.glActiveTexture(GL13.GL_TEXTURE0);
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, model.getTexture().getID());
      if (model.getTexture().hasTransparency()) MasterRenderer.disableCulling();

      for (Entity entity : entities.get(model)) {
        prepareInstance(entity);
        GL11.glDrawElements(GL11.GL_TRIANGLES, rawModel.getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
      }

      if (model.getTexture().hasTransparency()) MasterRenderer.enableCulling();
    }
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL30.glBindVertexArray(0);
  }
Ejemplo n.º 15
0
  private void renderVbo(int id) {
    if (lock.tryLock()) {
      try {
        if (vertexBuffers[id] <= 0 || disposed) {
          return;
        }

        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
        glEnableClientState(GL_NORMAL_ARRAY);

        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, idxBuffers[id]);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBuffers[id]);

        glVertexPointer(SIZE_VERTEX, GL11.GL_FLOAT, STRIDE, OFFSET_VERTEX);

        GL13.glClientActiveTexture(GL13.GL_TEXTURE0);
        glTexCoordPointer(SIZE_TEX0, GL11.GL_FLOAT, STRIDE, OFFSET_TEX_0);

        GL13.glClientActiveTexture(GL13.GL_TEXTURE1);
        glTexCoordPointer(SIZE_TEX1, GL11.GL_FLOAT, STRIDE, OFFSET_TEX_1);

        glColorPointer(SIZE_COLOR * 4, GL11.GL_UNSIGNED_BYTE, STRIDE, OFFSET_COLOR);

        glNormalPointer(GL11.GL_FLOAT, STRIDE, OFFSET_NORMAL);

        GL11.glDrawElements(GL11.GL_TRIANGLES, vertexCount[id], GL11.GL_UNSIGNED_INT, 0);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

        glDisableClientState(GL_NORMAL_ARRAY);
        glDisableClientState(GL_COLOR_ARRAY);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
        glDisableClientState(GL_VERTEX_ARRAY);

      } finally {
        lock.unlock();
      }
    }
  }
Ejemplo n.º 16
0
  public void renderBuffer(OpenGLBuffer buffer, ITextureObject texture) {
    GL13.glActiveTexture(GL13.GL_TEXTURE0 + 0);
    texture.bind();
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);
    glEnableVertexAttribArray(2);

    glBindBuffer(GL_ARRAY_BUFFER, buffer.getVboID());
    glVertexAttribPointer(0, 3, GL_FLOAT, false, Vertex.SIZE_IN_FLOATS * 4, 0);
    glVertexAttribPointer(1, 2, GL_FLOAT, false, Vertex.SIZE_IN_FLOATS * 4, 12);
    glVertexAttribPointer(2, 3, GL_FLOAT, false, Vertex.SIZE_IN_FLOATS * 4, 20);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer.getIboID());
    glDrawElements(GL_TRIANGLES, buffer.getIndicesCount(), GL_UNSIGNED_INT, 0);

    glDisableVertexAttribArray(2);
    glDisableVertexAttribArray(1);
    glDisableVertexAttribArray(0);
  }
Ejemplo n.º 17
0
  public void render(Camera camera) {
    shader.start();
    shader.loadViewMatrix(camera);
    GL30.glBindVertexArray(sun.getRawModel().getVaoID());
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    shader.loadBlendFactor();
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
    GL13.glActiveTexture(GL13.GL_TEXTURE1);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, redSunTexture);
    billboardRotation(camera);
    GL11.glDrawElements(
        GL11.GL_TRIANGLES, sun.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);

    GL11.glDisable(GL11.GL_BLEND);
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL30.glBindVertexArray(0);
    shader.stop();
  }
  public void loopCycle() {
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

    GL20.glUseProgram(pId);

    // Bind to the VAO that has all the information about the vertices
    GL30.glBindVertexArray(vaoId);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);

    // Bind to the index VBO that has all the information about the order of the vertices
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);

    // Draw the vertices
    GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);

    // Put everything back to default (deselect)
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL30.glBindVertexArray(0);
    GL20.glUseProgram(0);
  }
Ejemplo n.º 19
0
 public void render() {
   glPushMatrix();
   glEnable(GL_BLEND);
   shader.bind();
   glBindVertexArray(vao);
   glEnableVertexAttribArray(0);
   glEnableVertexAttribArray(1);
   {
     glTranslatef(x, y, 0);
     glActiveTexture(GL_TEXTURE1);
     glBindTexture(GL_TEXTURE_2D, texture);
     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vio);
     glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, 0);
     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
     glBindTexture(GL_TEXTURE_2D, 0);
   }
   glDisableVertexAttribArray(1);
   glDisableVertexAttribArray(0);
   glBindVertexArray(0);
   shader.release();
   glDisable(GL_BLEND);
   glPopMatrix();
 }
Ejemplo n.º 20
0
 public void glDrawElements(int mode, int count, int type, int indices) {
   GL11.glDrawElements(mode, count, type, indices);
 }
Ejemplo n.º 21
0
 public void draw() {
   if (ibo > 0) glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_BYTE, 0);
   else glDrawArrays(GL_TRIANGLES, 0, count);
 }