コード例 #1
0
    public void draw(float[] viewProjMatrix) {
        glUseProgram(mProgram);

        multiplyMM(mMVPMatrix, 0, viewProjMatrix, 0, mModelMatrix, 0);
        int handle = glGetUniformLocation(mProgram, Constants.U_MVP_MATRIX);
        glUniformMatrix4fv(handle, 1, false, mMVPMatrix, 0);

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, mTextureA);
        handle = glGetUniformLocation(mProgram, Constants.U_TEX_UNIT_0);
        glUniform1i(handle, 0);

        glActiveTexture(GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D, mTextureB);
        handle = glGetUniformLocation(mProgram, Constants.U_TEX_UNIT_1);
        glUniform1i(handle, 1);

        handle = glGetUniformLocation(mProgram, Constants.U_MIX_FACTOR);
        glUniform1f(handle, calcMixFactor());

        handle = glGetUniformLocation(mProgram, Constants.U_BACK_COLOR);
        glUniform3fv(handle, 1, mBackColor, 0);

        mMesh.draw(mProgram);
    }
コード例 #2
0
  @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();
  }
コード例 #3
0
    @Override
    public void onDrawFrame(GL10 glUnused) {
      GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
      GLES20.glUseProgram(mProgram);
      checkGlError("glUseProgram");

      if (mBuffer != null) {
        synchronized (this) {
          GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
          GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureY[0]);
          GLES20.glTexImage2D(
              GLES20.GL_TEXTURE_2D,
              0,
              GLES20.GL_LUMINANCE,
              mBufferWidthY,
              mBufferHeightY,
              0,
              GLES20.GL_LUMINANCE,
              GLES20.GL_UNSIGNED_BYTE,
              mBuffer.position(mBufferPositionY));
          GLES20.glUniform1i(muSamplerYHandle, 0);

          GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
          GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureU[0]);
          GLES20.glTexImage2D(
              GLES20.GL_TEXTURE_2D,
              0,
              GLES20.GL_LUMINANCE,
              mBufferWidthUV,
              mBufferHeightUV,
              0,
              GLES20.GL_LUMINANCE,
              GLES20.GL_UNSIGNED_BYTE,
              mBuffer.position(mBufferPositionU));
          GLES20.glUniform1i(muSamplerUHandle, 1);

          GLES20.glActiveTexture(GLES20.GL_TEXTURE2);
          GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureV[0]);
          GLES20.glTexImage2D(
              GLES20.GL_TEXTURE_2D,
              0,
              GLES20.GL_LUMINANCE,
              mBufferWidthUV,
              mBufferHeightUV,
              0,
              GLES20.GL_LUMINANCE,
              GLES20.GL_UNSIGNED_BYTE,
              mBuffer.position(mBufferPositionV));
          GLES20.glUniform1i(muSamplerVHandle, 2);
        }
      }

      GLES20.glDrawElements(
          GLES20.GL_TRIANGLES, INDICES_DATA.length, GLES20.GL_UNSIGNED_SHORT, mIndices);
    }
コード例 #4
0
ファイル: ObjectRenderer.java プロジェクト: vingt-2/Sweep2D
  public boolean Draw(Matrix4 projectionMatrix, Matrix4 viewMatrix) {
    GLES20.glUseProgram(programID);

    Matrix4 mvp =
        Matrix4.Multiply(
            projectionMatrix, Matrix4.Multiply(viewMatrix, parent.transform.transformMatrix));

    float[] mvpArray = mvp.GetOneDimensionalArray();

    GLES20.glUniformMatrix4fv(mvpLocation, 1, false, mvpArray, 0);

    GLES20.glUniform1f(opacityLocation, opacity);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureID);

    GLES20.glUniform1i(textureSamplerLocation, 0);

    // Log.i(DEBUG_TAG,"Enabling " + vertexArrayList.size() + " attribs");

    for (GLVertexArrayObject element : vertexArrayList) {
      GLES20.glEnableVertexAttribArray(element.attributeNumber);
    }

    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexArraySize);

    for (GLVertexArrayObject element : vertexArrayList) {
      GLES20.glDisableVertexAttribArray(element.attributeNumber);
    }
    return true;
  }
コード例 #5
0
 protected void onDrawArraysPre() {
   if (mToneCurveTexture[0] != -1) {
     GLES20.glActiveTexture(GLES20.GL_TEXTURE3);
     GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]);
     GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3);
   }
 }
コード例 #6
0
ファイル: YalgGLSurface.java プロジェクト: heandreas/YALG
  void renderFrame(float fDeltaTime) {
    GLES20.glUseProgram(m_DefaultProgram);

    int posHandle = GLES20.glGetAttribLocation(m_DefaultProgram, "vPosition");
    int uvHandle = GLES20.glGetAttribLocation(m_DefaultProgram, "vUV");
    int textureHandle = GLES20.glGetUniformLocation(m_DefaultProgram, "texture");
    int laserColorHandle = GLES20.glGetUniformLocation(m_DefaultProgram, "colLaser");

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glUniform1i(textureHandle, 0);

    for (GameObject go : gameActivity.gameObjects) {
      go.render(fDeltaTime, posHandle, uvHandle, laserColorHandle);
    }

    GLES20.glDisableVertexAttribArray(posHandle);
    GLES20.glDisableVertexAttribArray(uvHandle);

    ArrayList<PointF> laserSegments = new ArrayList<PointF>();
    ArrayList<Float> laserLengths = new ArrayList<>();
    ArrayList<ColorF> laserColors = new ArrayList<ColorF>();

    gameActivity.computeLasers(laserSegments, laserLengths, laserColors);

    laserRenderer.setLasers(laserSegments, laserLengths, laserColors);
    laserRenderer.render(fDeltaTime);
  }
コード例 #7
0
  public void onSurfaceChanged(GL10 unused, int width, int height) {
    GLES20.glViewport(0, 0, width, height);

    ratio = (float) width / height;

    // this projection matrix is applied to object coodinates
    // in the onDrawFrame() method
    Matrix.orthoM(mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7);

    muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
    Matrix.setLookAtM(mVMatrix, 0, 0, 0, 3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

    engine.initGL();

    GLES20.glUseProgram(mProgram);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

    GLES20.glUniform1i(mSampleHandle, 0);
    GLES20.glUniform1f(mOpacityHandle, 1f);

    GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false, 12, quadCoordsBuf);
    GLES20.glEnableVertexAttribArray(maPositionHandle);
    GLES20.glVertexAttribPointer(maTexCoordsHandle, 2, GLES20.GL_FLOAT, false, 8, quadTexCoordsBuf);
    GLES20.glEnableVertexAttribArray(maTexCoordsHandle);

    initTextures();
  }
コード例 #8
0
  public void onDraw(
      final int textureId, final FloatBuffer cubeBuffer, final FloatBuffer textureBuffer) {
    GLES20.glUseProgram(mGLProgId);
    runPendingOnDrawTasks();
    if (!mIsInitialized) {
      return;
    }

    cubeBuffer.position(0);
    GLES20.glVertexAttribPointer(mGLAttribPosition, 2, GLES20.GL_FLOAT, false, 0, cubeBuffer);
    GLES20.glEnableVertexAttribArray(mGLAttribPosition);
    textureBuffer.position(0);
    GLES20.glVertexAttribPointer(
        mGLAttribTextureCoordinate, 2, GLES20.GL_FLOAT, false, 0, textureBuffer);
    GLES20.glEnableVertexAttribArray(mGLAttribTextureCoordinate);
    if (textureId != OpenGlUtils.NO_TEXTURE) {
      GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
      GLES20.glUniform1i(mGLUniformTexture, 0);
    }
    onDrawArraysPre();
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    GLES20.glDisableVertexAttribArray(mGLAttribPosition);
    GLES20.glDisableVertexAttribArray(mGLAttribTextureCoordinate);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
  }
コード例 #9
0
  @Override
  public void onDrawFrame(GL10 gl) {
    super.onDrawFrame(gl);
    // GL Draw code onwards
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    // Do a complete rotation every 10 seconds.
    long time = SystemClock.uptimeMillis() % 10000L;
    float angleInDegrees = (360.0f / 10000.0f) * ((int) time);

    // Set our per-vertex lighting program.
    GLES20.glUseProgram(mProgramHandle);

    // Set program handles for cube drawing.
    mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVPMatrix");
    mMVMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVMatrix");
    mLightPosHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_LightPos");
    mTextureUniformHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_Texture");
    mPositionHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Position");
    mColorHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Color");
    mNormalHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Normal");
    mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_TexCoordinate");

    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, getGLSurfaceTexture());
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glUniform1i(mTextureUniformHandle, 0);

    //        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0);
    //        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, glSurfaceTex);
    //        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

    //        // Set the active texture unit to texture unit 0.
    //        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    //
    //        // Bind the texture to this unit.
    //        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, glSurfaceTex);

    // Tell the texture uniform sampler to use this texture in the shader by binding to texture unit
    // 0.
    //        GLES20.glUniform1i(mTextureUniformHandle, 0);

    // Calculate position of the light. Rotate and then push into the distance.
    Matrix.setIdentityM(mLightModelMatrix, 0);
    Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, -4.0f);
    Matrix.rotateM(mLightModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
    Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, 2.0f);

    Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0, mLightPosInModelSpace, 0);
    Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0);

    Matrix.setIdentityM(mModelMatrix, 0);
    Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -3.3f);
    Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 1.0f, 0.0f);
    drawCube();

    // Draw a point to indicate the light.
    GLES20.glUseProgram(mPointProgramHandle);
    drawLight();
  }
コード例 #10
0
  public void drawSelf(
      int ballTexId, int isShadow, int planeId, int isLanbanYy) // 0-no shadow 1-with shadow
      {
    // 制定使用某套shader程序
    GLES20.glUseProgram(mProgram);
    // 将最终变换矩阵传入shader程序
    GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, MatrixState.getFinalMatrix(), 0);
    // 将位置、旋转变换矩阵传入shader程序
    GLES20.glUniformMatrix4fv(muMMatrixHandle, 1, false, MatrixState.getMMatrix(), 0);
    // 将光源位置传入shader程序
    GLES20.glUniform3fv(maLightLocationHandle, 1, MatrixState.lightPositionFB);
    // 将摄像机位置传入shader程序
    GLES20.glUniform3fv(maCameraHandle, 1, MatrixState.cameraFB);
    // 将是否绘制阴影属性传入shader程序
    GLES20.glUniform1i(muIsShadow, isShadow);
    GLES20.glUniform1i(muIsShadowFrag, isShadow);
    GLES20.glUniform1i(muIsLanBanShdow, isLanbanYy);
    // 将摄像机矩阵传入shader程序
    GLES20.glUniformMatrix4fv(muCameraMatrixHandle, 1, false, MatrixState.mVMatrix, 0);
    // 将投影矩阵传入shader程序
    GLES20.glUniformMatrix4fv(muProjMatrixHandle, 1, false, MatrixState.mProjMatrix, 0);
    // 将平面位置传入程序
    GLES20.glUniform3fv(muPlaneV, 1, Constant.mianFXL[planeId][0]);
    // 将平面法向量传入程序
    GLES20.glUniform3fv(muPlaneN, 1, Constant.mianFXL[planeId][1]);

    // 传入顶点位置数据
    GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false, 3 * 4, mVertexBuffer);
    // 传入顶点纹理坐标数据
    GLES20.glVertexAttribPointer(maTexCoorHandle, 2, GLES20.GL_FLOAT, false, 2 * 4, mTexCoorBuffer);

    // 传入顶点法向量数据
    GLES20.glVertexAttribPointer(maNormalHandle, 3, GLES20.GL_FLOAT, false, 3 * 4, mNormalBuffer);

    // 允许顶点位置、纹理坐标、法向量数据数组
    GLES20.glEnableVertexAttribArray(maPositionHandle);
    GLES20.glEnableVertexAttribArray(maTexCoorHandle);
    GLES20.glEnableVertexAttribArray(maNormalHandle);

    // 绑定纹理
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, ballTexId);
    GLES20.glUniform1i(muBallTexHandle, 0);
    // 绘制纹理矩形
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vCount);
  }
コード例 #11
0
ファイル: GLSprite.java プロジェクト: ryanbis/AltBridge
  @Override
  public void draw(
      float[] mMVPMatrix, float[] mRotationMatrix, float[] mvMatrix, float[] mProjMatrix) {
    if (visible && canvasSurfaceCreated()) {

      if (!initialized) {
        if (!initObject()) {
          return;
        }
      }

      // Add program to OpenGL environment
      GLES20.glUseProgram(programHandle);

      GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureDataHandle);

      GLES20.glUniform1i(textureUniformHandle, 0);

      // Enable a handle to the triangle vertices
      // Prepare the triangle coordinate data
      vBuffer.position(0);
      GLES20.glVertexAttribPointer(
          positionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vBuffer);
      GLES20.glEnableVertexAttribArray(positionHandle);

      // Pass in the texture coordinate information
      textureBuffer.position(0);
      GLES20.glVertexAttribPointer(
          textureCoordinateHandle,
          COORDS_PER_TEXTURE,
          GLES20.GL_FLOAT,
          false,
          (COORDS_PER_TEXTURE * 4),
          textureBuffer);
      GLES20.glEnableVertexAttribArray(textureCoordinateHandle);

      Matrix.multiplyMM(mMVPMatrix, 0, mvMatrix, 0, mModelMatrix, 0);

      // Apply the projection and view transformation
      GLES20.glUniformMatrix4fv(mModelMatrixHandle, 1, false, mMVPMatrix, 0);
      GLES20Renderer.checkGLError("glUniformMatrix4fv");

      Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mMVPMatrix, 0);

      GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
      GLES20Renderer.checkGLError("glUniformMatrix4fv");

      // Draw the square
      GLES20.glDrawElements(
          GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawBuffer);

      // Disable vertex array
      // GLES20.glDisableVertexAttribArray(positionHandle);
    }
  }
コード例 #12
0
 protected void onDrawArraysPre() {
   for (int i = 0;
       i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE;
       i++) {
     GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + i);
     GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]);
     GLES20.glUniform1i(inputTextureUniformLocations[i], i + 1);
   }
 }
コード例 #13
0
  public void Draw(float[] viewProjectionMatrix, int textureName) {
    GLES20.glUseProgram(shaderProgram);
    // set position
    int aPosition = GLES20.glGetAttribLocation(shaderProgram, "aPosition");
    GLES20.glEnableVertexAttribArray(aPosition);
    GLES20.glVertexAttribPointer(aPosition, 3, GLES20.GL_FLOAT, false, 0, vertexBuffer);

    // set textcoord
    int aTexcoord = GLES20.glGetAttribLocation(shaderProgram, "aTexcoord");
    GLES20.glEnableVertexAttribArray(aTexcoord);
    GLES20.glVertexAttribPointer(aTexcoord, 2, GLES20.GL_FLOAT, false, 0, textureCoordinatesBuffer);

    // set matrix Projection * View * Rotation * world
    Matrix.multiplyMM(worldViewProjectionMatrix, 0, viewProjectionMatrix, 0, worldMatrix, 0);
    int mat4x4 = GLES20.glGetUniformLocation(shaderProgram, "matrix");
    GLES20.glUniformMatrix4fv(mat4x4, 1, false, worldViewProjectionMatrix, 0);

    int uTemp = GLES20.glGetUniformLocation(shaderProgram, "uTemp");

    if (textureName != 0) {
      GLES20.glUniform1f(uTemp, 1.0f);

      int uTexture = GLES20.glGetUniformLocation(shaderProgram, "uTexture");
      GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureName);
      GLES20.glUniform1i(uTexture, 0);

      int uTexture2 = GLES20.glGetUniformLocation(shaderProgram, "uTexture2");
      GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture.getName());
      GLES20.glUniform1i(uTexture2, 1);

    } else GLES20.glUniform1f(uTemp, 0.0f);

    // Draw Cube
    GLES20.glDrawElements(
        GLES20.GL_TRIANGLE_STRIP, index.length, GLES20.GL_UNSIGNED_SHORT, indexBuffer);

    // Disable attribute
    GLES20.glDisableVertexAttribArray(aPosition);
    GLES20.glDisableVertexAttribArray(aTexcoord);
  }
コード例 #14
0
 protected void onDrawArraysPre() {
   if (mToneCurveTexture[0] != -1) {
     GLES20.glActiveTexture(GLES20.GL_TEXTURE3);
     GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]);
     GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3);
   }
   if (mMaskGrey1TextureId != -1) {
     GLES20.glActiveTexture(GLES20.GL_TEXTURE4);
     GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey1TextureId);
     GLES20.glUniform1i(mMaskGrey1UniformLocation, 4);
   }
   if (mMaskGrey2TextureId != -1) {
     GLES20.glActiveTexture(GLES20.GL_TEXTURE5);
     GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey2TextureId);
     GLES20.glUniform1i(mMaskGrey2UniformLocation, 5);
   }
   if (mMaskGrey3TextureId != -1) {
     GLES20.glActiveTexture(GLES20.GL_TEXTURE6);
     GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey3TextureId);
     GLES20.glUniform1i(mMaskGrey3UniformLocation, 6);
   }
 }
コード例 #15
0
ファイル: Material.java プロジェクト: richardba/Rajawali
  /**
   * Binds the textures to an OpenGL texturing target. Called every frame by {@link
   * RajawaliScene#render(double, rajawali.renderer.RenderTarget)}. Shouldn't be called manually.
   */
  public void bindTextures() {
    int num = mTextureList.size();

    for (int i = 0; i < num; i++) {
      ATexture texture = mTextureList.get(i);
      bindTextureByName(texture.getTextureName(), i, texture);
      GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + i);
      GLES20.glBindTexture(texture.getGLTextureType(), texture.getTextureId());
      GLES20.glUniform1i(GLES20.glGetUniformLocation(mProgramHandle, texture.getTextureName()), i);
    }

    if (mPlugins != null) for (IMaterialPlugin plugin : mPlugins) plugin.bindTextures(num);
  }
コード例 #16
0
  public void draw(GL10 gl) {
    // Set our vertex/frag shader program.
    GLES20.glUseProgram(mProgram);

    // Set program handles for drawing.
    // mPositionHandle = GLES20.glGetAttribLocation(mProgram, "a_Position");
    // mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgram, "a_TexCoordinate");
    mTextureUniformHandle = GLES20.glGetUniformLocation(mProgram, "u_Texture");
    // Set the active texture unit to texture unit 0.
    // GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

    // Bind the texture to this unit.
    // GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);

    vertexBuffer.rewind();
    textureBuffer.rewind();

    // Tell the texture uniform sampler to use this texture in the shader by binding to texture unit
    // 0.
    GLES20.glUniform1i(mTextureUniformHandle, 0);

    // Point to our buffers
    // gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    // gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    // Point to our vertex buffer
    // gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
    // gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vertexBufferPointer);
    // first parameter is the ID number of the attribute of the vertex
    // we set attribute id = 0 to the position and 1 to the texture coordin
    GLES20.glVertexAttribPointer(0, 3, GLES20.GL_FLOAT, false, 0, 0);
    GLES20.glEnableVertexAttribArray(0);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, textureBufferPointer);
    GLES20.glVertexAttribPointer(1, 2, GLES20.GL_FLOAT, false, 0, 0);
    GLES20.glEnableVertexAttribArray(1);

    // Set the face rotation
    // GLES20.glFrontFace(GL10.GL_CW);

    // Draw the vertices as triangle strip
    GLES20.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);

    System.out.println(GLUtils.getEGLErrorString(gl.glGetError()));

    // Disable the client state before leaving
    // gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    // gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

  }
コード例 #17
0
  /**
   * Encapsulates the OpenGL ES instructions for drawing this shape.
   *
   * @param mvpMatrix - The Model View Project matrix in which to draw this shape.
   */
  public void draw(float[] mvpMatrix, int eye) {
    // Add program to OpenGL environment
    GLES20.glUseProgram(mProgram);

    // get handle to vertex shader's vPosition member
    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
    mUVCoordsHandle = GLES20.glGetAttribLocation(mProgram, "aTexCoord");
    mSamplerUniformHandle = GLES20.glGetUniformLocation(mProgram, "sTexture");

    // Enable a handle to the triangle vertices
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glEnableVertexAttribArray(mUVCoordsHandle);

    // Prepare the triangle coordinate data
    GLES20.glVertexAttribPointer(
        mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);

    GLES20.glVertexAttribPointer(mUVCoordsHandle, 2, GLES20.GL_FLOAT, true, 2 * 4, uvBuffer);

    int index = 0;
    int textureUnit = 0;
    if (eye == Eye.Type.LEFT) {
      index = 0;
    } else {
      index = 1;
    }

    textureUnit = GLES20.GL_TEXTURE0 + index;

    GLES20.glActiveTexture(textureUnit);
    GLES20.glUniform1i(mSamplerUniformHandle, index);

    // get handle to shape's transformation matrix
    mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
    MyGLRenderer.checkGlError("glGetUniformLocation");

    // Apply the projection and view transformation
    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
    MyGLRenderer.checkGlError("glUniformMatrix4fv");

    // Draw the square
    GLES20.glDrawElements(
        GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glDisableVertexAttribArray(mUVCoordsHandle);
  }
コード例 #18
0
 private void renderDistortionMesh(final DistortionMesh mesh, final int textureId) {
   ProgramHolder holder;
   if (this.mChromaticAberrationCorrectionEnabled) {
     holder = this.mProgramHolderAberration;
   } else {
     holder = this.mProgramHolder;
   }
   GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mesh.mArrayBufferId);
   GLES20.glVertexAttribPointer(holder.aPosition, 2, GLES20.GL_FLOAT, false, 36, 0 * 4);
   GLES20.glEnableVertexAttribArray(holder.aPosition);
   GLES20.glVertexAttribPointer(holder.aVignette, 1, GLES20.GL_FLOAT, false, 36, 2 * 4);
   GLES20.glEnableVertexAttribArray(holder.aVignette);
   GLES20.glVertexAttribPointer(holder.aBlueTextureCoord, 2, GLES20.GL_FLOAT, false, 36, 7 * 4);
   GLES20.glEnableVertexAttribArray(holder.aBlueTextureCoord);
   if (this.mChromaticAberrationCorrectionEnabled) {
     GLES20.glVertexAttribPointer(
         ((ProgramHolderAberration) holder).aRedTextureCoord,
         2,
         GLES20.GL_FLOAT,
         false,
         36,
         3 * 4);
     GLES20.glEnableVertexAttribArray(((ProgramHolderAberration) holder).aRedTextureCoord);
     GLES20.glVertexAttribPointer(
         ((ProgramHolderAberration) holder).aGreenTextureCoord,
         2,
         GLES20.GL_FLOAT,
         false,
         36,
         5 * 4);
     GLES20.glEnableVertexAttribArray(((ProgramHolderAberration) holder).aGreenTextureCoord);
   }
   GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
   GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
   GLES20.glUniform1i(this.mProgramHolder.uTextureSampler, 0);
   GLES20.glUniform1f(this.mProgramHolder.uTextureCoordScale, this.mResolutionScale);
   GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, mesh.mElementBufferId);
   GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP, mesh.nIndices, GLES20.GL_UNSIGNED_SHORT, 0);
 }
コード例 #19
0
  /** Draw the desktop. Make sure {@link hasVideoFrame} returns true. */
  public void draw(float[] combinedMatrix, boolean isTransparent) {
    GLES20.glUseProgram(mProgramHandle);

    // Pass in model view project matrix.
    GLES20.glUniformMatrix4fv(mCombinedMatrixHandle, 1, false, combinedMatrix, 0);

    // Pass in texture coordinate.
    GLES20.glVertexAttribPointer(
        mTextureCoordinateHandle,
        TEXTURE_COORDINATE_DATA_SIZE,
        GLES20.GL_FLOAT,
        false,
        0,
        TEXTURE_COORDINATES);
    GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);

    GLES20.glVertexAttribPointer(
        mPositionHandle, POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mPosition);
    GLES20.glEnableVertexAttribArray(mPositionHandle);

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

    // Pass in transparency.
    GLES20.glVertexAttrib1f(mTransparentHandle, isTransparent ? 0.5f : 1.0f);

    // Link texture data with texture unit.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle);
    GLES20.glUniform1i(mTextureUniformHandle, 0);

    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, VERTICES_NUMBER);

    GLES20.glDisable(GLES20.GL_BLEND);
    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glDisableVertexAttribArray(mTextureCoordinateHandle);
  }
コード例 #20
0
  private void drawRoad(int program) {
    Matrix.setIdentityM(mMMatrix, 0);

    Matrix.multiplyMM(mMVPMatrix, 0, mVMatrix, 0, mMMatrix, 0); // View
    Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mMVPMatrix, 0); // Proj

    // send to the shader
    GLES20.glUniformMatrix4fv(
        GLES20.glGetUniformLocation(program, "uMVPMatrix"), 1, false, mMVPMatrix, 0);

    // Create the normal modelview matrix
    // Invert + transpose of mvpmatrix
    Matrix.invertM(normalMatrix, 0, mMVPMatrix, 0);
    Matrix.transposeM(normalMatrix, 0, normalMatrix, 0);

    // send to the shader
    GLES20.glUniformMatrix4fv(
        GLES20.glGetUniformLocation(program, "normalMatrix"), 1, false, mMVPMatrix, 0);

    /** * DRAWING OBJECT * */
    // Get buffers from mesh
    Object3D ob = this._objects[this.ROAD];
    Mesh mesh = ob.getMesh();
    FloatBuffer _vb = mesh.get_vb();
    ShortBuffer _ib = mesh.get_ib();

    short[] _indices = mesh.get_indices();

    /*float[] myVertices = {
    	-20, 0, -20,
    	-20f, 0, 20,
    	20, 0, -20,
    	20, 0, 20
    };

    _vb = ByteBuffer.allocateDirect(myVertices.length
    		* FLOAT_SIZE_BYTES).order(ByteOrder.nativeOrder()).asFloatBuffer();
    _vb.put(myVertices);*/

    // Vertex buffer

    // the vertex coordinates
    _vb.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
    GLES20.glVertexAttribPointer(
        GLES20.glGetAttribLocation(program, "aPosition"),
        3,
        GLES20.GL_FLOAT,
        false,
        TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
        _vb);
    GLES20.glEnableVertexAttribArray(GLES20.glGetAttribLocation(program, "aPosition"));

    // the normal info
    _vb.position(TRIANGLE_VERTICES_DATA_NOR_OFFSET);
    GLES20.glVertexAttribPointer(
        GLES20.glGetAttribLocation(program, "aNormal"),
        3,
        GLES20.GL_FLOAT,
        false,
        TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
        _vb);
    GLES20.glEnableVertexAttribArray(GLES20.glGetAttribLocation(program, "aNormal"));

    // Texture info

    // bind textures
    if (ob.hasTexture()) { // && enableTexture) {
      // number of textures
      int[] texIDs = ob.get_texID();

      for (int i = 0; i < _texIDs.length; i++) {
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + i);
        // Log.d("TEXTURE BIND: ", i + " " + texIDs[i]);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texIDs[i]);
        GLES20.glUniform1i(GLES20.glGetUniformLocation(program, "texture" + (i + 1)), i);
      }
    }

    // enable texturing? [fix - sending float is waste]
    GLES20.glUniform1f(
        GLES20.glGetUniformLocation(program, "hasTexture") /*shader.hasTextureHandle*/,
        ob.hasTexture() && enableTexture ? 2.0f : 0.0f);

    // texture coordinates
    _vb.position(TRIANGLE_VERTICES_DATA_TEX_OFFSET);
    GLES20.glVertexAttribPointer(
        GLES20.glGetAttribLocation(program, "textureCoord") /*shader.maTextureHandle*/,
        2,
        GLES20.GL_FLOAT,
        false,
        TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
        _vb);
    GLES20.glEnableVertexAttribArray(
        GLES20.glGetAttribLocation(
            program, "textureCoord")); // GLES20.glEnableVertexAttribArray(shader.maTextureHandle);

    // Draw with indices
    GLES20.glDrawElements(GLES20.GL_TRIANGLES, _indices.length, GLES20.GL_UNSIGNED_SHORT, _ib);
    checkGlError("glDrawElements");

    /** END DRAWING OBJECT ** */
  }
コード例 #21
0
ファイル: AndroidGL20.java プロジェクト: simensan/playn
 @Override
 public void glUniform1i(int location, int x) {
   GLES20.glUniform1i(location, x);
 }
コード例 #22
0
ファイル: Material.java プロジェクト: richardba/Rajawali
 public void bindTextureByName(String name, int index, ATexture texture) {
   GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + index);
   GLES20.glBindTexture(texture.getGLTextureType(), texture.getTextureId());
   GLES20.glUniform1i(GLES20.glGetUniformLocation(mProgramHandle, name), index);
 }
コード例 #23
0
ファイル: MarkerTile.java プロジェクト: walke/Xquisite_GIT
  /**
   * drawing function also calculates color value
   *
   * @param mvpMatrix
   */
  public void draw(float[] mvpMatrix) {
    float dif =
        Math.abs(midx - midTx)
            + Math.abs(midy - midTy)
            + Math.abs(sizx - sizTx)
            + Math.abs(sizy - sizTy);
    // Log.d("ASCII","dif"+dif);
    if (dif > 0.01) {
      midx += (midTx - midx) / 10.0f;
      midy += (midTy - midy) / 10.0f;
      sizx += (sizTx - sizx) / 10.0f;
      sizy += (sizTy - sizy) / 10.0f;
    }

    // color[0]= recBlink;
    // color[1]=1.0f-recBlink/5;
    // color[2]=1.0f-recBlink/5;

    GLES20.glUseProgram(mProgram);

    // get handle to vertex shader's vPosition member
    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");

    // get handle to fragment shader's vColor member
    mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");

    // get handle to texture coordinate variable
    mTextureHandle = GLES20.glGetAttribLocation(mProgram, "TexCoordIn");
    // if (mTextureHandle == -1) Log.e("ASCII", "TexCoordIn not found");

    // get handle to shape's texture reference
    fsTexture = GLES20.glGetUniformLocation(mProgram, "Texture");
    // if (fsTexture == -1) Log.e("ASCII", "Texture not found");

    //
    GLES20.glUniform4fv(mColorHandle, 1, color, 0);

    // get handle to shape's transformation matrix
    mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
    // XQGLRenderer.checkGlError("glGetUniformLocation");

    // Apply the projection and view transformation
    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
    // MyGLRenderer.checkGlError("glUniformMatrix4fv");

    //
    GLES20.glEnableVertexAttribArray(mPositionHandle);

    //
    GLES20.glVertexAttribPointer(
        mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);

    GLES20.glVertexAttribPointer(
        mTextureHandle, COORDS_PER_TEXTURE, GLES20.GL_FLOAT, false, textureStride, textureBuffer);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE3);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureRef);
    GLES20.glUniform1i(fsTexture, 3);

    // GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glEnableVertexAttribArray(mTextureHandle);

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

    // Draw the shape
    GLES20.glDrawElements(
        GLES20.GL_TRIANGLE_STRIP, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, indexBuffer);

    GLES20.glDisable(GLES20.GL_BLEND);

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glDisableVertexAttribArray(mTextureHandle);
  }
コード例 #24
0
ファイル: Cube.java プロジェクト: joshkillinger/graphics
  public void draw(float[] mvMatrix, float[] pMatrix) {
    float[] normalMatrix = new float[16];
    float[] tmpMatrix = new float[16];
    Matrix.invertM(tmpMatrix, 0, mvMatrix, 0);
    Matrix.transposeM(normalMatrix, 0, tmpMatrix, 0);

    // Add program to OpenGL ES environment
    GLES20.glUseProgram(shaderProgram);

    // vertex position attribute array
    int mPositionHandle = GLES20.glGetAttribLocation(shaderProgram, "vPosition");
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glVertexAttribPointer(
        mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);

    // vertex normal attribute array
    int mNormalHandle = GLES20.glGetAttribLocation(shaderProgram, "vNormal");
    GLES20.glEnableVertexAttribArray(mNormalHandle);
    GLES20.glVertexAttribPointer(
        mNormalHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, normalBuffer);

    // vertex UV attribute array
    int mUVHandle = GLES20.glGetAttribLocation(shaderProgram, "vTexCoord");
    GLES20.glEnableVertexAttribArray(mUVHandle);
    GLES20.glVertexAttribPointer(mUVHandle, 2, GLES20.GL_FLOAT, false, 8, uvBuffer);

    // material data
    int mColorHandle = GLES20.glGetUniformLocation(shaderProgram, "Color");
    int mAmbientHandle = GLES20.glGetUniformLocation(shaderProgram, "Ambient");
    int mDiffuseHandle = GLES20.glGetUniformLocation(shaderProgram, "Diffuse");
    int mSpecularHandle = GLES20.glGetUniformLocation(shaderProgram, "Specular");
    int mShininessHandle = GLES20.glGetUniformLocation(shaderProgram, "Shininess");
    GLES20.glUniform4fv(mColorHandle, 1, color, 0);
    GLES20.glUniform3fv(mAmbientHandle, 1, ambient, 0);
    GLES20.glUniform3fv(mDiffuseHandle, 1, diffuse, 0);
    GLES20.glUniform3fv(mSpecularHandle, 1, specular, 0);
    GLES20.glUniform1f(mShininessHandle, shininess);

    // transformation matrices
    int mMVMatrixHandle = GLES20.glGetUniformLocation(shaderProgram, "MVMatrix");
    int mPMatrixHandle = GLES20.glGetUniformLocation(shaderProgram, "PMatrix");
    int mNormalMatrixHandle = GLES20.glGetUniformLocation(shaderProgram, "NormalMatrix");
    GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mvMatrix, 0);
    GLES20.glUniformMatrix4fv(mPMatrixHandle, 1, false, pMatrix, 0);
    GLES20.glUniformMatrix4fv(mNormalMatrixHandle, 1, false, normalMatrix, 0);

    // lighting data
    int mLightPosHandle = GLES20.glGetUniformLocation(shaderProgram, "LightPos");
    int mLightColorHandle = GLES20.glGetUniformLocation(shaderProgram, "LightColor");
    GLES20.glUniform4fv(mLightPosHandle, 1, lightPosition, 0);
    GLES20.glUniform3fv(mLightColorHandle, 1, lightColor, 0);

    // texture
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
    int mTexHandle = GLES20.glGetUniformLocation(shaderProgram, "Tex");
    GLES20.glUniform1i(mTexHandle, 0);

    // Draw the object
    GLES20.glDrawElements(
        GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

    // Disable arrays
    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glDisableVertexAttribArray(mNormalHandle);
    GLES20.glDisableVertexAttribArray(mUVHandle);
  }
コード例 #25
0
ファイル: GLPicture.java プロジェクト: 0359xiaodong/muzei
  public void draw(float[] mvpMatrix, float alpha) {
    if (!mHasContent) {
      return;
    }

    // Add program to OpenGL ES environment
    GLES20.glUseProgram(sProgramHandle);

    // Apply the projection and view transformation
    GLES20.glUniformMatrix4fv(sUniformMVPMatrixHandle, 1, false, mvpMatrix, 0);
    GLUtil.checkGlError("glUniformMatrix4fv");

    // Set up vertex buffer
    GLES20.glEnableVertexAttribArray(sAttribPositionHandle);
    GLES20.glVertexAttribPointer(
        sAttribPositionHandle,
        COORDS_PER_VERTEX,
        GLES20.GL_FLOAT,
        false,
        VERTEX_STRIDE_BYTES,
        mVertexBuffer);

    // Set up texture stuff
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glUniform1i(sUniformTextureHandle, 0);
    GLES20.glVertexAttribPointer(
        sAttribTextureCoordsHandle,
        COORDS_PER_TEXTURE_VERTEX,
        GLES20.GL_FLOAT,
        false,
        TEXTURE_VERTEX_STRIDE_BYTES,
        mTextureCoordsBuffer);
    GLES20.glEnableVertexAttribArray(sAttribTextureCoordsHandle);

    // Set the alpha
    GLES20.glUniform1f(sUniformAlphaHandle, alpha);

    // Draw tiles
    for (int y = 0; y < mRows; y++) {
      for (int x = 0; x < mCols; x++) {
        // Pass in the vertex information
        mVertices[0] =
            mVertices[3] = mVertices[9] = Math.min(-1 + 2f * x * mTileSize / mWidth, 1); // left
        mVertices[1] =
            mVertices[10] =
                mVertices[16] = Math.min(-1 + 2f * (y + 1) * mTileSize / mHeight, 1); // top
        mVertices[6] =
            mVertices[12] =
                mVertices[15] = Math.min(-1 + 2f * (x + 1) * mTileSize / mWidth, 1); // right
        mVertices[4] =
            mVertices[7] = mVertices[13] = Math.min(-1 + 2f * y * mTileSize / mHeight, 1); // bottom
        mVertexBuffer.put(mVertices);
        mVertexBuffer.position(0);

        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureHandles[y * mCols + x]);
        GLUtil.checkGlError("glBindTexture");

        // Draw the two triangles
        GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, mVertices.length / COORDS_PER_VERTEX);
      }
    }

    GLES20.glDisableVertexAttribArray(sAttribPositionHandle);
    GLES20.glDisableVertexAttribArray(sAttribTextureCoordsHandle);
  }
コード例 #26
0
ファイル: NativeGL2_Android.java プロジェクト: RMMJR/g3m
 @Override
 public void uniform1i(final IGLUniformID loc, final int v) {
   checkOpenGLThread();
   GLES20.glUniform1i(((GLUniformID_Android) loc).getID(), v);
 }
コード例 #27
0
ファイル: Spaceship.java プロジェクト: ErikHK/LunarLander3D
  public void DrawModel() {

    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, m.textureHandle[0]);
    Mat4 rot;
    if (!haslanded) {
      Vec3 cross = VecMath.CrossProduct(MainActivity.phone_n, MainActivity.init_phone_n);
      phone_n = MainActivity.phone_n;
      init_phone_n = MainActivity.init_phone_n;

      Vec3 ny = new Vec3(0, 0, -1);
      Vec3 cross2 = VecMath.CrossProduct(init_phone_n, ny);
      float ang2 = (float) Math.asin(VecMath.Norm(cross2) / (VecMath.Norm(init_phone_n)));
      ;
      Mat4 rotmat2 = VecMath.ArbRotate(cross2, ang2);
      // Mat4 rotmat = VecMath.ArbRotate(cross, MainActivity.phone_ang);
      Mat4 rotmat = VecMath.ArbRotate(VecMath.Normalize(cross), MainActivity.phone_ang);

      if (Math.abs(init_phone_n.z) > Math.abs(init_phone_n.y))
        rotmat =
            VecMath.ArbRotate(
                VecMath.MultVec3(VecMath.Rx(-(float) Math.PI / 2), VecMath.Normalize(cross)),
                MainActivity.phone_ang);

      Mat4 rotmatf = VecMath.Mult(rotmat, rotmat2);

      Ro = rotmat;
      // Ro = VecMath.ArbRotate( VecMath.MultVec3(VecMath.Rx(-(float) Math.PI/2),
      // VecMath.Normalize(cross)), MainActivity.phone_ang);
      rot = VecMath.Mult(T, Ro);
      GLES20.glUniformMatrix4fv(Shader.rothandle, 1, true, makefloatbuffer(rot.m));
    } else {
      rot = T;
      GLES20.glUniformMatrix4fv(Shader.rothandle, 1, true, makefloatbuffer(rot.m));
      // Ro = rot;
    }

    // GLES20.glUniformMatrix4fv(Shader.rothandle, 1, true, makefloatbuffer(Ro.m));
    m.DrawModel();
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);

    // draw debug spheres
    for (int i = 0; i < 3; i++) {
      float r = .3f;
      float coss = (float) (r * Math.cos(Math.PI / 6 + i * 2 * Math.PI / 3));
      float sinn = (float) (r * Math.sin(Math.PI / 6 + i * 2 * Math.PI / 3));
      Vec3 poss = new Vec3(coss, -.5f, sinn);
      Mat4 TT = VecMath.T(poss);

      Mat4 SS = VecMath.S(.2f, .2f, .2f);
      Mat4 tott = VecMath.Mult(T, VecMath.Mult(Ro, VecMath.Mult(TT, SS)));
      fin_pos[i] = VecMath.MultVec3(tott, poss); // fin position in absolute coords
      GLES20.glUniformMatrix4fv(Shader.rothandle, 1, true, makefloatbuffer(tott.m));
      sphere[i].DrawModel();
    }

    if (isthrusting && fuel > .0f) {
      GLES20.glUniform1i(GLES20.glGetUniformLocation(Shader.program, "draw_exhaustf"), 1);
      Mat4 Tf = VecMath.Mult(rot, VecMath.T(0, -.8f, 0));
      GLES20.glUniformMatrix4fv(Shader.rothandle, 1, true, makefloatbuffer(Tf.m));
      GLES20.glEnable(GLES20.GL_BLEND);
      GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
      GLES20.glDepthMask(false);
      fire.DrawModel();
      GLES20.glDepthMask(true);
      GLES20.glDisable(GLES20.GL_BLEND);
      GLES20.glUniform1i(GLES20.glGetUniformLocation(Shader.program, "draw_exhaustf"), 0);
    }
  }
コード例 #28
0
  private void drawCar(int program, float[] startPos) {
    Matrix.setIdentityM(mMMatrix, 0);
    Matrix.setIdentityM(mTransMatrix, 0);

    // Képernyõ Y tengely
    if (Math.abs(mDY) < 2) mDY = 0;

    if (Math.abs(mDY) <= 250) {
      accelY = -1 * mDY * 2;
    } else {
      if (mDY < 0) mDY = -250f;
      if (mDY > 0) mDY = 250f;
    }
    distanceY += accelY;
    Log.d("mDY:", String.valueOf(mDY));

    // Képernyõ X tengely
    if (Math.abs(mDX) < 2) mDX = 0;
    float[] forward = {(float) Math.cos(mDX / 50), 0.0f, (float) Math.sin(mDX / 50)};

    // lookAt
    lookAt[0] = eyePos[0] + 25 * forward[0];
    lookAt[1] = eyePos[1] + 25 * forward[1];
    lookAt[2] = eyePos[2] + 25 * forward[2];

    // eyePos
    eyePos[0] = 0.0f + distanceY / 1000 * forward[0];
    eyePos[2] = 25.0f + distanceY / 1000 * forward[2];

    Matrix.setLookAtM(
        mVMatrix, 0, eyePos[0], eyePos[1], eyePos[2], lookAt[0], lookAt[1], lookAt[2], 0.0f, 1.0f,
        0.0f);

    // Kormányzás
    startPos[0] = eyePos[0] + 5 * forward[0];
    startPos[2] = eyePos[2] + 5 * forward[2];

    Matrix.translateM(mTransMatrix, 0, startPos[0], startPos[1], startPos[2]);

    Matrix.multiplyMM(mMMatrix, 0, mMMatrix, 0, mTransMatrix, 0); // Translate
    Matrix.multiplyMM(mMVPMatrix, 0, mVMatrix, 0, mMMatrix, 0); // View
    Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mMVPMatrix, 0); // Proj

    // send to the shader
    GLES20.glUniformMatrix4fv(
        GLES20.glGetUniformLocation(program, "uMVPMatrix"), 1, false, mMVPMatrix, 0);

    // Create the normal modelview matrix
    // Invert + transpose of mvpmatrix
    Matrix.invertM(normalMatrix, 0, mMVPMatrix, 0);
    Matrix.transposeM(normalMatrix, 0, normalMatrix, 0);

    // send to the shader
    GLES20.glUniformMatrix4fv(
        GLES20.glGetUniformLocation(program, "normalMatrix"), 1, false, mMVPMatrix, 0);

    /** * DRAWING OBJECT * */
    // Get buffers from mesh
    Object3D ob = this._objects[this.CUBE];
    Mesh mesh = ob.getMesh();
    FloatBuffer _vb = mesh.get_vb();
    ShortBuffer _ib = mesh.get_ib();

    short[] _indices = mesh.get_indices();

    // Vertex buffer

    // the vertex coordinates
    _vb.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
    GLES20.glVertexAttribPointer(
        GLES20.glGetAttribLocation(program, "aPosition"),
        3,
        GLES20.GL_FLOAT,
        false,
        TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
        _vb);
    GLES20.glEnableVertexAttribArray(GLES20.glGetAttribLocation(program, "aPosition"));

    // the normal info
    _vb.position(TRIANGLE_VERTICES_DATA_NOR_OFFSET);
    GLES20.glVertexAttribPointer(
        GLES20.glGetAttribLocation(program, "aNormal"),
        3,
        GLES20.GL_FLOAT,
        false,
        TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
        _vb);
    GLES20.glEnableVertexAttribArray(GLES20.glGetAttribLocation(program, "aNormal"));

    // Texture info

    // bind textures
    if (ob.hasTexture()) { // && enableTexture) {
      // number of textures
      int[] texIDs = ob.get_texID();

      for (int i = 0; i < _texIDs.length; i++) {
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + i);
        // Log.d("TEXTURE BIND: ", i + " " + texIDs[i]);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texIDs[i]);
        GLES20.glUniform1i(GLES20.glGetUniformLocation(program, "texture" + (i + 1)), i);
      }
    }

    // enable texturing? [fix - sending float is waste]
    GLES20.glUniform1f(
        GLES20.glGetUniformLocation(program, "hasTexture") /*shader.hasTextureHandle*/,
        ob.hasTexture() && enableTexture ? 2.0f : 0.0f);

    // texture coordinates
    _vb.position(TRIANGLE_VERTICES_DATA_TEX_OFFSET);
    GLES20.glVertexAttribPointer(
        GLES20.glGetAttribLocation(program, "textureCoord") /*shader.maTextureHandle*/,
        2,
        GLES20.GL_FLOAT,
        false,
        TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
        _vb);
    GLES20.glEnableVertexAttribArray(
        GLES20.glGetAttribLocation(
            program, "textureCoord")); // GLES20.glEnableVertexAttribArray(shader.maTextureHandle);

    // Draw with indices
    GLES20.glDrawElements(GLES20.GL_TRIANGLES, _indices.length, GLES20.GL_UNSIGNED_SHORT, _ib);
    checkGlError("glDrawElements");

    /** END DRAWING OBJECT ** */
  }
コード例 #29
0
  // The render function.
  private void renderFrame() {
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    State state = mRenderer.begin();
    mRenderer.drawVideoBackground();

    GLES20.glEnable(GLES20.GL_DEPTH_TEST);

    // handle face culling, we need to detect if we are using reflection
    // to determine the direction of the culling
    GLES20.glEnable(GLES20.GL_CULL_FACE);
    GLES20.glCullFace(GLES20.GL_BACK);
    if (Renderer.getInstance().getVideoBackgroundConfig().getReflection()
        == VIDEO_BACKGROUND_REFLECTION.VIDEO_BACKGROUND_REFLECTION_ON)
      GLES20.glFrontFace(GLES20.GL_CW); // Front camera
    else GLES20.glFrontFace(GLES20.GL_CCW); // Back camera

    // did we find any trackables this frame?
    for (int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++) {
      TrackableResult result = state.getTrackableResult(tIdx);
      Trackable trackable = result.getTrackable();
      printUserData(trackable);
      Matrix44F modelViewMatrix_Vuforia = Tool.convertPose2GLMatrix(result.getPose());
      float[] modelViewMatrix = modelViewMatrix_Vuforia.getData();

      int textureIndex = trackable.getName().equalsIgnoreCase("cat") ? 0 : 1;
      textureIndex = trackable.getName().equals("city") ? 1 : textureIndex;
      textureIndex = trackable.getName().equalsIgnoreCase("tree") ? 2 : textureIndex;

      // Part B

      Calendar calendar = Calendar.getInstance();
      int day = calendar.get(Calendar.DAY_OF_WEEK);

      if (day != Calendar.SATURDAY && day != Calendar.SUNDAY) {

        textureIndex =
            trackable.getName().equalsIgnoreCase("b11_013")
                ? ImageTargets.orderImages.indexOf("b11_013") + 3
                : textureIndex;
        textureIndex =
            trackable.getName().equalsIgnoreCase("b11_014")
                ? ImageTargets.orderImages.indexOf("b11_014") + 3
                : textureIndex;
        textureIndex =
            trackable.getName().equalsIgnoreCase("b11_015")
                ? ImageTargets.orderImages.indexOf("b11_015") + 3
                : textureIndex;
        textureIndex =
            trackable.getName().equalsIgnoreCase("berkaer_003")
                ? ImageTargets.orderImages.indexOf("berkaer_003") + 3
                : textureIndex;
        textureIndex =
            trackable.getName().equalsIgnoreCase("p_013")
                ? ImageTargets.orderImages.indexOf("p_013") + 3
                : textureIndex;

      } else {
        textureIndex = trackable.getName().equalsIgnoreCase("b11_013") ? 3 : textureIndex;
        textureIndex = trackable.getName().equalsIgnoreCase("b11_014") ? 3 : textureIndex;
        textureIndex = trackable.getName().equalsIgnoreCase("b11_015") ? 3 : textureIndex;
        textureIndex = trackable.getName().equalsIgnoreCase("berkaer_003") ? 3 : textureIndex;
        textureIndex = trackable.getName().equalsIgnoreCase("p_013") ? 3 : textureIndex;
      }

      // deal with the modelview and projection matrices
      float[] modelViewProjection = new float[16];

      boolean partA =
          trackable.getName().equalsIgnoreCase("cat")
              || trackable.getName().equalsIgnoreCase("city")
              || trackable.getName().equalsIgnoreCase("tree");

      if (!mActivity.isExtendedTrackingActive()) {
        if (partA) {
          Matrix.translateM(modelViewMatrix, 0, 0.0f, 0.0f, OBJECT_SCALE_FLOAT);
          Matrix.scaleM(
              modelViewMatrix, 0, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT);
        } else {
          Matrix.translateM(
              modelViewMatrix, 0, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT);
          Matrix.scaleM(
              modelViewMatrix, 0, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT);
        }

      } else {
        Matrix.rotateM(modelViewMatrix, 0, 90.0f, 1.0f, 0, 0);
        Matrix.scaleM(modelViewMatrix, 0, kBuildingScale, kBuildingScale, kBuildingScale);
      }

      Matrix.multiplyMM(
          modelViewProjection,
          0,
          vuforiaAppSession.getProjectionMatrix().getData(),
          0,
          modelViewMatrix,
          0);

      // activate the shader program and bind the vertex/normal/tex coords
      GLES20.glUseProgram(shaderProgramID);

      if (!mActivity.isExtendedTrackingActive()) {

        if (partA) {
          GLES20.glVertexAttribPointer(
              vertexHandle, 3, GLES20.GL_FLOAT, false, 0, mTeapot.getVertices());
          GLES20.glVertexAttribPointer(
              normalHandle, 3, GLES20.GL_FLOAT, false, 0, mTeapot.getNormals());
          GLES20.glVertexAttribPointer(
              textureCoordHandle, 2, GLES20.GL_FLOAT, false, 0, mTeapot.getTexCoords());
        } else {

          Log.d("Object", "Name:" + trackable.getName());
          // To replace the Teapot for a plane Image

          GLES20.glVertexAttribPointer(
              vertexHandle, 3, GLES20.GL_FLOAT, false, 0, mTextPlane.getVertices());
          GLES20.glVertexAttribPointer(
              normalHandle, 3, GLES20.GL_FLOAT, false, 0, mTextPlane.getNormals());
          GLES20.glVertexAttribPointer(
              textureCoordHandle, 2, GLES20.GL_FLOAT, false, 0, mTextPlane.getTexCoords());
        }

        GLES20.glEnableVertexAttribArray(vertexHandle);
        GLES20.glEnableVertexAttribArray(normalHandle);
        GLES20.glEnableVertexAttribArray(textureCoordHandle);

        // activate texture 0, bind it, and pass to shader
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures.get(textureIndex).mTextureID[0]);

        GLES20.glUniform1i(texSampler2DHandle, 0);

        // pass the model view matrix to the shader
        GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, modelViewProjection, 0);

        if (partA) {
          // Finally draw the teapot
          GLES20.glDrawElements(
              GLES20.GL_TRIANGLES,
              mTeapot.getNumObjectIndex(),
              GLES20.GL_UNSIGNED_SHORT,
              mTeapot.getIndices());

        } else {
          // Draw the plane text
          GLES20.glDrawElements(
              GLES20.GL_TRIANGLES,
              mTextPlane.getNumObjectIndex(),
              GLES20.GL_UNSIGNED_SHORT,
              mTextPlane.getIndices());
        }

        // disable the enabled arrays
        GLES20.glDisableVertexAttribArray(vertexHandle);
        GLES20.glDisableVertexAttribArray(normalHandle);
        GLES20.glDisableVertexAttribArray(textureCoordHandle);
      } else {
        GLES20.glDisable(GLES20.GL_CULL_FACE);
        GLES20.glVertexAttribPointer(
            vertexHandle, 3, GLES20.GL_FLOAT, false, 0, mBuildingsModel.getVertices());
        GLES20.glVertexAttribPointer(
            normalHandle, 3, GLES20.GL_FLOAT, false, 0, mBuildingsModel.getNormals());
        GLES20.glVertexAttribPointer(
            textureCoordHandle, 2, GLES20.GL_FLOAT, false, 0, mBuildingsModel.getTexCoords());

        GLES20.glEnableVertexAttribArray(vertexHandle);
        GLES20.glEnableVertexAttribArray(normalHandle);
        GLES20.glEnableVertexAttribArray(textureCoordHandle);

        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures.get(3).mTextureID[0]);
        GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, modelViewProjection, 0);
        GLES20.glUniform1i(texSampler2DHandle, 0);
        GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, mBuildingsModel.getNumObjectVertex());

        SampleUtils.checkGLError("Renderer DrawBuildings");
      }

      SampleUtils.checkGLError("Render Frame");
    }

    GLES20.glDisable(GLES20.GL_DEPTH_TEST);

    mRenderer.end();
  }
コード例 #30
0
ファイル: WaterLayer.java プロジェクト: scheibk/FFZ
  public void draw(StandardProgram prog, Viewport vp) {

    // get handle to vertex shader's vPosition member
    mPositionHandle = prog.getAttributeLocation("vPosition");

    // set the vertext pointer to the front of the buffer
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]);
    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, buffers[1]); // draw order

    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // get handle to fragment shader's vColor member
    mColorHandle = prog.getUniformLocation("vColor");

    // texture stuff

    mTextureUniformHandle = prog.getUniformLocation("u_Texture");
    mTextureCoordinateHandle = prog.getAttributeLocation("a_TexCoordinate");
    tm.setTextureToRepeat(R.drawable.blank);
    GLES20.glUniform1i(mTextureUniformHandle, 0);

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

    GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);

    // get handle to shape's transformation matrix
    mMVPMatrixHandle = prog.getUniformLocation("uMVPMatrix");

    // start the position at -1, -1
    Matrix.setIdentityM(mMMatrix, 0);
    Matrix.translateM(mMMatrix, 0, 0, 0, 1.0f); // z index is at the very front

    // ---- draw a puddle

    setBufferPosition(PUDDLE);
    setColor(normalColor);

    setDrawPosition(300f, -300f);

    setScale(9.0f, 7.0f);

    // set up the view matrix and projection matrix
    Matrix.multiplyMM(eyeMatrix, 0, vp.getViewMatrix(), 0, mMMatrix, 0);
    Matrix.multiplyMM(mvpMatrix, 0, vp.getProjMatrix(), 0, eyeMatrix, 0);

    // Apply the projection and view transformation
    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);

    // Draw
    GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, 0);

    // ---- end draw puddle

    // IMPORTANT: Unbind from the buffer when we're done with it.
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
  }