Java Code Examples for android.opengl.GLES30#glLinkProgram()
The following examples show how to use
android.opengl.GLES30#glLinkProgram() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java From alynx-live-wallpaper with Apache License 2.0 | 6 votes |
static int linkProgramGLES30( final int vertShader, final int fragShader ) throws RuntimeException { int program = GLES30.glCreateProgram(); if (program == 0) { throw new RuntimeException("Failed to create program"); } GLES30.glAttachShader(program, vertShader); GLES30.glAttachShader(program, fragShader); GLES30.glLinkProgram(program); final int[] status = new int[1]; GLES30.glGetProgramiv(program, GLES30.GL_LINK_STATUS, status, 0); if (status[0] == 0) { final String log = GLES30.glGetProgramInfoLog(program); GLES30.glDeleteProgram(program); throw new RuntimeException(log); } return program; }
Example 2
Source File: GLHelper.java From libcommon with Apache License 2.0 | 5 votes |
/** * 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:"); final int[] compiled = new int[1]; // 頂点シェーダーをコンパイル final int vs = loadShader(GLES30.GL_VERTEX_SHADER, vss); if (vs == 0) { Log.d(TAG, "loadShader:failed to compile vertex shader,\n" + vss); return 0; } // フラグメントシェーダーをコンパイル int fs = loadShader(GLES30.GL_FRAGMENT_SHADER, fss); if (fs == 0) { Log.d(TAG, "loadShader:failed to compile fragment shader,\n" + fss); return 0; } // リンク final int program = GLES30.glCreateProgram(); checkGlError("glCreateProgram"); if (program == 0) { Log.e(TAG, "Could not create program"); } GLES30.glAttachShader(program, vs); checkGlError("glAttachShader"); GLES30.glAttachShader(program, fs); checkGlError("glAttachShader"); GLES30.glLinkProgram(program); final int[] linkStatus = new int[1]; GLES30.glGetProgramiv(program, GLES30.GL_LINK_STATUS, linkStatus, 0); if (linkStatus[0] != GLES30.GL_TRUE) { Log.e(TAG, "Could not link program: "); Log.e(TAG, GLES30.glGetProgramInfoLog(program)); GLES30.glDeleteProgram(program); return 0; } return program; }
Example 3
Source File: Square.java From opengl with Apache License 2.0 | 5 votes |
/** * Sets up the drawing object data for use in an OpenGL ES context. */ 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( GLES30.GL_VERTEX_SHADER, vertexShaderCode); int fragmentShader = MyGLRenderer.loadShader( GLES30.GL_FRAGMENT_SHADER, fragmentShaderCode); mProgram = GLES30.glCreateProgram(); // create empty OpenGL Program GLES30.glAttachShader(mProgram, vertexShader); // add the vertex shader to program GLES30.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program GLES30.glLinkProgram(mProgram); // create OpenGL program executables }
Example 4
Source File: Triangle.java From opengl with Apache License 2.0 | 5 votes |
/** * Sets up the drawing object data for use in an OpenGL ES context. */ 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); // prepare shaders and OpenGL program int vertexShader = MyGLRenderer.loadShader( GLES30.GL_VERTEX_SHADER, vertexShaderCode); int fragmentShader = MyGLRenderer.loadShader( GLES30.GL_FRAGMENT_SHADER, fragmentShaderCode); mProgram = GLES30.glCreateProgram(); // create empty OpenGL Program GLES30.glAttachShader(mProgram, vertexShader); // add the vertex shader to program GLES30.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program GLES30.glLinkProgram(mProgram); // create OpenGL program executables }
Example 5
Source File: Pyramid.java From opengl with Apache License 2.0 | 4 votes |
public Pyramid() { //first setup the mVertices correctly. mVertices = ByteBuffer .allocateDirect(mVerticesData.length * 4) .order(ByteOrder.nativeOrder()) .asFloatBuffer() .put(mVerticesData); mVertices.position(0); //setup the shaders int vertexShader; int fragmentShader; int programObject; int[] linked = new int[1]; // Load the vertex/fragment shaders vertexShader = myRenderer.LoadShader(GLES30.GL_VERTEX_SHADER, vShaderStr); fragmentShader = myRenderer.LoadShader(GLES30.GL_FRAGMENT_SHADER, fShaderStr); // Create the program object programObject = GLES30.glCreateProgram(); if (programObject == 0) { Log.e(TAG, "So some kind of error, but what?"); return; } GLES30.glAttachShader(programObject, vertexShader); GLES30.glAttachShader(programObject, fragmentShader); // Bind vPosition to attribute 0 GLES30.glBindAttribLocation(programObject, 0, "vPosition"); // Link the program GLES30.glLinkProgram(programObject); // Check the link status GLES30.glGetProgramiv(programObject, GLES30.GL_LINK_STATUS, linked, 0); if (linked[0] == 0) { Log.e(TAG, "Error linking program:"); Log.e(TAG, GLES30.glGetProgramInfoLog(programObject)); GLES30.glDeleteProgram(programObject); return; } // Store the program object mProgramObject = programObject; //now everything is setup and ready to draw. }
Example 6
Source File: HelloTriangleRenderer.java From opengl with Apache License 2.0 | 4 votes |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) { String vShaderStr = "#version 300 es \n" + "in vec4 vPosition; \n" + "void main() \n" + "{ \n" + " gl_Position = vPosition; \n" + "} \n"; //a red ise 1.0, 0.0, 0.0, 1.0 but I prefer blue. String fShaderStr = "#version 300 es \n" + "precision mediump float; \n" + "out vec4 fragColor; \n" + "void main() \n" + "{ \n" + " fragColor = vec4 ( 0.0, 0.0, 1.0, 1.0 ); \n" + "} \n"; int vertexShader; int fragmentShader; int programObject; int[] linked = new int[1]; // Load the vertex/fragment shaders vertexShader = LoadShader(GLES30.GL_VERTEX_SHADER, vShaderStr); fragmentShader = LoadShader(GLES30.GL_FRAGMENT_SHADER, fShaderStr); // Create the program object programObject = GLES30.glCreateProgram(); if (programObject == 0) { return; } GLES30.glAttachShader(programObject, vertexShader); GLES30.glAttachShader(programObject, fragmentShader); // Bind vPosition to attribute 0 GLES30.glBindAttribLocation(programObject, 0, "vPosition"); // Link the program GLES30.glLinkProgram(programObject); // Check the link status GLES30.glGetProgramiv(programObject, GLES30.GL_LINK_STATUS, linked, 0); if (linked[0] == 0) { Log.e(TAG, "Error linking program:"); Log.e(TAG, GLES30.glGetProgramInfoLog(programObject)); GLES30.glDeleteProgram(programObject); return; } // Store the program object mProgramObject = programObject; //set the clear buffer color to white. GLES30.glClearColor(1.0f, 1.0f, 1.0f, 0.0f); }
Example 7
Source File: Cube.java From opengl with Apache License 2.0 | 4 votes |
public Cube() { //first setup the mVertices correctly. mVertices = ByteBuffer .allocateDirect(mVerticesData.length * 4) .order(ByteOrder.nativeOrder()) .asFloatBuffer() .put(mVerticesData); mVertices.position(0); //setup the shaders int vertexShader; int fragmentShader; int programObject; int[] linked = new int[1]; // Load the vertex/fragment shaders vertexShader = myRenderer.LoadShader(GLES30.GL_VERTEX_SHADER, vShaderStr); fragmentShader = myRenderer.LoadShader(GLES30.GL_FRAGMENT_SHADER, fShaderStr); // Create the program object programObject = GLES30.glCreateProgram(); if (programObject == 0) { Log.e(TAG, "So some kind of error, but what?"); return; } GLES30.glAttachShader(programObject, vertexShader); GLES30.glAttachShader(programObject, fragmentShader); // Bind vPosition to attribute 0 GLES30.glBindAttribLocation(programObject, 0, "vPosition"); // Link the program GLES30.glLinkProgram(programObject); // Check the link status GLES30.glGetProgramiv(programObject, GLES30.GL_LINK_STATUS, linked, 0); if (linked[0] == 0) { Log.e(TAG, "Error linking program:"); Log.e(TAG, GLES30.glGetProgramInfoLog(programObject)); GLES30.glDeleteProgram(programObject); return; } // Store the program object mProgramObject = programObject; //now everything is setup and ready to draw. }
Example 8
Source File: Cube.java From opengl with Apache License 2.0 | 4 votes |
public Cube() { //first setup the mVertices correctly. mVertices = ByteBuffer .allocateDirect(mVerticesData.length * 4) .order(ByteOrder.nativeOrder()) .asFloatBuffer() .put(mVerticesData); mVertices.position(0); //setup the shaders int vertexShader; int fragmentShader; int programObject; int[] linked = new int[1]; // Load the vertex/fragment shaders vertexShader = myRenderer.LoadShader(GLES30.GL_VERTEX_SHADER, vShaderStr); fragmentShader = myRenderer.LoadShader(GLES30.GL_FRAGMENT_SHADER, fShaderStr); // Create the program object programObject = GLES30.glCreateProgram(); if (programObject == 0) { Log.e(TAG, "So some kind of error, but what?"); return; } GLES30.glAttachShader(programObject, vertexShader); GLES30.glAttachShader(programObject, fragmentShader); // Bind vPosition to attribute 0 GLES30.glBindAttribLocation(programObject, 0, "vPosition"); // Link the program GLES30.glLinkProgram(programObject); // Check the link status GLES30.glGetProgramiv(programObject, GLES30.GL_LINK_STATUS, linked, 0); if (linked[0] == 0) { Log.e(TAG, "Error linking program:"); Log.e(TAG, GLES30.glGetProgramInfoLog(programObject)); GLES30.glDeleteProgram(programObject); return; } // Store the program object mProgramObject = programObject; //now everything is setup and ready to draw. }