@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();
  }
Пример #2
0
 public boolean AssignShaderProgram(String materialName) {
   programID = MainGame.singleton.sharedResources.GetShaderProgram(materialName);
   mvpLocation = GLES20.glGetUniformLocation(programID, UNIFORM_MATRIX_MVP);
   opacityLocation = GLES20.glGetUniformLocation(programID, "opacity");
   textureSamplerLocation = GLES20.glGetUniformLocation(programID, UNIFORM_TEX_SAMPLER);
   return (programID != 0);
 }
Пример #3
0
  public void draw() {
    GLES20.glUseProgram(shaderProgram);

    int muMVPMat = GLES20.glGetUniformLocation(shaderProgram, "uMVPMatrix");
    GLESUtils.checkGlError("glGetUniformLocation");
    GLES20.glUniformMatrix4fv(muMVPMat, 1, false, scene.modelViewProjectionMatrix(), 0);
    GLESUtils.checkGlError("glUniformMatrix4fv");

    int mPositionH = vertexAttribArrayf("vPosition", CpV, cStride, posBuffer);
    GLESUtils.checkGlError("vPosition");

    int normalH = vertexAttribArrayf("vNormal", CpV, cStride, normalBuffer);
    GLESUtils.checkGlError("vNormal");

    int mColorH = GLES20.glGetAttribLocation(shaderProgram, "vColor");
    GLES20.glVertexAttrib4f(mColorH, c[0], c[1], c[2], c[3]);
    GLESUtils.checkGlError("vColor");

    int phaseH = vertexAttribArrayf("vPhase", 1, NumVerts, phaseBuffer);
    GLESUtils.checkGlError("vPhase");

    int gTime = GLES20.glGetUniformLocation(shaderProgram, "iGlobalTime");
    GLES20.glUniform1f(gTime, (float) (SystemClock.uptimeMillis() / 1000.0));
    GLESUtils.checkGlError("iGlobalTime");

    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, oBufferLength);

    GLES20.glDisableVertexAttribArray(mPositionH);
    GLES20.glDisableVertexAttribArray(normalH);
    GLES20.glDisableVertexAttribArray(mColorH);
    GLES20.glDisableVertexAttribArray(phaseH);
  }
Пример #4
0
  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);
  }
  public void draw(float[] mvpMatrix) {
    // Add program to OpenGL ES environment
    GLES20.glUseProgram(mProgram);

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

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

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

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

    // Set color for drawing the triangle
    GLES20.glUniform4fv(mColorHandle, 1, color, 0);

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

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

    // Draw the triangle
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount);

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
  }
Пример #6
0
  /** Constructor this should be called in GL context */
  public GLDrawer2D() {
    pVertex =
        ByteBuffer.allocateDirect(VERTEX_SZ * FLOAT_SZ)
            .order(ByteOrder.nativeOrder())
            .asFloatBuffer();
    pVertex.put(VERTICES);
    pVertex.flip();
    pTexCoord =
        ByteBuffer.allocateDirect(VERTEX_SZ * FLOAT_SZ)
            .order(ByteOrder.nativeOrder())
            .asFloatBuffer();
    pTexCoord.put(TEXCOORD);
    pTexCoord.flip();

    hProgram = loadShader(vss, fss);
    GLES20.glUseProgram(hProgram);
    maPositionLoc = GLES20.glGetAttribLocation(hProgram, "aPosition");
    maTextureCoordLoc = GLES20.glGetAttribLocation(hProgram, "aTextureCoord");
    muMVPMatrixLoc = GLES20.glGetUniformLocation(hProgram, "uMVPMatrix");
    muTexMatrixLoc = GLES20.glGetUniformLocation(hProgram, "uTexMatrix");

    Matrix.setIdentityM(mMvpMatrix, 0);
    GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mMvpMatrix, 0);
    GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, mMvpMatrix, 0);
    GLES20.glVertexAttribPointer(maPositionLoc, 2, GLES20.GL_FLOAT, false, VERTEX_SZ, pVertex);
    GLES20.glVertexAttribPointer(
        maTextureCoordLoc, 2, GLES20.GL_FLOAT, false, VERTEX_SZ, pTexCoord);
    GLES20.glEnableVertexAttribArray(maPositionLoc);
    GLES20.glEnableVertexAttribArray(maTextureCoordLoc);
  }
Пример #7
0
  public void draw(float[] mvpMatrix) {
    // Add program to OpenGL environment
    GLES20.glUseProgram(mProgram);

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

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

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

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

    // Set color for drawing the triangle
    GLES20.glUniform4fv(mColorHandle, 1, color, 0);

    // 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);
  }
Пример #8
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");
  }
Пример #9
0
 protected void onInit() {
   super.onInit();
   mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(mGLProgId, "curve");
   mMaskGrey1UniformLocation = GLES20.glGetUniformLocation(getProgram(), "grey1Frame");
   mMaskGrey2UniformLocation = GLES20.glGetUniformLocation(getProgram(), "grey2Frame");
   mMaskGrey3UniformLocation = GLES20.glGetUniformLocation(getProgram(), "grey3Frame");
 }
  @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();
  }
 @Override
 public void onInit() {
   super.onInit();
   mScaleLocation = GLES20.glGetUniformLocation(getProgram(), "scale");
   mRadiusLocation = GLES20.glGetUniformLocation(getProgram(), "radius");
   mCenterLocation = GLES20.glGetUniformLocation(getProgram(), "center");
   mAspectRatioLocation = GLES20.glGetUniformLocation(getProgram(), "aspectRatio");
 }
Пример #12
0
  public void draw() {
    // Add program to OpenGL environment
    GLES20.glUseProgram(mProgram);

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

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

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

    // get handle to fragment shader's vColor member
    mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");
    // Set colorVertices for drawing the scene
    GLES20.glUniform4fv(mColorHandle, 1, colorVertices, 0);

    // Get handle to shape's transformation matrix
    int mtrxhandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");

    // Apply the projection and view transformation
    GLES20.glUniformMatrix4fv(mtrxhandle, 1, false, pointsRenderer.mtrxProjectionAndView, 0);

    // Draw the scene
    GLES20.glDrawArrays(GLES20.GL_POINTS, 0, vertexCount);

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

    if (drawLines) {
      GLES20.glUseProgram(mLinesProgram);
      mLinesPositionHandle = GLES20.glGetAttribLocation(mLinesProgram, "vPosition");
      GLES20.glEnableVertexAttribArray(mLinesPositionHandle);
      // Prevent null pointer race condition
      if (linesVertexBuffer != null) {
        GLES20.glVertexAttribPointer(
            mLinesPositionHandle,
            COORDS_PER_VERTEX,
            GLES20.GL_FLOAT,
            false,
            VERTEX_STRIDE,
            linesVertexBuffer);
        mLinesColorHandle = GLES20.glGetUniformLocation(mLinesProgram, "vColor");
        GLES20.glUniform4fv(mLinesColorHandle, 1, colorLines, 0);
        int mtrxLineshandle = GLES20.glGetUniformLocation(mLinesProgram, "uMVPMatrix");
        GLES20.glUniformMatrix4fv(
            mtrxLineshandle, 1, false, pointsRenderer.mtrxProjectionAndView, 0);
        // GLES20.glDrawArrays(GLES20.GL_LINE_STRIP, 0, linesVertexCount);
        // GLES20.glDrawArrays(GLES20.GL_LINES, 0, linesVertexCount);
        // GLES20.glDrawArrays(GLES20.GL_LINE_LOOP, 0, linesVertexCount);
        // GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, linesVertexCount);
        GLES20.glDrawArrays(renderMethod, 0, linesVertexCount);
        GLES20.glDisableVertexAttribArray(mLinesPositionHandle);
      }
    }
  }
  SimpleShader() {
    program = loadProgram(vertexShader, fragmentShader);
    uMVMatrixHandle = GLES20.glGetUniformLocation(program, "mvMatrix");
    if (uMVMatrixHandle == 0) Log.d("WEEE", "" + uMVMatrixHandle);
    uPMatrixHandle = GLES20.glGetUniformLocation(program, "pMatrix");
    if (uPMatrixHandle == 0) Log.d("WEEE", "" + uPMatrixHandle);

    aVertexHandle = GLES20.glGetAttribLocation(program, "vertex");
    if (aVertexHandle == 0) Log.d("WEEE", "" + aVertexHandle);
    aNormalHandle = GLES20.glGetAttribLocation(program, "normal");
    if (aNormalHandle == 0) Log.d("WEEE", "" + aNormalHandle);
  }
Пример #14
0
  /**
   * we override {@link #setUniformsAndAttribs()} and make sure to call the super so we can add our
   * own uniforms to our shaders here. CameraRenderer handles the rest for us automatically
   */
  @Override
  protected void setUniformsAndAttribs() {
    super.setUniformsAndAttribs();

    int offsetRLoc = GLES20.glGetUniformLocation(mCameraShaderProgram, "offsetR");
    int offsetGLoc = GLES20.glGetUniformLocation(mCameraShaderProgram, "offsetG");
    int offsetBLoc = GLES20.glGetUniformLocation(mCameraShaderProgram, "offsetB");

    GLES20.glUniform1f(offsetRLoc, offsetR);
    GLES20.glUniform1f(offsetGLoc, offsetG);
    GLES20.glUniform1f(offsetBLoc, offsetB);
  }
Пример #15
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);
  }
  /*
   * 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);
  }
Пример #17
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();
  }
Пример #18
0
  public void draw() {
    // 将program加入OpenGL ES环境中
    GLES20.glUseProgram(mProgram);

    // 获取指向vertex shader的成员vPosition的 handle
    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");

    // 启用一个指向三角形的顶点数组的handle
    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // 准备三角形的坐标数据
    GLES20.glVertexAttribPointer(
        mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);

    // 获取指向fragment shader的成员vColor的handle
    mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");

    // 设置三角形的颜色
    GLES20.glUniform4fv(mColorHandle, 1, color, 0);

    // 画三角形
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount);

    // 禁用指向三角形的顶点数组
    GLES20.glDisableVertexAttribArray(mPositionHandle);
  }
Пример #19
0
 public void intShader(MySurfaceView mv) { // 初始化着色器
   // 加载顶点着色器的脚本内容
   mVertexShader = ShaderUtil.loadFromAssetsFile("vertex_xk.sh", mv.getResources());
   ShaderUtil.checkGlError("==ss==");
   // 加载片元着色器的脚本内容
   mFragmentShader = ShaderUtil.loadFromAssetsFile("frag_xk.sh", mv.getResources());
   // 基于顶点着色器与片元着色器创建程序
   ShaderUtil.checkGlError("==ss==");
   mProgram = createProgram(mVertexShader, mFragmentShader);
   // 获取程序中顶点位置属性引用id
   maPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");
   // 获取程序中总变换矩阵引用id
   muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
   // 获取顶点尺寸参数引用
   uPointSizeHandle = GLES20.glGetUniformLocation(mProgram, "uPointSize");
 }
Пример #20
0
  public void draw() {

    // Add program to OpenGLES environment
    GLES20.glUseProgram(mProgram);

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

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

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

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

    // set color for drawing the triangle
    GLES20.glUniform4fv(mColorHandle, 1, mColor, 0);

    // draw the triangle
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, mVertexCount);

    // disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
  }
  @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();
  }
Пример #22
0
  public void draw(final int mShader) {

    // Bind Texture VBO
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, getTexVBO());
    // Pass in texture map position
    mTexVertBuffer.position(0);
    final int mTextureCoordinateHandle = GLES20.glGetAttribLocation(mShader, "a_TexCoord");
    GLES20.glVertexAttribPointer(
        mTextureCoordinateHandle, mPositionDataSize, GLES20.GL_FLOAT, false, 0, 0);
    GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);

    // Bind VBO
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, getPlaneVBO());
    // Pass in the position information
    mPlaneVertBuffer.position(0);
    final int mPositionHandle = GLES20.glGetAttribLocation(mShader, "a_Position");
    GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false, 0, 0);
    GLES20.glEnableVertexAttribArray(mPositionHandle);

    //	Pass in the color information
    final int mColorHandle = GLES20.glGetUniformLocation(mShader, "u_Color");
    GLES20.glUniform4f(mColorHandle, 0, 1, 1, 1);

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

    // Unbind buffers
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
  }
 public void onInit() {
   mGLProgId = OpenGlUtils.loadProgram(mVertexShader, mFragmentShader);
   mGLAttribPosition = GLES20.glGetAttribLocation(mGLProgId, "position");
   mGLUniformTexture = GLES20.glGetUniformLocation(mGLProgId, "inputImageTexture");
   mGLAttribTextureCoordinate = GLES20.glGetAttribLocation(mGLProgId, "inputTextureCoordinate");
   mIsInitialized = true;
 }
Пример #24
0
 public Desktop(Display display) {
   mDisplay = display;
   mVertexShaderHandle = ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, VERTEX_SHADER);
   mFragmentShaderHandle = ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER);
   mProgramHandle =
       ShaderHelper.createAndLinkProgram(
           mVertexShaderHandle,
           mFragmentShaderHandle,
           new String[] {"a_Position", "a_TexCoordinate", "u_CombinedMatrix", "u_Texture"});
   mCombinedMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_CombinedMatrix");
   mTextureUniformHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_Texture");
   mPositionHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Position");
   mTransparentHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_transparency");
   mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_TexCoordinate");
   mTextureDataHandle = TextureHelper.createTextureHandle();
 }
Пример #25
0
    public void draw(float[] mvpMatrix) {
      GLES20.glUseProgram(mProgram);
      mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
      GLES20.glEnableVertexAttribArray(mPositionHandle);
      GLES20.glVertexAttribPointer(
          mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);

      mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");
      GLES20.glUniform4fv(mColorHandle, 1, color, 0);
      mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
      checkGlError("glGetUniformLocation");
      GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
      checkGlError("glUniformMatrix4fv");
      GLES20.glDrawArrays(GLES20.GL_LINES, 0, vertexCount);
      GLES20.glDisableVertexAttribArray(mPositionHandle);
    }
Пример #26
0
 // 初始化着色器程序的initShader方法
 public void initShader(int programId) {
   mProgram = programId;
   // 获得顶点坐标数据的引用
   maPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");
   // 顶点纹理坐标的引用id
   maTexCoorHandle = GLES20.glGetAttribLocation(mProgram, "aTexCoor");
   muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
 }
Пример #27
0
  public static void initGl() {
    // Initialize shaders and create/link program
    int vertexShaderHandle = GLUtil.loadShader(GLES20.GL_VERTEX_SHADER, VERTEX_SHADER_CODE);
    int fragShaderHandle = GLUtil.loadShader(GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER_CODE);

    sProgramHandle = GLUtil.createAndLinkProgram(vertexShaderHandle, fragShaderHandle, null);
    sAttribPositionHandle = GLES20.glGetAttribLocation(sProgramHandle, "aPosition");
    sAttribTextureCoordsHandle = GLES20.glGetAttribLocation(sProgramHandle, "aTexCoords");
    sUniformMVPMatrixHandle = GLES20.glGetUniformLocation(sProgramHandle, "uMVPMatrix");
    sUniformTextureHandle = GLES20.glGetUniformLocation(sProgramHandle, "uTexture");
    sUniformAlphaHandle = GLES20.glGetUniformLocation(sProgramHandle, "uAlpha");

    // Compute max texture size
    int[] maxTextureSize = new int[1];
    GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);
    sMaxTextureSize = maxTextureSize[0];
  }
  // Function for initializing the renderer.
  private void initRendering() {
    mTeapot = new Teapot();
    mTextPlane = new TextPlane();

    mRenderer = Renderer.getInstance();

    GLES20.glClearColor(0.0f, 0.0f, 0.0f, Vuforia.requiresAlpha() ? 0.0f : 1.0f);

    for (Texture t : mTextures) {
      GLES20.glGenTextures(1, t.mTextureID, 0);
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, t.mTextureID[0]);
      GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexImage2D(
          GLES20.GL_TEXTURE_2D,
          0,
          GLES20.GL_RGBA,
          t.mWidth,
          t.mHeight,
          0,
          GLES20.GL_RGBA,
          GLES20.GL_UNSIGNED_BYTE,
          t.mData);
    }

    shaderProgramID =
        SampleUtils.createProgramFromShaderSrc(
            CubeShaders.CUBE_MESH_VERTEX_SHADER, CubeShaders.CUBE_MESH_FRAGMENT_SHADER);

    vertexHandle = GLES20.glGetAttribLocation(shaderProgramID, "vertexPosition");
    normalHandle = GLES20.glGetAttribLocation(shaderProgramID, "vertexNormal");
    textureCoordHandle = GLES20.glGetAttribLocation(shaderProgramID, "vertexTexCoord");
    mvpMatrixHandle = GLES20.glGetUniformLocation(shaderProgramID, "modelViewProjectionMatrix");
    texSampler2DHandle = GLES20.glGetUniformLocation(shaderProgramID, "texSampler2D");

    try {
      mBuildingsModel = new SampleApplication3DModel();
      mBuildingsModel.loadModel(mActivity.getResources().getAssets(), "ImageTargets/Buildings.txt");
    } catch (IOException e) {
      Log.e(LOGTAG, "Unable to load buildings");
    }

    // Hide the Loading Dialog
    mActivity.loadingDialogHandler.sendEmptyMessage(LoadingDialogHandler.HIDE_LOADING_DIALOG);
  }
Пример #29
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);
  }
Пример #30
0
 public void draw(float[] mvp, float x, float y) {
   float[] mvpMatrix = new float[16];
   System.arraycopy(mvp, 0, mvpMatrix, 0, 16);
   Matrix.setIdentityM(transMatrix, 0);
   //
   glBase.translate(transMatrix, x, y, 0);
   Matrix.multiplyMM(mvpMatrix, 0, transMatrix, 0, mvpMatrix, 0);
   GLES20.glUseProgram(mProgram);
   mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
   GLES20.glEnableVertexAttribArray(mPositionHandle);
   GLES20.glVertexAttribPointer(
       mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);
   mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");
   GLES20.glUniform4fv(mColorHandle, 1, color, 0);
   mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
   checkGlError("glGetUniformLocation");
   GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
   checkGlError("glUniformMatrix4fv");
   GLES20.glDrawArrays(GLES20.GL_LINE_LOOP, 0, vertexCount);
   GLES20.glDisableVertexAttribArray(mPositionHandle);
 }