/** Draws a red box in the corner. */
 private void drawBox() {
   GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
   GLES20.glScissor(0, 0, 100, 100);
   GLES20.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
   GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
   GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
 }
Beispiel #2
0
  @Override
  public void onDrawFrame(GL10 unused) {
    GLES20.glClearColor(backgroundColorRed, backgroundColorGreen, backgroundColorBlue, 1.0f);

    if (resetFramebuffers) {
      resetFramebuffers = false;
      if (!useOneFramebuffer) {
        frameBuffers[1 - activeTargettexture].bind();
        GLES20.glViewport(0, 0, frameBufferWidth, frameBufferHeight);
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
      }
    }

    frameBuffers[activeTargettexture].bind();
    GLES20.glViewport(0, 0, frameBufferWidth, frameBufferHeight);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    renderBlurTexture(useOneFramebuffer ? (activeTargettexture) : (1 - activeTargettexture));
    renderLines();

    frameBuffers[activeTargettexture].unbind();

    GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    renderBlurTexture(activeTargettexture);

    if (!useOneFramebuffer) {
      activeTargettexture = 1 - activeTargettexture;
    }
  }
  /*
   * Draw function - called for every frame
   */
  public void onDrawFrame(GL10 glUnused) {
    // Ignore the passed-in GL10 interface, and use the GLES20
    // class's static methods instead.
    GLES20.glClearColor(.0f, .0f, .0f, 1.0f);
    GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);

    GLES20.glUseProgram(0);
    // the current shader
    Shader shader = _shaders[this._currentShader]; // PROBLEM!
    int program = shader.get_program();

    // Start using the shader
    GLES20.glUseProgram(program);
    checkGlError("glUseProgram");

    setLight(program);
    drawCar(program, new float[] {0.0f, 5.0f, 20.0f});
    drawCar2(program, new float[] {-10.0f, 5.0f, 10.0f});
    drawCar2(program, new float[] {-5.0f, 5.0f, -10.0f});
    drawCar2(program, new float[] {10.0f, 5.0f, 0.0f});
    drawCar2(program, new float[] {50.0f, 5.0f, 15.0f});
    drawRoad(program);

    // eye position
    GLES20.glUniform3fv(
        GLES20.glGetUniformLocation(program, "eyePos") /*shader.eyeHandle*/, 1, eyePos, 0);
  }
  @Override
  public void onDrawFrame(GL10 unused) {

    GLES20.glClearColor(0f, 0f, 0f, 0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    if (mShaderCompilerSupport[0] == false) {
      return;
    }

    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);

    float angle = (SystemClock.uptimeMillis() % 5000) / 5000f * 360;
    Matrix.setRotateM(mMatrixModel, 0, angle, 1, 2, 0);

    Matrix.multiplyMM(mMatrixModelViewProjection, 0, mMatrixView, 0, mMatrixModel, 0);
    Matrix.multiplyMM(
        mMatrixModelViewProjection, 0, mMatrixProjection, 0, mMatrixModelViewProjection, 0);

    mShaderSpline.useProgram();

    GLES20.glUniformMatrix4fv(
        mShaderSpline.getHandle("uModelViewProjectionM"), 1, false, mMatrixModelViewProjection, 0);

    GLES20.glVertexAttribPointer(
        mShaderSpline.getHandle("aPosition"), 2, GLES20.GL_FLOAT, false, 0, mBufferSpline);
    GLES20.glEnableVertexAttribArray(mShaderSpline.getHandle("aPosition"));

    for (float[] ctrl : mSplines) {
      GLES20.glUniform3fv(mShaderSpline.getHandle("uCtrl"), 4, ctrl, 0);
      GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, COUNT_VERTICES);
    }
  }
  private void setFBO(GL10 glUnused, boolean useBuffer) {
    if (useBuffer) {
      // Bind the framebuffer
      GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fb[0]);

      // specify texture as color attachment
      GLES20.glFramebufferTexture2D(
          GLES20.GL_FRAMEBUFFER,
          GLES20.GL_COLOR_ATTACHMENT0,
          GLES20.GL_TEXTURE_2D,
          renderTex[0],
          0);
      // attach render buffer as depth buffer
      GLES20.glFramebufferRenderbuffer(
          GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, depthRb[0]);

      // check status
      int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
      if (status != GLES20.GL_FRAMEBUFFER_COMPLETE)
        Log.e("Selection", "Frame buffer couldn't attach!");

      GLES20.glClearColor(.0f, .0f, .0f, 1.0f);
      GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
    } else {
      GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    }
  }
  public void onSurfaceCreated(GL10 unused, EGLConfig config) {

    // Set the background frame color
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glDisable(GLES20.GL_DITHER);
    GLES20.glDisable(GL10.GL_LIGHTING);
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
    GLES20.glEnable(GLES20.GL_TEXTURE_2D);
    GLES20.glEnable(GL10.GL_BLEND);
    GLES20.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    inirBuffers();

    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
    int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);

    mProgram = GLES20.glCreateProgram(); // create empty OpenGL Program
    GLES20.glAttachShader(mProgram, vertexShader); // add the vertex shader to program
    GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program
    GLES20.glLinkProgram(mProgram); // creates OpenGL program executables

    // get handle to the vertex shader's vPosition member

    maPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
    maTexCoordsHandle = GLES20.glGetAttribLocation(mProgram, "aTexCoords");
    mSampleHandle = GLES20.glGetUniformLocation(mProgram, "u_Texture");
    //        mSampleHandle2 = GLES20.glGetUniformLocation(mProgram, "u_Texture2");
    mOpacityHandle = GLES20.glGetUniformLocation(mProgram, "u_Opacity");
  }
  @Override
  public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    int vertexShaderHandle = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
    GLES20.glShaderSource(vertexShaderHandle, loadShader(R.raw.vertex_shader));
    GLES20.glCompileShader(vertexShaderHandle);
    int fragmentShaderHandle = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);
    GLES20.glShaderSource(fragmentShaderHandle, loadShader(R.raw.fragment_shader));
    GLES20.glCompileShader(fragmentShaderHandle);
    int programHandle = GLES20.glCreateProgram();
    GLES20.glAttachShader(programHandle, vertexShaderHandle);
    GLES20.glAttachShader(programHandle, fragmentShaderHandle);
    GLES20.glLinkProgram(programHandle);
    GLES20.glUseProgram(programHandle);
    Object3D.init(programHandle);
    mLightPosHandle = GLES20.glGetUniformLocation(programHandle, "uLightPos");

    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    GLES20.glEnable(GLES20.GL_CULL_FACE);
    GLES20.glCullFace(GLES20.GL_BACK);

    //		GLES20.glEnable(GLES20.GL_BLEND);
    //		GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);

    mPrism.init();
    mCylinder.init();
    mSphere.init();
  }
  @Override
  public void onSurfaceCreated(GL10 unused, EGLConfig config) {
    int program = GLES20.glCreateProgram();
    addShaderTo(GLES20.GL_VERTEX_SHADER, VERTEX_SHADER_STRING, program);
    addShaderTo(GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER_STRING, program);

    GLES20.glLinkProgram(program);
    int[] result = new int[] {GLES20.GL_FALSE};
    result[0] = GLES20.GL_FALSE;
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, result, 0);
    abortUnless(result[0] == GLES20.GL_TRUE, GLES20.glGetProgramInfoLog(program));
    GLES20.glUseProgram(program);

    GLES20.glUniform1i(GLES20.glGetUniformLocation(program, "y_tex"), 0);
    GLES20.glUniform1i(GLES20.glGetUniformLocation(program, "u_tex"), 1);
    GLES20.glUniform1i(GLES20.glGetUniformLocation(program, "v_tex"), 2);

    // Actually set in drawRectangle(), but queried only once here.
    posLocation = GLES20.glGetAttribLocation(program, "in_pos");

    int tcLocation = GLES20.glGetAttribLocation(program, "in_tc");
    GLES20.glEnableVertexAttribArray(tcLocation);
    GLES20.glVertexAttribPointer(tcLocation, 2, GLES20.GL_FLOAT, false, 0, textureCoords);

    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    checkNoGLES2Error();
  }
  @SuppressLint("NewApi")
  @Override
  public void onSurfaceCreated(GL10 unused, EGLConfig config) {
    Logging.d(TAG, "VideoRendererGui.onSurfaceCreated");
    // Store render EGL context.
    if (CURRENT_SDK_VERSION >= EGL14_SDK_VERSION) {
      synchronized (VideoRendererGui.class) {
        eglContext = EGL14.eglGetCurrentContext();
        Logging.d(TAG, "VideoRendererGui EGL Context: " + eglContext);
      }
    }

    synchronized (yuvImageRenderers) {
      // Create drawer for YUV/OES frames.
      drawer = new GlRectDrawer();
      // Create textures for all images.
      for (YuvImageRenderer yuvImageRenderer : yuvImageRenderers) {
        yuvImageRenderer.createTextures();
      }
      onSurfaceCreatedCalled = true;
    }
    GlUtil.checkNoGLES2Error("onSurfaceCreated done");
    GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
    GLES20.glClearColor(0.15f, 0.15f, 0.15f, 1.0f);

    // Fire EGL context ready event.
    synchronized (VideoRendererGui.class) {
      if (eglContextReady != null) {
        eglContextReady.run();
      }
    }
  }
Beispiel #10
0
  /**
   * Creates the buffers we use to store information about the 3D world. OpenGL doesn't use Java
   * arrays, but rather needs data in a format it can understand. Hence we use ByteBuffers.
   *
   * @param config The EGL configuration used when creating the surface.
   */
  @Override
  public void onSurfaceCreated(EGLConfig config) {
    Log.i(TAG, "In onSurfaceCreated");
    GLES20.glClearColor(0.1f, 0.1f, 0.1f, 0.5f); // Dark background so camera stuff show up.

    ByteBuffer bb = ByteBuffer.allocateDirect(squareVertices.length * 4);
    bb.order(ByteOrder.nativeOrder());
    vertexBuffer = bb.asFloatBuffer();
    vertexBuffer.put(squareVertices);
    vertexBuffer.position(0);

    ByteBuffer dlb = ByteBuffer.allocateDirect(drawOrder.length * 2);
    dlb.order(ByteOrder.nativeOrder());
    drawListBuffer = dlb.asShortBuffer();
    drawListBuffer.put(drawOrder);
    drawListBuffer.position(0);

    ByteBuffer bb2 = ByteBuffer.allocateDirect(textureVertices.length * 4);
    bb2.order(ByteOrder.nativeOrder());
    textureVerticesBuffer = bb2.asFloatBuffer();
    textureVerticesBuffer.put(textureVertices);
    textureVerticesBuffer.position(0);

    int vertexShader = loadGLShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
    int fragmentShader = loadGLShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);

    mProgram = GLES20.glCreateProgram(); // create empty OpenGL ES Program
    GLES20.glAttachShader(mProgram, vertexShader); // add the vertex shader to program
    GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program
    GLES20.glLinkProgram(mProgram);

    // Create a texture and start mirroring the camera on the texture:
    texture = createTexture();
    startCamera(texture);
  }
  @Override
  public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    space = new Space(new Point(0f, 0f, 0f));
    space2 = new Space(new Point(0f, 2f, 0f));
    spaceShip = new Spaceship();

    spaceshipVector = new Vector(0, 0, 0);
    bulletVector = new Vector(0, 0.08f, 0);
    spaceDownVector = new Vector(0f, -0.01f, 0f);

    textureProgram = new TextureShaderProgram(context);
    colorProgram = new ColorShaderProgram(context);

    asteroidTexture = TextureHelper.loadTexture(context, R.drawable.asteroid_text);
    spaceshipTexture = TextureHelper.loadTexture(context, R.drawable.space);
    spaceTexture = TextureHelper.loadTexture(context, R.drawable.stars_background);

    spaceShipPosition = new Point(0f, -0.8f, 0f);

    for (int i = 0; i < 10; i++) {
      asteroids[i] = new Asteroid(3);
      if (i < 5) bullets[i] = new Bullet();
    }
  }
    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
      // 设置屏幕背景色RGBA
      GLES20.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
      // 打开深度检测
      GLES20.glEnable(GLES20.GL_DEPTH_TEST);
      MatrixState.setInitStack();

      treeTextureId = initTexture(R.drawable.tree);

      desert =
          new Desert(
              MySurfaceView.this,
              new float[] {
                0, 0, 0, 6, 6, 6,
                6, 6, 6, 0, 0, 0
              },
              30,
              20);
      desertId = initTexture(R.drawable.desert);

      group = new TreeGroup(MySurfaceView.this, treeTextureId);

      Collections.sort(mRender.group.trees);
    }
  public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    // TODO Auto-generated method stub
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    // mTriangle = new Triangle();
    mSquare = new Square();
    // personaje = new ZxCPersonaje();
  }
Beispiel #14
0
 @Override
 public void onSurfaceCreated(GL10 gl, EGLConfig config) {
   // TODO Auto-generated method stub
   // Set the background frame color
   GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
   mTriangle = new Triangle();
   mSquare = new Square();
 }
  @Override
  public void onDrawFrame(GL10 unused) {
    GLES20.glClearColor(0f, 0f, 0f, 1f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    if (mShaderCompilerSupport[0] == false) {
      return;
    }

    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);

    long time = SystemClock.uptimeMillis();

    if (mLastRenderTime == -1) {
      for (Star star : mStarArray) {
        star.randomize();
        star.mPosition[2] = (float) (Math.random() * 4 - 2);
      }
      mLastRenderTime = time;
    }

    float t = (time - mLastRenderTime) / 1000f;
    mLastRenderTime = time;

    mShaderStar.useProgram();

    GLES20.glUniformMatrix4fv(
        mShaderStar.getHandle("uModelViewProjectionM"), 1, false, mMatrixModelViewProjection, 0);
    GLES20.glUniform1f(mShaderStar.getHandle("uSize"), .01f);

    GLES20.glVertexAttribPointer(
        mShaderStar.getHandle("aPosition"), 2, GLES20.GL_BYTE, false, 0, mBufferVertices);
    GLES20.glEnableVertexAttribArray(mShaderStar.getHandle("aPosition"));

    for (Star star : mStarArray) {
      star.mPosition[2] += star.mSpeed * t;
      if (star.mPosition[2] > 2) {
        star.randomize();
      }
    }

    Arrays.sort(
        mStarArray,
        new Comparator<Star>() {
          @Override
          public int compare(Star arg0, Star arg1) {
            return arg0.mPosition[2] < arg1.mPosition[2] ? -1 : 1;
          }
        });

    for (Star star : mStarArray) {
      GLES20.glUniform3fv(mShaderStar.getHandle("uPosition"), 1, star.mPosition, 0);
      GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    }

    GLES20.glDisable(GLES20.GL_BLEND);
  }
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
      // 设置屏幕背景色RGBA
      GLES20.glClearColor(0.9f, 0.9f, 0.9f, 1.0f);
      // 启用深度测试
      GLES20.glEnable(GLES20.GL_DEPTH_TEST);
      // 设置为打开背面剪裁
      GLES20.glEnable(GLES20.GL_CULL_FACE);
      // 初始化变换矩阵
      MatrixState.setInitStack();

      float[] colorValue = {1, 0, 0, 1}; // 创建颜色数组
      ball = new Ball(MySurfaceView.this, Constant.BALL_R, colorValue); // 创建球对象
      colorValue = new float[] {1, 1, 0, 1};
      stick =
          new Stick(
              MySurfaceView.this,
              Constant.LENGTH,
              Constant.R,
              Constant.ANGLE_SPAN,
              colorValue); // 创建圆管对象

      double[] initPoint = Utils.getFirstPoint(Constant.LENGTH); // 得到第一个五边形左下点的坐标
      double[] initVector = {1, 0, 0, 1}; // 初始化方向向量
      double[] zPivot = {0, 0, 1, 1}; // 以z轴为旋转轴
      int[] vertices = {0, 1, 2, 3, 4}; // 球的索引
      int[] borders = {0, 1, 2, 3, 4}; // 圆管的索引
      first =
          new RegularPolygon(
              MySurfaceView.this,
              5,
              72,
              Constant.LENGTH,
              initPoint,
              initVector,
              zPivot,
              vertices,
              borders); // 1

      vertices = new int[] {2, 3, 4}; // 球的索引
      borders = new int[] {1, 2, 3, 4}; // 圆管的索引
      RegularPolygon rp2 = first.buildChild(6, -60, 1, vertices, borders); // 2

      vertices = new int[] {2, 3, 4, 5};
      borders = new int[] {1, 2, 3, 4, 5};
      RegularPolygon rp4 = rp2.buildChild(6, 60, 3, vertices, borders); // 4

      vertices = new int[] {};
      borders = new int[] {1, 5};
      rp4.buildChild(6, -60, 2, vertices, borders); // 5

      vertices = new int[] {2};
      borders = new int[] {1, 2};
      RegularPolygon rp6 = rp4.buildChild(5, -72, 3, vertices, borders); // 6

      vertices = new int[] {3, 4, 5};
      borders = new int[] {2, 3, 4, 5};
      rp6.buildChild(6, 60, 2, vertices, borders); // 7
    }
  @Override
  public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    heightmapProgram = new HeightmapShaderProgram(context);
    heightmap =
        new Heightmap(
            ((BitmapDrawable) context.getResources().getDrawable(R.drawable.heightmap))
                .getBitmap());

    skyboxProgram = new SkyboxShaderProgram(context);
    skybox = new Skybox();

    particleProgram = new ParticleShaderProgram(context);
    particleSystem = new ParticleSystem(10000);
    globalStartTime = System.nanoTime();

    final Vector particleDirection = new Vector(0f, 0.5f, 0f);
    final float angleVarianceInDegrees = 5f;
    final float speedVariance = 1f;

    redParticleShooter =
        new ParticleShooter(
            new Point(-1f, 0f, 0f),
            particleDirection,
            Color.rgb(255, 50, 5),
            angleVarianceInDegrees,
            speedVariance);

    greenParticleShooter =
        new ParticleShooter(
            new Point(0f, 0f, 0f),
            particleDirection,
            Color.rgb(25, 255, 25),
            angleVarianceInDegrees,
            speedVariance);

    blueParticleShooter =
        new ParticleShooter(
            new Point(1f, 0f, 0f),
            particleDirection,
            Color.rgb(5, 50, 255),
            angleVarianceInDegrees,
            speedVariance);

    particleTexture = TextureHelper.loadTexture(context, R.drawable.particle_texture);

    skyboxTexture =
        TextureHelper.loadCubeMap(
            context,
            new int[] {
              R.drawable.left, R.drawable.right,
              R.drawable.bottom, R.drawable.top,
              R.drawable.front, R.drawable.back
            });
  }
 @Override
 public void onSurfaceCreated(GL10 gl, EGLConfig config) {
   System.out.println("onSurfaceCreated");
   GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
   for (int i = 0; i < ha.length; i++) {
     ha[i] = new SixPointerStar(MySurfaceView.this, 0.2f, 0.5f, -0.3f * i);
   }
   GLES20.glEnable(GLES20.GL_DEPTH_TEST);
 }
  @Override
  public void onSurfaceCreated(GL10 unused, EGLConfig config) {
    GLES20.glClearColor(0.0f, 0.0f, 0f, 1.0f);
    // GLES20.glShadeModel(GL11.GL_SMOOTH);
    GLES20.glClearDepthf(1.0f);
    GLES20.glDisable(GL11.GL_DEPTH_TEST);
    // gl.glDepthFunc(GL11.GL_LEQUAL);
    // GLES20.glHint(GLES20.GL_PERSPECTIVE_CORRECTION_HINT,
    //        GLES20.GL_NICEST);

    GLES20.glDisable(GL11.GL_CULL_FACE);

    // ByteBuffer temp = ByteBuffer.allocateDirect(16);
    // temp.order(ByteOrder.nativeOrder());
    /*
    gl.glLightfv(GL11.GL_LIGHT1, GL11.GL_AMBIENT, (FloatBuffer) temp
                    .asFloatBuffer().put(lightAmbient).flip()); // Setup The Ambient
                                                                                                            // Light
    gl.glLightfv(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, (FloatBuffer) temp
                    .asFloatBuffer().put(lightDiffuse).flip()); // Setup The Diffuse
                                                                                                            // Light
    gl.glLightfv(GL11.GL_LIGHT1, GL11.GL_POSITION, (FloatBuffer) temp
                    .asFloatBuffer().put(lightPosition).flip()); // Position The
                                                                                                                    // Light
    gl.glEnable(GL11.GL_LIGHT1); // Enable Light One
    */

    // Display.setVSyncEnabled(true);

    Log.d("openglrenderer", "createSurface : initialized = " + initialized);
    if (!initialized) { // Doesn't work at each attempt

      client.getEngineZildo().initializeClient(false);
      client.setMenuListener(new AndroidMenuListener(touchListener));
      touchListener.init();
      // Holes
      client.setOpenGLGestion(Zildo.pdPlugin.openGLGestion);
      Zildo.pdPlugin.openGLGestion.setClientEngineZildo(client.getEngineZildo());

      // gl.glClearColor(0.0f, 0.0f, 0f, 0.0f);

      Log.d("renderer", "init finished - start main menu");

      // unused.glDisable(GL11.GL_LIGHTING);

      initialized = true;
    } else {
      // Recreate context by reloading all textures and shaders
      Log.d("openglrenderer", "recreating context");
      SpriteDisplay spriteDisplay = ClientEngineZildo.spriteDisplay;
      TileEngine tileEngine = ClientEngineZildo.tileEngine;
      tileEngine.loadTextures();
      Zildo.pdPlugin.initFilters(true);
      ClientEngineZildo.spriteEngine.init(spriteDisplay);
      AndroidPixelShaders.shaders.load();
    }
  }
 public void onSurfaceCreated(GL10 gl, EGLConfig config) {
   // 设置屏幕背景色RGBA
   GLES20.glClearColor(0, 0, 0, 1.0f);
   // 创建点或线对象
   PointsOrLines = new PointsOrLines(MySurfaceView.this);
   // 打开深度检测
   GLES20.glEnable(GLES20.GL_DEPTH_TEST);
   // 打开背面剪裁
   GLES20.glEnable(GLES20.GL_CULL_FACE);
 }
 public void onSurfaceCreated(GL10 gl, EGLConfig config) {
   // 设置屏幕背景色RGBA
   GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
   // 创建立方体对象
   cube = new Cube(MySurfaceView.this);
   // 打开深度检测
   GLES20.glEnable(GLES20.GL_DEPTH_TEST);
   // 打开背面剪裁
   GLES20.glEnable(GLES20.GL_CULL_FACE);
 }
    public void onDrawFrame(GL10 glUnused) {

      synchronized (this) {
        if (updateSurface) {
          mSurface.updateTexImage();
          mSurface.getTransformMatrix(mSTMatrix);
          updateSurface = false;
        } else {
          return;
        }
      }

      GLES20.glClearColor(255.0f, 255.0f, 255.0f, 1.0f);
      GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);

      GLES20.glUseProgram(mProgram);
      checkGlError("glUseProgram");

      GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
      GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureID);

      mTriangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
      GLES20.glVertexAttribPointer(
          maPositionHandle,
          3,
          GLES20.GL_FLOAT,
          false,
          TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
          mTriangleVertices);
      checkGlError("glVertexAttribPointer maPosition");
      GLES20.glEnableVertexAttribArray(maPositionHandle);
      checkGlError("glEnableVertexAttribArray maPositionHandle");

      mTextureVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
      GLES20.glVertexAttribPointer(
          maTextureHandle,
          2,
          GLES20.GL_FLOAT,
          false,
          TEXTURE_VERTICES_DATA_STRIDE_BYTES,
          mTextureVertices);

      checkGlError("glVertexAttribPointer maTextureHandle");
      GLES20.glEnableVertexAttribArray(maTextureHandle);
      checkGlError("glEnableVertexAttribArray maTextureHandle");

      Matrix.setIdentityM(mMVPMatrix, 0);

      GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
      GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);

      GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
      checkGlError("glDrawArrays");
      GLES20.glFinish();
    }
  @Override
  public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
    // set the background clear color to black.
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    // use culling to remove back faces.
    GLES20.glEnable(GLES20.GL_CULL_FACE);

    // enable depth testing
    // GLES20.glEnable(GLES20.GL_DEPTH_TEST);
  }
  /**
   * Generates a frame of data using GL commands.
   *
   * <p>We have an 8-frame animation sequence that wraps around. It looks like this:
   *
   * <pre>
   *   0 1 2 3
   *   7 6 5 4
   * </pre>
   *
   * We draw one of the eight rectangles and leave the rest set to the zero-fill color.
   */
  private void generateSurfaceFrame(int frameIndex) {
    frameIndex %= 8;

    int startX, startY;
    if (frameIndex < 4) {
      // (0,0) is bottom-left in GL
      startX = frameIndex * (mWidth / 4);
      startY = mHeight / 2;
    } else {
      startX = (7 - frameIndex) * (mWidth / 4);
      startY = 0;
    }

    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
    GLES20.glClearColor(TEST_R0 / 255.0f, TEST_G0 / 255.0f, TEST_B0 / 255.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glScissor(startX, startY, mWidth / 4, mHeight / 2);
    GLES20.glClearColor(TEST_R1 / 255.0f, TEST_G1 / 255.0f, TEST_B1 / 255.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
  }
Beispiel #25
0
 @Override
 public void onDraw(final GLState pGLState, final Camera pCamera) {
   if (this.mColorEnabled) {
     GLES20.glClearColor(
         this.mColor.getRed(),
         this.mColor.getGreen(),
         this.mColor.getBlue(),
         this.mColor.getAlpha());
     GLES20.glClear(
         GLES20.GL_COLOR_BUFFER_BIT); // TODO Does this cause problems when multisampling?
   }
 }
  public void Render() {
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    particleSource0.AddField(magnet0);
    particleSource0.AddField(magnet1);
    particleSource1.AddField(magnet0);
    particleSource1.AddField(magnet1);

    boolean s0 = particleSource0.AddDetector(detector);
    boolean s1 = particleSource1.AddDetector(detector);
    int maxScore = 500;
    int incValue = 20;
    int decValue = 3;
    int winThreshold = maxScore - 20;
    if (s0) complete0 += incValue;
    else complete0 -= decValue;
    if (s1) complete1 += incValue;
    else complete1 -= decValue;
    if (complete0 < 0) complete0 = 0;
    if (complete1 < 0) complete1 = 0;
    if (complete0 > maxScore) complete0 = maxScore;
    if (complete1 > maxScore) complete1 = maxScore;
    if (complete0 >= winThreshold && complete1 >= winThreshold) {
      SharedPreferences userPref = context.getSharedPreferences("userPref", 0);
      int saveState = userPref.getInt("saveState", 20);
      if (saveState < windowId + 1) {
        SharedPreferences.Editor editorPref = userPref.edit();
        editorPref.putInt("saveState", windowId + 1);
        editorPref.commit();
      }
      manager.Activate(windowId + 1);
    }

    magnet0.AddSourceCollision(particleSource0);
    magnet0.AddSourceCollision(particleSource1);
    magnet1.AddSourceCollision(particleSource0);
    magnet1.AddSourceCollision(particleSource1);

    magnet0.AddMagnetCollision(magnet1);
    magnet1.AddMagnetCollision(magnet0);

    grid.Render();

    particleSource0.RenderSourceSprite();
    particleSource1.RenderSourceSprite();
    magnet0.Render();
    magnet1.Render();
    particleSource0.Render();
    particleSource1.Render();
    detector.Render();
  }
  @Override
  public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {

    // Set the background clear color to sky blue
    GLES20.glClearColor(135.0f / 255.0f, 206.0f / 255.0f, 255.0f / 255f, 1.0f);
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    // GLES20.glEnable(GLES20.GL_CULL_FACE);
    GLES20.glEnable(GLES20.GL_TEXTURE_2D);

    // Position the eye behind the origin
    this.mCamera.eye = new Vector3d(0.0f, 0.0f, 0.0f);

    // We are looking toward the distance
    this.mCamera.look = new Vector3d(0f, 0f, 0f);

    // Set our up vector. This is where our head would be pointing were we holding the camera
    this.mCamera.up = new Vector3d(0.0f, 0.0f, 1.0f);

    // Set the view matrix. This matrix can be said to represent the camera position.
    // NOTE: In OpenGL 1, a ModelView matrix is used, which is a combination of a model and
    // view matrix. In OpenGL 2, we can keep track of these matrices separately if we choose.
    Matrix.setLookAtM(
        this.mViewMatrix,
        0,
        this.mCamera.eye.x,
        this.mCamera.eye.y,
        this.mCamera.eye.z,
        this.mCamera.look.x,
        this.mCamera.look.y,
        this.mCamera.look.z,
        this.mCamera.up.x,
        this.mCamera.up.y,
        this.mCamera.up.z);

    Matrix.setIdentityM(mModelMatrix, 0);
    final String vertexShader = getVertexShader();
    final String fragmentShader = getFragmentShader();

    final int vertexShaderHandle = compileShader(GLES20.GL_VERTEX_SHADER, vertexShader);
    final int fragmentShaderHandle = compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentShader);

    mPerVertexProgramHandle =
        createAndLinkProgram(
            vertexShaderHandle,
            fragmentShaderHandle,
            new String[] {"a_Position", "a_Color", "a_Normal", "a_TexCoordinate"});

    addTexture(R.drawable.grass_texture_1);
    addTexture(R.drawable.azure_waters);
    addTexture(R.drawable.wood_texture_1);
    addTexture(R.drawable.sky_texture_1);
  }
 @Override
 public void onSurfaceCreated(GL10 gl, EGLConfig config) {
   // 设置屏幕背景色RGBA
   GLES20.glClearColor(1.f, 1.0f, 1.0f, 1.0f);
   // 打开深度检测
   GLES20.glEnable(GLES20.GL_DEPTH_TEST);
   // 打开背面剪裁
   GLES20.glEnable(GLES20.GL_CULL_FACE);
   // 初始化变换矩阵
   MatrixState.setInitStack();
   pmBase = new TextureRect(MySurfaceView.this, 15, 15, 1, 1);
   pmJJ = new TextureRectJJ(MySurfaceView.this, 15, 15, 1, 1);
   pmTexId = initTexture(R.drawable.pm);
 }
  @Override
  public void onDrawFrame(GL10 gl) {
    // Set GL_MODELVIEW transformation mode
    // gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity(); // reset the matrix to its default state

    // When using GL_MODELVIEW, you must set the camera view
    // GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
    GLES20.glClearColor(0.8f, 0.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    triangle.draw();
    sprite.draw(gl);
  }
Beispiel #30
0
  /** Generates a frame of data using GL commands. */
  private void generateFrame(int frameIndex) {
    final int BOX_SIZE = 80;
    frameIndex %= 240;
    int xpos, ypos;

    int absIndex = Math.abs(frameIndex - 120);
    xpos = absIndex * WIDTH / 120;
    ypos = absIndex * HEIGHT / 120;

    float lumaf = absIndex / 120.0f;

    GLES20.glClearColor(lumaf, lumaf, lumaf, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glScissor(BOX_SIZE / 2, ypos, BOX_SIZE, BOX_SIZE);
    GLES20.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glScissor(xpos, BOX_SIZE / 2, BOX_SIZE, BOX_SIZE);
    GLES20.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
  }