List of usage examples for android.opengl GLES20 glClearColor
public static native void glClearColor(float red, float green, float blue, float alpha);
From source file:com.sveder.cardboardpassthrough.MainActivity.java
/** * 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. *///from w w w. java 2 s.co m @Override public void onSurfaceCreated(EGLConfig config) { Log.i(TAG, "onSurfaceCreated"); GLES20.glClearColor(0.1f, 0.1f, 0.1f, 0.5f); // Dark background so text shows up well 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); texture = createTexture(); startCamera(texture); // ByteBuffer bbVertices = ByteBuffer.allocateDirect(DATA.CUBE_COORDS.length * 4); // bbVertices.order(ByteOrder.nativeOrder()); // mCubeVertices = bbVertices.asFloatBuffer(); // mCubeVertices.put(DATA.CUBE_COORDS); // mCubeVertices.position(0); // // ByteBuffer bbColors = ByteBuffer.allocateDirect(DATA.CUBE_COLORS.length * 4); // bbColors.order(ByteOrder.nativeOrder()); // mCubeColors = bbColors.asFloatBuffer(); // mCubeColors.put(DATA.CUBE_COLORS); // mCubeColors.position(0); // // ByteBuffer bbFoundColors = ByteBuffer.allocateDirect(DATA.CUBE_FOUND_COLORS.length * 4); // bbFoundColors.order(ByteOrder.nativeOrder()); // mCubeFoundColors = bbFoundColors.asFloatBuffer(); // mCubeFoundColors.put(DATA.CUBE_FOUND_COLORS); // mCubeFoundColors.position(0); // // ByteBuffer bbNormals = ByteBuffer.allocateDirect(DATA.CUBE_NORMALS.length * 4); // bbNormals.order(ByteOrder.nativeOrder()); // mCubeNormals = bbNormals.asFloatBuffer(); // mCubeNormals.put(DATA.CUBE_NORMALS); // mCubeNormals.position(0); // // // make a floor // ByteBuffer bbFloorVertices = ByteBuffer.allocateDirect(DATA.FLOOR_COORDS.length * 4); // bbFloorVertices.order(ByteOrder.nativeOrder()); // mFloorVertices = bbFloorVertices.asFloatBuffer(); // mFloorVertices.put(DATA.FLOOR_COORDS); // mFloorVertices.position(0); // // ByteBuffer bbFloorNormals = ByteBuffer.allocateDirect(DATA.FLOOR_NORMALS.length * 4); // bbFloorNormals.order(ByteOrder.nativeOrder()); // mFloorNormals = bbFloorNormals.asFloatBuffer(); // mFloorNormals.put(DATA.FLOOR_NORMALS); // mFloorNormals.position(0); // // ByteBuffer bbFloorColors = ByteBuffer.allocateDirect(DATA.FLOOR_COLORS.length * 4); // bbFloorColors.order(ByteOrder.nativeOrder()); // mFloorColors = bbFloorColors.asFloatBuffer(); // mFloorColors.put(DATA.FLOOR_COLORS); // mFloorColors.position(0); // // int vertexShader = loadGLShader(GLES20.GL_VERTEX_SHADER, R.raw.light_vertex); // int gridShader = loadGLShader(GLES20.GL_FRAGMENT_SHADER, R.raw.grid_fragment); // // mGlProgram = GLES20.glCreateProgram(); // GLES20.glAttachShader(mGlProgram, vertexShader); // GLES20.glAttachShader(mGlProgram, gridShader); // GLES20.glLinkProgram(mGlProgram); // // GLES20.glEnable(GLES20.GL_DEPTH_TEST); // // // Object first appears directly in front of user // Matrix.setIdentityM(mModelCube, 0); // Matrix.translateM(mModelCube, 0, 0, 0, -mObjectDistance); // // Matrix.setIdentityM(mModelFloor, 0); // Matrix.translateM(mModelFloor, 0, 0, -mFloorDepth, 0); // Floor appears below user // // checkGLError("onSurfaceCreated"); }
From source file:com.aimfire.gallery.cardboard.PhotoActivity.java
@Override public void onSurfaceCreated(EGLConfig config) { if (BuildConfig.DEBUG) Log.i(TAG, "onSurfaceCreated"); /*/*from w ww .jav a 2 s. c om*/ * Dark background so text shows up well. */ GLES20.glClearColor(0.1f, 0.1f, 0.1f, 0.5f); ByteBuffer bbElements = ByteBuffer.allocateDirect(drawOrder.length * 2); bbElements.order(ByteOrder.nativeOrder()); mPicElements = bbElements.asShortBuffer(); mPicElements.put(drawOrder); mPicElements.position(0); int vertexShader = loadGLShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode); int fragmentShader = loadGLShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode); mPicProgram = GLES20.glCreateProgram(); GLES20.glAttachShader(mPicProgram, vertexShader); GLES20.glAttachShader(mPicProgram, fragmentShader); GLES20.glLinkProgram(mPicProgram); GLES20.glUseProgram(mPicProgram); checkGLError("Pic program"); mDimRatioParam = GLES20.glGetUniformLocation(mPicProgram, "u_dimRatio"); mZoomParam = GLES20.glGetUniformLocation(mPicProgram, "u_zoom"); mParallaxParam = GLES20.glGetUniformLocation(mPicProgram, "u_parallax"); mPicPositionParam = GLES20.glGetAttribLocation(mPicProgram, "a_position"); GLES20.glEnableVertexAttribArray(mPicPositionParam); checkGLError("Pic program params"); GLES20.glEnable(GLES20.GL_DEPTH_TEST); checkGLError("onSurfaceCreated"); /* * initializes a few textures (current, previous and next). we have to do this * here (as opposed to onCreate) as gl context is only available here */ initTextures(); /* * so onDrawEye will know to draw */ mAssetChangedLeft = mAssetChangedRight = true; }