Beispiel #1
0
  private void renderMesh() {
    if (idx == 0) return;

    renderCalls++;
    totalRenderCalls++;
    int spritesInBatch = idx / 20;
    if (spritesInBatch > maxSpritesInBatch) maxSpritesInBatch = spritesInBatch;

    lastTexture.bind();
    mesh.setVertices(vertices, 0, idx);

    if (blendingDisabled) {
      Gdx.gl.glDisable(GL20.GL_BLEND);
    } else {
      Gdx.gl.glEnable(GL20.GL_BLEND);
      Gdx.gl.glBlendFunc(blendSrcFunc, blendDstFunc);
    }

    if (Gdx.graphics.isGL20Available()) {
      if (customShader != null) mesh.render(customShader, GL10.GL_TRIANGLES, 0, spritesInBatch * 6);
      else mesh.render(shader, GL10.GL_TRIANGLES, 0, spritesInBatch * 6);
    } else {
      mesh.render(GL10.GL_TRIANGLES, 0, spritesInBatch * 6);
    }

    idx = 0;
    currBufferIdx++;
    if (currBufferIdx == buffers.length) currBufferIdx = 0;
    mesh = buffers[currBufferIdx];
  }
  private void renderPlanet(
      GL10 gl,
      String texture,
      boolean uvtype,
      float radius,
      float x,
      float y,
      float z,
      Application app) {
    radius = radius * worldscale;

    if (texture.equals("earth")) {
      // render earth/jupiter  texture
      planetTexture.bind();
    } else if (texture.equals("sun")) {
      // render mars/sun  texture
      planetTexture.bind();
    }

    gl.glPushMatrix();
    // move away from origin
    gl.glTranslatef(x, y, z);
    // scale to 10% size of earth
    gl.glScalef(radius, radius, radius);
    gl.glRotatef((Splash.planetmove / 10) - 180, 0, 1, 0);
    if (uvtype == true) {
      // render lower planet texture
      planetMesh.render(GL10.GL_TRIANGLES);
    } else {
      // render upper planet texture
      planetMesh02.render(GL10.GL_TRIANGLES);
    }
    gl.glPopMatrix();
  }
  @Override
  public void render() {
    frameBuffer.begin();
    Gdx.graphics.getGL20().glViewport(0, 0, frameBuffer.getWidth(), frameBuffer.getHeight());
    Gdx.graphics.getGL20().glClearColor(0f, 1f, 0f, 1);
    Gdx.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT);
    Gdx.graphics.getGL20().glEnable(GL20.GL_TEXTURE_2D);
    texture.bind();
    meshShader.begin();
    meshShader.setUniformi("u_texture", 0);
    mesh.render(meshShader, GL20.GL_TRIANGLES);
    meshShader.end();
    frameBuffer.end();

    Gdx.graphics.getGL20().glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.graphics.getGL20().glClearColor(0.2f, 0.2f, 0.2f, 1);
    Gdx.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT);

    spriteBatch.begin();
    spriteBatch.draw(
        frameBuffer.getColorBufferTexture(),
        0,
        0,
        256,
        256,
        0,
        0,
        frameBuffer.getColorBufferTexture().getWidth(),
        frameBuffer.getColorBufferTexture().getHeight(),
        false,
        true);
    spriteBatch.end();
  }
Beispiel #4
0
  /** Call this after scene. Renders the bloomed scene. */
  public void render() {
    if (capturing) {
      capturing = false;
      frameBuffer.end();
    }

    Gdx.gl.glDisable(GL20.GL_BLEND);
    Gdx.gl.glDisable(GL20.GL_DEPTH_TEST);
    Gdx.gl.glDepthMask(false);

    gaussianBlur();

    if (blending) {
      Gdx.gl.glEnable(GL20.GL_BLEND);
      Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    }

    pingPongTex1.bind(1);
    original.bind(0);
    bloomShader.begin();
    {
      fullScreenQuad.render(bloomShader, GL20.GL_TRIANGLE_FAN);
    }
    bloomShader.end();
  }
Beispiel #5
0
 @Override
 public void render() {
   Gdx.gl10.glPushMatrix();
   Gdx.gl10.glTranslatef(x, y, z);
   mesh.render(GL10.GL_TRIANGLES);
   Gdx.gl10.glPopMatrix();
 }
Beispiel #6
0
  private void gaussianBlur() {

    // cut bright areas of the picture and blit to smaller fbo

    original.bind(0);
    pingPongBuffer1.begin();
    {
      tresholdShader.begin();
      {
        // tresholdShader.setUniformi("u_texture0", 0);
        fullScreenQuad.render(tresholdShader, GL20.GL_TRIANGLE_FAN, 0, 4);
      }
      tresholdShader.end();
    }
    pingPongBuffer1.end();

    for (int i = 0; i < blurPasses; i++) {

      pingPongTex1.bind(0);

      // horizontal
      pingPongBuffer2.begin();
      {
        blurShader.begin();
        {
          blurShader.setUniformf("dir", 1f, 0f);
          fullScreenQuad.render(blurShader, GL20.GL_TRIANGLE_FAN, 0, 4);
        }
        blurShader.end();
      }
      pingPongBuffer2.end();

      pingPongTex2.bind(0);
      // vertical
      pingPongBuffer1.begin();
      {
        blurShader.begin();
        {
          blurShader.setUniformf("dir", 0f, 1f);

          fullScreenQuad.render(blurShader, GL20.GL_TRIANGLE_FAN, 0, 4);
        }
        blurShader.end();
      }
      pingPongBuffer1.end();
    }
  }
 public void render(Application app, boolean hit) {
   app.modelViewProjectionMatrix.set(app.cam.combined);
   app.modelViewProjectionMatrix.mul(modelMatrix);
   if (hit) app.shader.setUniformi("s_hit", 1);
   else app.shader.setUniformi("s_hit", 0);
   texture.bind(0);
   app.shader.setUniformi("s_texture", 0);
   app.shader.setUniformMatrix("u_mvpMatrix", app.modelViewProjectionMatrix);
   partMesh.render(app.shader, GL20.GL_TRIANGLES);
 }
Beispiel #8
0
  public void render() {
    Gdx.gl20.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);

    Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE0);
    texture.bind();
    shader.begin();
    shader.setUniformf("s_texture", 0);

    Gdx.gl20.glTexParameteri(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MIN_FILTER, GL20.GL_NEAREST);
    shader.setUniformf("u_offset", -0.6f);
    mesh.render(shader, GL20.GL_TRIANGLES);

    Gdx.gl20.glTexParameteri(
        GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MIN_FILTER, GL20.GL_LINEAR_MIPMAP_LINEAR);
    shader.setUniformf("u_offset", 0.6f);
    mesh.render(shader, GL20.GL_TRIANGLES);

    shader.end();
  }
  private void renderStaticShip(GL10 gl, Application app) {

    shipTexture.bind();
    gl.glPushMatrix();
    gl.glTranslatef(0, 0, 0);
    shipMesh.render(GL10.GL_TRIANGLES);
    gl.glPopMatrix();
    float noise = (float) Math.random() / 2;
    renderJet(gl, 2.3f, 1f + noise, 1.1f, -.5f, 1.8f, app);
    noise = (float) Math.random() / 2;
    renderJet(gl, 2.3f, 1f + noise, -1.1f, -.5f, 1.8f, app);
  }
  private void renderSky(GL10 gl) {

    gl.glDisable(GL10.GL_LIGHTING);
    skyTexture.bind();
    gl.glColor4f(1, 1, 1, 1);

    gl.glPushMatrix();
    gl.glTranslatef(0, 0, 0);
    gl.glScalef(100f, 100f, 100f);
    skyMesh.render(GL10.GL_TRIANGLES);
    gl.glPopMatrix();
    gl.glEnable(GL10.GL_LIGHTING);
  }
Beispiel #11
0
 public void end() {
   newFrame.end();
   FrameBuffer oldFrame = newFrame;
   newFrame = cleanFrame;
   oldFrame.getColorBufferTexture().bind();
   {
     Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
     mShaderProgram.begin();
     {
       mScreenMesh.render(mShaderProgram, GL20.GL_TRIANGLE_FAN, 0, 4);
     }
     mShaderProgram.end();
   }
 }
 /**
  * render ship jets
  *
  * @param basescale :- scale factor for jet size before applying thrust
  * @param length :- scale factor for jet length, typically thrust value + random noise
  * @param x The jet's x-coordinate.
  * @param y The jet's y-coordinate.
  * @param z The jet's z-coordinate.
  * @return The product, in a vector <#, #, #, 1>, representing the rotated point.
  */
 private void renderJet(
     GL10 gl, float baseScale, float length, float x, float y, float z, Application app) {
   jetTexture.bind();
   gl.glPushMatrix();
   // move away from origin
   gl.glTranslatef(x, y, z);
   // scale to size of earth
   gl.glScalef(baseScale, baseScale, baseScale * length);
   gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE);
   gl.glDisable(GL10.GL_LIGHTING);
   // gl.glRotatef((Splash.planetmove/10), .25f, .75f, .5f);
   jetMesh.render(GL10.GL_TRIANGLES);
   gl.glPopMatrix();
   gl.glEnable(GL10.GL_LIGHTING);
   // gl.glEnable(GL10.GL_DEPTH_TEST);
 }
Beispiel #13
0
  @Override
  public void render() {
    Gdx.graphics.getGL10().glClear(GL10.GL_COLOR_BUFFER_BIT);

    if (mode == 3) {
      Gdx.graphics.getGL10().glDisable(GL10.GL_BLEND);
      Gdx.graphics.getGL10().glEnable(GL10.GL_ALPHA_TEST);
    }

    if (mode == 2) {
      Gdx.graphics.getGL10().glEnable(GL10.GL_BLEND);
      Gdx.graphics.getGL10().glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    }

    if (mode >= 1) {
      Gdx.graphics.getGL10().glEnable(GL10.GL_TEXTURE_2D);
      texture.bind();
    }

    if (mode == 0) {
      Gdx.graphics.getGL10().glDisable(GL10.GL_BLEND);
      Gdx.graphics.getGL10().glDisable(GL10.GL_ALPHA_TEST);
      Gdx.graphics.getGL10().glDisable(GL10.GL_TEXTURE_2D);
    }

    Gdx.graphics.getGL10().glColor4f(1, 1, 1, 0.01f);

    for (int i = 0; i < numFills; i++) mesh.render(GL10.GL_TRIANGLES);

    mean += numFills;
    frames++;

    if (Gdx.graphics.getDeltaTime() < 1 / 60f) numFills++;

    if (TimeUtils.nanoTime() - lastOut >= 1000000000) {
      Gdx.app.log("FillrateTest", "fills: " + mean / frames + ", fps: " + frames + ", mode" + mode);
      mean = 0;
      frames = 0;
      lastOut = TimeUtils.nanoTime();
      if (Gdx.graphics.getFramesPerSecond() < 60) numFills--;
    }
  }
 @Override
 public void render() {
   Gdx.gl20.glViewport(
       0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight());
   Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
   shader.begin();
   shader.setUniform2fv(
       "u_resolution",
       new float[] {(float) Gdx.graphics.getWidth(), (float) Gdx.graphics.getHeight()},
       0,
       2);
   shader.setUniformf("u_time", TimeUtils.timeSinceMillis(startTime) / 1000f);
   shader.setUniform2fv(
       "u_mousePos",
       new float[] {Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY()},
       0,
       2);
   mesh.render(shader, GL20.GL_TRIANGLES);
   shader.end();
 }
  private void renderSun(GL10 gl, float radius, float x, float y, float z, Application app) {

    gl.glDisable(GL10.GL_LIGHTING);
    radius = radius * worldscale;
    sunTexture.bind();
    gl.glPushMatrix();
    // move away from origin
    gl.glTranslatef(x, y, z);
    // scale to size of earth
    gl.glScalef(radius, radius, radius);
    gl.glDisable(GL10.GL_CULL_FACE);

    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE);
    gl.glPushMatrix();
    gl.glDisable(GL10.GL_LIGHTING);
    // gl.glRotatef((Splash.planetmove/10), .25f, .75f, .5f);
    sunMesh.render(GL10.GL_TRIANGLES);
    gl.glPopMatrix();
    gl.glEnable(GL10.GL_LIGHTING);
    gl.glEnable(GL10.GL_CULL_FACE);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
  }
  public void flush() {
    // if we've already flushed
    if (idx == 0) return;
    // sends our vertex data to the mesh
    mesh.setVertices(verts);

    // no need for depth...
    Gdx.gl.glDepthMask(false);

    // enable blending, for alpha
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    // number of vertices we need to render
    int vertexCount = (idx / NUM_COMPONENTS);

    cam.update();

    // start the shader before setting any uniforms
    shader.begin();

    // update the projection matrix so our triangles are rendered in 2D
    shader.setUniformMatrix("u_projTrans", cam.combined);

    // render the mesh
    mesh.render(shader, RENDER_TYPE, 0, vertexCount);

    shader.end();

    // re-enable depth to reset states to their default
    Gdx.gl.glDepthMask(true);

    // reset index to zero
    idx = 0;

    // reset verts
    Arrays.fill(verts, 0);
  }
Beispiel #17
0
 public void render(GL10 gl) {
   gl.glPushMatrix();
   gl.glTranslatef(position.x, position.y, -50);
   mesh.render(GL10.GL_TRIANGLE_STRIP);
   gl.glPopMatrix();
 }
 public void render() {
   for (Mesh mesh : meshes) {
     mesh.render(GL10.GL_TRIANGLE_STRIP, 0, 4);
   }
 }
 /** Renders the quad with the specified shader program. */
 public void render(ShaderProgram program) {
   quad.render(program, GL20.GL_TRIANGLE_FAN, 0, 4);
 }
Beispiel #20
0
  /**
   * This method is responsible for OpenGL rendering mechanism. Adds lighting to the world. Checks
   * rigidBody map for proper collisionshapes (like SphereShape or BoxShape).
   */
  public void render(float delta) {
    float[] light_ambient = new float[] {1.5f, 1.5f, 1.5f, 1.5f};
    float[] light_diffuse = new float[] {1.0f, 1.0f, 1.0f, 1.0f};
    float[] light_specular = new float[] {1.0f, 1.0f, 1.0f, 1.0f};
    float[] light_position0 = new float[] {1.0f, 10.0f, 1.0f, 0.0f};
    light_position0[0] = position.x + 10;
    light_position0[1] = position.y;
    light_position0[2] = position.z;
    float x = 0.0f, z = 0.0f;

    GL10 gl = Gdx.graphics.getGL10();
    deltaTime = Gdx.graphics.getDeltaTime();

    Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    Gdx.graphics.getGL11().glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, light_ambient, 0);
    Gdx.graphics.getGL11().glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, light_diffuse, 0);
    Gdx.graphics.getGL11().glLightfv(GL10.GL_LIGHT0, GL10.GL_SPECULAR, light_specular, 0);
    Gdx.graphics.getGL11().glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, light_position0, 0);

    Gdx.graphics.getGL11().glEnable(GL10.GL_LIGHTING);
    Gdx.graphics.getGL11().glEnable(GL10.GL_LIGHT0);

    Gdx.gl.glEnable(GL10.GL_DEPTH_TEST);

    Gdx.gl.glEnable(GL10.GL_CULL_FACE);
    Gdx.gl.glEnable(GL10.GL_TEXTURE_2D);

    startTime = System.nanoTime();
    rigidBody = physics.doSimulation(deltaTime, 1);
    endTime = (System.nanoTime() - startTime) / 1000000000.0f;

    for (RigidBody body : rigidBody.values()) {

      if (body.geometry.shape.getType() == ShapeType.BOX_SHAPE_PROXYTYPE) {
        gl.glPushMatrix();

        body.motionState.resultSimulation.getOpenGLMatrix(glMat);
        gl.glMultMatrixf(glMat, 0);

        wallShapeZ = (BoxShape) body.geometry.shape;

        wood.bind();
        gl.glRotatef(270, 1, 0, 0);
        gl.glScalef(7, 7, 7);
        wall.render(GL10.GL_TRIANGLES);
        gl.glPopMatrix();
      }

      if (body.geometry.shape.getType() == ShapeType.STATIC_PLANE_PROXYTYPE) {
        gl.glPushMatrix();

        body.motionState.resultSimulation.getOpenGLMatrix(glMat);
        gl.glMultMatrixf(glMat, 0);

        groundShape = (StaticPlaneShape) body.geometry.shape;

        stone.bind();
        gl.glRotatef(270, 1, 0, 0);
        gl.glScalef(6f, 6f, 6f);
        plane.render(GL10.GL_TRIANGLES);
        gl.glPopMatrix();
      }

      if (body.geometry.shape.getType() == ShapeType.SPHERE_SHAPE_PROXYTYPE) {

        gl.glPushMatrix();

        sphereMovement(body);

        body.motionState.resultSimulation.getOpenGLMatrix(glMat);
        gl.glMultMatrixf(glMat, 0);

        x = body.motionState.resultSimulation.originPoint.x;
        z = body.motionState.resultSimulation.originPoint.z;

        if ((x >= 19.0 && x <= 26.5) && (z >= 8.4 && z <= 8.6)) {
          Gdx.app.log("Zwyciestwo", "lolol");
        }

        if (indexior == 0) black.bind();
        else if (indexior == 1) green.bind();
        else if (indexior == 2) pink.bind();
        else if (indexior == 3) steel.bind();
        else if (indexior == 4) maja.bind();

        sphere.render(GL10.GL_TRIANGLES);
        gl.glPopMatrix();
        cameraSetup(body);
      }
    }

    if (Gdx.input.justTouched()) {
      FileHandle fh = Gdx.files.local("ala.txt");
      fh.writeString(
          String.valueOf(x) + " " + String.valueOf(z) + " " + String.valueOf(indexior), false);
      game.setScreen(new MenuScreen(game));
    }

    gl.glPushMatrix();
    gl.glTranslatef(22.0f, -10.0f, 8.5f);
    gl.glScalef(1.0f, 1.0f, 1.0f);
    gl.glRotatef(270, 1, 0, 0);
    aim.bind();
    target.render(GL10.GL_TRIANGLES);
    gl.glPopMatrix();

    gl.glDisable(GL10.GL_CULL_FACE);
    gl.glDisable(GL10.GL_DEPTH_TEST);
  }