private int createProgram(String vertexSource, String fragmentSource) {
   int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
   if (vertexShader == 0) {
     return TRIANGLE_VERTICES_DATA_POS_OFFSET;
   }
   int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
   if (pixelShader == 0) {
     return TRIANGLE_VERTICES_DATA_POS_OFFSET;
   }
   int program = GLES20.glCreateProgram();
   checkGlError("glCreateProgram");
   if (program == 0) {
     Log.e(TAG, "Could not create program");
   }
   GLES20.glAttachShader(program, vertexShader);
   checkGlError("glAttachShader");
   GLES20.glAttachShader(program, pixelShader);
   checkGlError("glAttachShader");
   GLES20.glLinkProgram(program);
   int[] linkStatus = new int[FLIP_TYPE_HORIZONTAL];
   GLES20.glGetProgramiv(
       program, GLES20.GL_LINK_STATUS, linkStatus, TRIANGLE_VERTICES_DATA_POS_OFFSET);
   if (linkStatus[TRIANGLE_VERTICES_DATA_POS_OFFSET] == FLIP_TYPE_HORIZONTAL) {
     return program;
   }
   Log.e(TAG, "Could not link program: ");
   Log.e(TAG, GLES20.glGetProgramInfoLog(program));
   GLES20.glDeleteProgram(program);
   throw new IllegalStateException("Could not link program");
 }
예제 #2
0
  public static int createProgram(String vertexShaderSource, String fragmentShaderSource) {
    if (TextUtils.isEmpty(vertexShaderSource) || TextUtils.isEmpty(fragmentShaderSource)) {
      throw new IllegalArgumentException("传入的顶点着色器源码为空或者传入的片元着色器源码为空");
    }

    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderSource);
    if (vertexShader == 0) {
      return 0;
    }

    int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderSource);
    if (fragmentShader == 0) {
      return 0;
    }

    int program = GLES20.glCreateProgram();
    if (program != 0) {
      GLES20.glAttachShader(program, vertexShader);
      checkGLError("AttachVertexShader");
      GLES20.glAttachShader(program, vertexShader);
      checkGLError("AttachFragmentShader");

      GLES20.glLinkProgram(program);
      int[] result = new int[1];
      GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, result, 0);
      if (result[0] == 0) {
        Log.w(TAG, "加载程序失败");
        Log.w(TAG, GLES20.glGetProgramInfoLog(program));
        GLES20.glDeleteProgram(program);
        program = 0;
      }
    }

    return program;
  }
  public Triangle() {
    // initialize vertex byte buffer for shape coordinates
    ByteBuffer bb =
        ByteBuffer.allocateDirect(
            // (number of coordinate values * 4 bytes per float)
            triangleCoords.length * 4);
    // use the device hardware's native byte order
    bb.order(ByteOrder.nativeOrder());

    // create a floating point buffer from the ByteBuffer
    vertexBuffer = bb.asFloatBuffer();
    // add the coordinates to the FloatBuffer
    vertexBuffer.put(triangleCoords);
    // set the buffer to read the first coordinate
    vertexBuffer.position(0);

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

    // create empty OpenGL ES Program
    mProgram = GLES20.glCreateProgram();

    // add the vertex shader to program
    GLES20.glAttachShader(mProgram, vertexShader);

    // add the fragment shader to program
    GLES20.glAttachShader(mProgram, fragmentShader);

    // creates OpenGL ES program executables
    GLES20.glLinkProgram(mProgram);
  }
예제 #4
0
  public static int LoadProgram(String strVSource, String strFSource) {
    Log.d("Utils", "LoadProgram");
    int iVShader;
    int iFShader;
    int iProgId;
    int[] link = new int[1];
    iVShader = LoadShader(strVSource, GLES20.GL_VERTEX_SHADER);
    if (iVShader == 0) {
      Log.d("Load Program", "Vertex Shader Failed");
      return 0;
    }
    iFShader = LoadShader(strFSource, GLES20.GL_FRAGMENT_SHADER);
    if (iFShader == 0) {
      Log.d("Load Program", "Fragment Shader Failed");
      return 0;
    }

    iProgId = GLES20.glCreateProgram();

    GLES20.glAttachShader(iProgId, iVShader);
    GLES20.glAttachShader(iProgId, iFShader);

    GLES20.glLinkProgram(iProgId);

    GLES20.glGetProgramiv(iProgId, GLES20.GL_LINK_STATUS, link, 0);
    if (link[0] <= 0) {
      Log.d("Load Program", "Linking Failed");
      return 0;
    }
    GLES20.glDeleteShader(iVShader);
    GLES20.glDeleteShader(iFShader);
    return iProgId;
  }
예제 #5
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);
  }
예제 #6
0
    public axizLines(float size) {
      triangleCoords =
          new float[] {
            0f, 0f, 0f, size, 0f, 0f, 0f, 0f, 0f, 0f, 0, size, 0f, 0f, 0f, 0f, size, 0f,
            //				0f,0f,0f,
            //				size,size,size
          };
      vertexCount = triangleCoords.length / COORDS_PER_VERTEX;
      vertexStride = COORDS_PER_VERTEX * 4;
      // initialize vertex byte buffer for shape coordinates
      ByteBuffer bb =
          ByteBuffer.allocateDirect(
              // (number of coordinate values * 4 bytes per float)
              triangleCoords.length * 4);
      // use the device hardware's native byte order
      bb.order(ByteOrder.nativeOrder());

      // create a floating point buffer from the ByteBuffer
      vertexBuffer = bb.asFloatBuffer();
      // add the coordinates to the FloatBuffer
      vertexBuffer.put(triangleCoords);
      // set the buffer to read the first coordinate
      vertexBuffer.position(0);

      // prepare shaders and OpenGL program
      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); // create OpenGL program executables
    }
예제 #7
0
    public circle(float r) {
      transMatrix = new float[16];
      int sides = 24;
      vertexCoords = new float[sides * 3];
      double angle = 2 * Math.PI / sides;

      for (int i = 0; i < sides; i++) {
        vertexCoords[3 * i] = (float) (Math.cos(i * angle) * r);
        vertexCoords[3 * i + 1] = (float) (Math.sin(i * angle) * r);
        vertexCoords[3 * i + 2] = 0f;
      }
      vertexCount = vertexCoords.length / COORDS_PER_VERTEX;
      vertexStride = COORDS_PER_VERTEX * 4;
      ByteBuffer bb = ByteBuffer.allocateDirect(vertexCoords.length * 4);
      bb.order(ByteOrder.nativeOrder());
      vertexBuffer = bb.asFloatBuffer();
      vertexBuffer.put(vertexCoords);
      vertexBuffer.position(0);
      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); // create OpenGL program executables
    }
예제 #8
0
  public static int createProgram(int vertexShaderHandle, int fragmentShaderHandle) {
    int mProgram = GLES20.glCreateProgram();

    if (mProgram != 0) {
      GLES20.glAttachShader(mProgram, vertexShaderHandle);
      GLES20.glAttachShader(mProgram, fragmentShaderHandle);

      GLES20.glLinkProgram(mProgram);

      final int[] linkStatus = new int[1];
      GLES20.glGetProgramiv(mProgram, GLES20.GL_LINK_STATUS, linkStatus, 0);

      if (linkStatus[0] == 0) {
        Log.v(OpenGLUtil.class.getCanonicalName(), GLES20.glGetProgramInfoLog(mProgram));
        GLES20.glDeleteProgram(mProgram);
        mProgram = 0;
      }
    }

    if (mProgram == 0) {
      throw new RuntimeException("Error creating program.");
    }

    return mProgram;
  }
예제 #9
0
  /**
   * load, compile and link shader
   *
   * @param vss source of vertex shader
   * @param fss source of fragment shader
   * @return
   */
  public static int loadShader(final String vss, final String fss) {
    if (DEBUG) Log.v(TAG, "loadShader:");
    int vs = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
    GLES20.glShaderSource(vs, vss);
    GLES20.glCompileShader(vs);
    final int[] compiled = new int[1];
    GLES20.glGetShaderiv(vs, GLES20.GL_COMPILE_STATUS, compiled, 0);
    if (compiled[0] == 0) {
      if (DEBUG) Log.e(TAG, "Failed to compile vertex shader:" + GLES20.glGetShaderInfoLog(vs));
      GLES20.glDeleteShader(vs);
      vs = 0;
    }

    int fs = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);
    GLES20.glShaderSource(fs, fss);
    GLES20.glCompileShader(fs);
    GLES20.glGetShaderiv(fs, GLES20.GL_COMPILE_STATUS, compiled, 0);
    if (compiled[0] == 0) {
      if (DEBUG) Log.w(TAG, "Failed to compile fragment shader:" + GLES20.glGetShaderInfoLog(fs));
      GLES20.glDeleteShader(fs);
      fs = 0;
    }

    final int program = GLES20.glCreateProgram();
    GLES20.glAttachShader(program, vs);
    GLES20.glAttachShader(program, fs);
    GLES20.glLinkProgram(program);

    return program;
  }
예제 #10
0
  public Square() {
    // initialize vertex byte buffer for shape coordinates
    ByteBuffer bb =
        ByteBuffer.allocateDirect(
            // (# of coordinate values * 4 bytes per float)
            squareCoords.length * 4);
    bb.order(ByteOrder.nativeOrder());
    vertexBuffer = bb.asFloatBuffer();
    vertexBuffer.put(squareCoords);
    vertexBuffer.position(0);

    // initialize byte buffer for the draw list
    ByteBuffer dlb =
        ByteBuffer.allocateDirect(
            // (# of coordinate values * 2 bytes per short)
            drawOrder.length * 2);
    dlb.order(ByteOrder.nativeOrder());
    drawListBuffer = dlb.asShortBuffer();
    drawListBuffer.put(drawOrder);
    drawListBuffer.position(0);

    // prepare shaders and OpenGL program
    int vertexShader = MyGLRenderer.loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
    int fragmentShader = MyGLRenderer.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); // create OpenGL program executables
  }
  @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();
  }
 private int createProgram(final String vertexSource, final String fragmentSource) {
   final int vertexShader = this.loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
   if (vertexShader == 0) {
     return 0;
   }
   final int pixelShader = this.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
   if (pixelShader == 0) {
     return 0;
   }
   int program = GLES20.glCreateProgram();
   if (program != 0) {
     GLES20.glAttachShader(program, vertexShader);
     this.checkGlError("glAttachShader");
     GLES20.glAttachShader(program, pixelShader);
     this.checkGlError("glAttachShader");
     GLES20.glLinkProgram(program);
     final int[] linkStatus = {0};
     GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
     if (linkStatus[0] != 1) {
       Log.e("DistortionRenderer", "Could not link program: ");
       Log.e("DistortionRenderer", GLES20.glGetProgramInfoLog(program));
       GLES20.glDeleteProgram(program);
       program = 0;
     }
   }
   return program;
 }
예제 #13
0
  /**
   * Creates a shader program by compiling the vertex and fragment shaders from a string.
   *
   * @param vertexSource
   * @param fragmentSource
   * @return
   */
  private int createProgram(String vertexSource, String fragmentSource) {
    mVShaderHandle = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    if (mVShaderHandle == 0) {
      return 0;
    }

    mFShaderHandle = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    if (mFShaderHandle == 0) {
      return 0;
    }

    int program = GLES20.glCreateProgram();
    if (program != 0) {
      GLES20.glAttachShader(program, mVShaderHandle);
      GLES20.glAttachShader(program, mFShaderHandle);
      GLES20.glLinkProgram(program);

      int[] linkStatus = new int[1];
      GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
      if (linkStatus[0] != GLES20.GL_TRUE) {
        RajLog.e("Could not link program in " + getClass().getCanonicalName() + ": ");
        RajLog.e(GLES20.glGetProgramInfoLog(program));
        GLES20.glDeleteProgram(program);
        program = 0;
      }
    }
    return program;
  }
예제 #14
0
  /**
   * Creates a new program from the supplied vertex and fragment shaders.
   *
   * @return A handle to the program, or 0 on failure.
   */
  public static int createProgram(String vertexSource, String fragmentSource) {
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    if (vertexShader == 0) {
      return 0;
    }
    int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    if (pixelShader == 0) {
      return 0;
    }

    int program = GLES20.glCreateProgram();
    checkGlError("glCreateProgram");
    if (program == 0) {
      Log.e(TAG, "Could not create program");
    }
    GLES20.glAttachShader(program, vertexShader);
    checkGlError("glAttachShader");
    GLES20.glAttachShader(program, pixelShader);
    checkGlError("glAttachShader");
    GLES20.glLinkProgram(program);
    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] != GLES20.GL_TRUE) {
      Log.e(TAG, "Could not link program: ");
      Log.e(TAG, GLES20.glGetProgramInfoLog(program));
      GLES20.glDeleteProgram(program);
      program = 0;
    }
    return program;
  }
예제 #15
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");
  }
예제 #16
0
  public Triangle(PointF center, boolean reflec) {

    this.reflec = reflec;
    // this.bmp = bmp;
    this.center = center;

    computePoints(center, /*bmp.getWidth() * 0.8888f fix it later */ 0.2f);

    Lados = new ArrayList();
    // In counterclockwise order v1,v2; v3,v2; v3,v1
    Lados.add(
        new Recta(triangleCoords[0], triangleCoords[1], triangleCoords[2], triangleCoords[3]));
    Lados.add(
        new Recta(triangleCoords[4], triangleCoords[5], triangleCoords[2], triangleCoords[3]));
    Lados.add(
        new Recta(triangleCoords[4], triangleCoords[5], triangleCoords[0], triangleCoords[1]));

    // x=center.x - bmp.getWidth()/ 2;
    // y=center.y + peq + bmp.getHeight()*0.125f;

    // initialize vertex byte buffer for shape coordinates
    ByteBuffer bb =
        ByteBuffer.allocateDirect(
            // (number of coordinate values * 4 bytes per float)
            triangleCoords.length * 4);
    // use the device hardware's native byte order
    bb.order(ByteOrder.nativeOrder());

    // create a floating point buffer from the ByteBuffer
    vertexBuffer = bb.asFloatBuffer();
    // add the coordinates to the FloatBuffer
    vertexBuffer.put(triangleCoords);
    // set the buffer to read the first coordinate
    vertexBuffer.position(0);

    // To render vertices
    int vertexShader = MyGLRenderer.loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
    // To render faces
    int fragmentShader = MyGLRenderer.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);

    // create empty OpenGL ES Program
    mProgram = GLES20.glCreateProgram();

    // add the vertex shader to program
    GLES20.glAttachShader(mProgram, vertexShader);

    // add the fragment shader to program
    GLES20.glAttachShader(mProgram, fragmentShader);

    // creates OpenGL ES program executables
    GLES20.glLinkProgram(mProgram);
  }
예제 #17
0
  public static int getProgram(String vsSrc, String fsSrc) {
    // vertexShaderのコンパイル
    int vs = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
    GLES20.glShaderSource(vs, vsSrc);
    GLES20.glCompileShader(vs);

    // コンパイルチェック
    final int[] vsCompileStatus = new int[1];
    GLES20.glGetShaderiv(vs, GLES20.GL_COMPILE_STATUS, vsCompileStatus, 0);

    if (vsCompileStatus[0] == 0) {
      // コンパイル失敗
      GLES20.glDeleteShader(vs);
      vs = 0;
      // ログにエラーを出力
      Log.d("debug", "VERTEXSHADER_COMPILE_ERROR");
    }

    // fragmentShaderのコンパイル
    int fs = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);
    GLES20.glShaderSource(fs, fsSrc);
    GLES20.glCompileShader(fs);

    // コンパイルチェック
    final int[] fsCompileStatus = new int[1];
    GLES20.glGetShaderiv(fs, GLES20.GL_COMPILE_STATUS, fsCompileStatus, 0);

    if (fsCompileStatus[0] == 0) {
      // コンパイル失敗
      GLES20.glDeleteShader(fs);
      fs = 0;
      Log.d("debug", "FRAGMENTSHADER_COMPILE_ERROR");
    }

    // shaderをリンクしてProgramを作る
    int shaderProgram;
    shaderProgram = GLES20.glCreateProgram();
    GLES20.glAttachShader(shaderProgram, vs);
    GLES20.glAttachShader(shaderProgram, fs);
    GLES20.glLinkProgram(shaderProgram);

    // リンク結果をチェック
    final int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(shaderProgram, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] == 0) {
      // リンク失敗
      GLES20.glDeleteProgram(shaderProgram);
      shaderProgram = 0;
      Log.d("debug", "LINK_ERROR");
    }
    return shaderProgram;
  }
예제 #18
0
  public Cube(Bitmap b) {
    // initialize buffer for vertex coordinates
    ByteBuffer vpb =
        ByteBuffer.allocateDirect(
            // (# of coordinate values * 4 bytes per float)
            faceCoords.length * 4);
    vpb.order(ByteOrder.nativeOrder());
    vertexBuffer = vpb.asFloatBuffer();
    vertexBuffer.put(faceCoords);
    vertexBuffer.position(0);

    // initialize buffer for vertex normals
    ByteBuffer vnb =
        ByteBuffer.allocateDirect(
            // (# of coordinate values * 4 bytes per float)
            normals.length * 4);
    vnb.order(ByteOrder.nativeOrder());
    normalBuffer = vnb.asFloatBuffer();
    normalBuffer.put(normals);
    normalBuffer.position(0);

    // initialize buffer for UV Coordinates
    ByteBuffer uvb =
        ByteBuffer.allocateDirect(
            // (# of coordinate values * 4 bytes per float)
            uvs.length * 4);
    uvb.order(ByteOrder.nativeOrder());
    uvBuffer = uvb.asFloatBuffer();
    uvBuffer.put(uvs);
    uvBuffer.position(0);

    // initialize byte buffer for the draw list
    ByteBuffer dlb =
        ByteBuffer.allocateDirect(
            // (# of coordinate values * 2 bytes per short)
            drawOrder.length * 2);
    dlb.order(ByteOrder.nativeOrder());
    drawListBuffer = dlb.asShortBuffer();
    drawListBuffer.put(drawOrder);
    drawListBuffer.position(0);

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

    shaderProgram = GLES20.glCreateProgram();
    GLES20.glAttachShader(shaderProgram, vertexShader);
    GLES20.glAttachShader(shaderProgram, fragmentShader);
    GLES20.glLinkProgram(shaderProgram);

    loadTexture(b);
  }
예제 #19
0
  public MarkerTile(float mx, float my, float sx, float sy, int texture) {
    midx = mx;
    midy = my;
    sizx = sx;
    sizy = sy;

    midOx = mx;
    midOy = my;
    sizOx = sx;
    sizOy = sy;

    midTx = mx;
    midTy = my;
    sizTx = sx;
    sizTy = sy;

    textureRef = texture;

    int vertexInfoShader =
        XQGLRenderer.loadShader(GLES20.GL_VERTEX_SHADER, vertexInfoTileShaderCode);
    int fragmentInfoShader =
        XQGLRenderer.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentInfoTileShaderCode);

    mProgram = GLES20.glCreateProgram();

    // add the vertex shader to program
    GLES20.glAttachShader(mProgram, vertexInfoShader);

    // add the fragment shader to program
    GLES20.glAttachShader(mProgram, fragmentInfoShader);

    // creates OpenGL ES program executables
    GLES20.glLinkProgram(mProgram);

    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(tileCoords.length * 4);
    byteBuffer.order(ByteOrder.nativeOrder());
    vertexBuffer = byteBuffer.asFloatBuffer();
    vertexBuffer.put(tileCoords);
    vertexBuffer.position(0);
    byteBuffer = ByteBuffer.allocateDirect(drawOrder.length * 4);
    byteBuffer.order(ByteOrder.nativeOrder());
    indexBuffer = byteBuffer.asShortBuffer();
    indexBuffer.put(drawOrder);
    indexBuffer.position(0);
    byteBuffer = ByteBuffer.allocateDirect(TextureCoords.length * 4);
    byteBuffer.order(ByteOrder.nativeOrder());
    textureBuffer = byteBuffer.asFloatBuffer();
    textureBuffer.put(TextureCoords);
    textureBuffer.position(0);
  }
예제 #20
0
 public void init(int... shader) {
   programID = GLES20.glCreateProgram();
   for (int i : shader) {
     GLES20.glAttachShader(programID, i);
     GLES20.glDeleteShader(i);
   }
   GLES20.glLinkProgram(programID);
 }
예제 #21
0
    void build() {

      vertexCount = vertexCoords.length / COORDS_PER_VERTEX;
      vertexStride = COORDS_PER_VERTEX * 4;
      ByteBuffer bb = ByteBuffer.allocateDirect(vertexCoords.length * 4);
      bb.order(ByteOrder.nativeOrder());
      vertexBuffer = bb.asFloatBuffer();
      vertexBuffer.put(vertexCoords);
      vertexBuffer.position(0);
      int vertexShader = glObjects.loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
      int fragmentShader = glObjects.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); // create OpenGL program executables
    }
예제 #22
0
  /**
   * Links a vertex shader and a fragment shader together into an OpenGL program. Returns the OpenGL
   * program object ID, or 0 if linking failed.
   */
  public static int linkProgram(int vertexShaderId, int fragmentShaderId) {

    // Create a new program object.
    final int programObjectId = GLES20.glCreateProgram();

    if (programObjectId == 0) {
      if (LoggerConfig.ON) {
        Log.w(TAG, "Could not create new program");
      }

      return 0;
    }

    // Attach the vertex shader to the program.
    glAttachShader(programObjectId, vertexShaderId);

    // Attach the fragment shader to the program.
    glAttachShader(programObjectId, fragmentShaderId);

    // Link the two shaders together into a program.
    glLinkProgram(programObjectId);

    // Get the link status.
    final int[] linkStatus = new int[1];
    glGetProgramiv(programObjectId, GLES20.GL_LINK_STATUS, linkStatus, 0);

    if (LoggerConfig.ON) {
      // Print the program info log to the Android log output.
      Log.v(TAG, "Results of linking program:\n" + GLES20.glGetProgramInfoLog(programObjectId));
    }

    // Verify the link status.
    if (linkStatus[0] == 0) {
      // If it failed, delete the program object.
      GLES20.glDeleteProgram(programObjectId);

      if (LoggerConfig.ON) {
        Log.w(TAG, "Linking of program failed.");
      }

      return 0;
    }

    // Return the program object ID.
    return programObjectId;
  }
 public static int linkProgram(int vsh, int fsh) {
   if (vsh == 0 || fsh == 0) {
     Log.e(TAG, "Invalid vertex shader and fragment shader");
     return 0;
   }
   int prog = GLES20.glCreateProgram();
   GLES20.glAttachShader(prog, vsh);
   GLES20.glAttachShader(prog, fsh);
   GLES20.glLinkProgram(prog);
   int[] status = new int[1];
   GLES20.glGetProgramiv(prog, GLES20.GL_LINK_STATUS, status, 0);
   Log.e(TAG, "link program " + GLES20.glGetProgramInfoLog(prog));
   if (status[0] == 0) {
     GLES20.glDeleteProgram(prog);
     return 0;
   }
   return prog;
 }
예제 #24
0
 public static int createProgram(String vertexSource, String fragmentSource) {
   int vs = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
   int fs = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
   int program = GLES20.glCreateProgram();
   GLES20.glAttachShader(program, vs);
   GLES20.glAttachShader(program, fs);
   GLES20.glLinkProgram(program);
   //
   int[] linkStatus = new int[1];
   GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
   if (linkStatus[0] != GLES20.GL_TRUE) {
     Log.e(TAG, "Could not link program:");
     Log.e(TAG, GLES20.glGetProgramInfoLog(program));
     GLES20.glDeleteProgram(program);
     program = 0;
   }
   //
   return program;
 }
예제 #25
0
  public CloudElem(Renderer3D s3D, float[] v, float[] oscDir, float[] oscPhase, float[] color) {
    scene = s3D;
    int vertexShader;
    if (oscDir.length == 0) {
      vertexShader = GLESUtils.loadShader(GLES20.GL_VERTEX_SHADER, nonMovingVerts());
    }

    if (color.length == 4) {
      c = color;
    } else {
      c = new float[4];
      c[0] = 0.95f;
      c[1] = 0.95f;
      c[2] = 0.95f;
      c[3] = 0.8f;
    }

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

    shaderProgram = GLES20.glCreateProgram();
    GLES20.glAttachShader(shaderProgram, vertexShader);
    GLES20.glAttachShader(shaderProgram, fragmentShader);
    GLES20.glLinkProgram(shaderProgram);

    short[] order = new short[NumVerts];
    oBufferLength = NumVerts;
    for (int i = 0; i < NumVerts; i++) {
      order[i] = (short) i;
    }

    posBuffer = GLESUtils.packBuffer(NumVerts * CpV, v);
    if (oscDir.length > 0) {
      normalBuffer = GLESUtils.packBuffer(NumVerts * CpV, oscDir);
      phaseBuffer = GLESUtils.packBuffer(NumVerts, oscPhase);
    } else {
      float[] nullBuf = new float[NumVerts * CpV];
      float[] nulleBuf = new float[NumVerts];
      normalBuffer = GLESUtils.packBuffer(NumVerts * CpV, nullBuf);
      phaseBuffer = GLESUtils.packBuffer(NumVerts, nulleBuf);
    }
    orderBuffer = GLESUtils.packBuffer(NumVerts, order);
  }
예제 #26
0
  public void onSurfaceCreated(GL10 unused, javax.microedition.khronos.egl.EGLConfig config) {

    Log.i("MyGLRenderer", "MyGLRenderer : onSurfaceCreated() - Entered onSurfaceCreated");
    // Set the background frame color
    GLES20.glClearColor(1.0f, 0.6f, 0.0f, 1.0f);

    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
    int fragmentShader = loadShader(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); // creates OpenGL ES program executables

    // initialize a triangle
    Log.i("MyGLRenderer", "MyGLRenderer : onSurfaceCreated() - Creating new triangle object");
    mTriangle = new Triangle(mProgram);
    Log.i("MyGLRenderer", "MyGLRenderer : onSurfaceCreated() - New Triangle object created");
  }
예제 #27
0
  public Triangle() {
    // inicializando o vetor de bytes para a forma que sera desenha
    // tamanho do vetor de coordenadas * 4 butes para cada float
    ByteBuffer bbuffer = ByteBuffer.allocateDirect(formCoordenates.length * 4);
    // Hardware ByteOrder
    bbuffer.order(ByteOrder.nativeOrder());
    this.vertexBuffer = bbuffer.asFloatBuffer();
    this.vertexBuffer.put(formCoordenates);
    // definindo o buffer para posicao zero para ser lido a primeira coordenada
    this.vertexBuffer.position(0);

    int verTexShader = GLRenderImpl.loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
    int fragmentShader = GLRenderImpl.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);
    // criando um OpenGL ES program vazio
    compiledShader = GLES20.glCreateProgram();
    GLES20.glAttachShader(compiledShader, verTexShader);
    GLES20.glAttachShader(compiledShader, fragmentShader);
    // criando um OpenGL ES program executavel
    GLES20.glLinkProgram(compiledShader);
  }
예제 #28
0
파일: Scene.java 프로젝트: Karm/galgs
  public Scene(PointsRenderer pointsRenderer, GAlg galg) {
    this.pointsRenderer = pointsRenderer;
    this.rubyAlgorithms = new RubyAlgorithms();
    this.galg = galg;

    newVertexBufferToDraw();
    // prepare shaders and OpenGL program
    int vertexShader = PointsRenderer.loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
    int fragmentShader = PointsRenderer.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);
    mProgram = GLES20.glCreateProgram(); // create empty OpenGL Program
    mLinesProgram = 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); // create OpenGL program executables
    // Hmm, let'suse the same shaders for this. TODO: Really?
    // TODO: This is weird... :-(
    GLES20.glAttachShader(mLinesProgram, vertexShader); // add the vertex shader to program
    GLES20.glAttachShader(mLinesProgram, fragmentShader); // add the fragment shader to program
    GLES20.glLinkProgram(mLinesProgram); // create OpenGL program executables
  }
 // Compile & attach a |type| shader specified by |source| to |program|.
 private static void addShaderTo(int type, String source, int program) {
   int[] result = new int[] {GLES20.GL_FALSE};
   int shader = GLES20.glCreateShader(type);
   GLES20.glShaderSource(shader, source);
   GLES20.glCompileShader(shader);
   GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, result, 0);
   abortUnless(
       result[0] == GLES20.GL_TRUE, GLES20.glGetShaderInfoLog(shader) + ", source: " + source);
   GLES20.glAttachShader(program, shader);
   GLES20.glDeleteShader(shader);
   checkNoGLES2Error();
 }
예제 #30
0
  public Cube() {
    // Prepare shaders and OpenGL program
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, VERTEX_SHADER_CODE);
    if (vertexShader == 0) {
      Log.e(TAG, "Vertex shader failed");
      return;
    }
    int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER_CODE);
    if (fragmentShader == 0) {
      Log.e(TAG, "Fragment shader failed");
      return;
    }

    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); // create OpenGL program executables

    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(mProgram, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] != GLES20.GL_TRUE) {
      Log.e(TAG, "Could not link program: ");
      Log.e(TAG, GLES20.glGetProgramInfoLog(mProgram));
      GLES20.glDeleteProgram(mProgram);
      mProgram = 0;
      return;
    }
    GLES20.glDeleteShader(vertexShader);
    GLES20.glDeleteShader(fragmentShader);

    // Initialize vertex byte buffer for shape coordinates
    mVertexBuffer = allocateFloatBuffer(VERTICES);

    // Initialize byte buffer for the colors
    mColor1Buffer = allocateFloatBuffer(COLORS1);
    mColor2Buffer = allocateFloatBuffer(COLORS2);

    // Initialize byte buffer for the draw list
    mIndexBuffer = allocateShortBuffer(INDICES);
  }