Java Code Examples for android.opengl.GLES30#glBindAttribLocation()

The following examples show how to use android.opengl.GLES30#glBindAttribLocation() . 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: Pyramid.java    From opengl with Apache License 2.0 4 votes vote down vote up
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 2
Source File: HelloTriangleRenderer.java    From opengl with Apache License 2.0 4 votes vote down vote up
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 3
Source File: Cube.java    From opengl with Apache License 2.0 4 votes vote down vote up
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 4
Source File: Cube.java    From opengl with Apache License 2.0 4 votes vote down vote up
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.
}