javax.microedition.khronos.opengles.GL10 Java Examples

The following examples show how to use javax.microedition.khronos.opengles.GL10. 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: MainActivity.java    From AndroidPlayground with MIT License 6 votes vote down vote up
@Override
public void onDrawFrame(GL10 unused) {
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    GLES20.glUseProgram(mProgram);

    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glVertexAttribPointer(mPositionHandle, 3, GLES20.GL_FLOAT, false, 0,
            mVertexBuffer);

    GLES20.glEnableVertexAttribArray(mTexCoordHandle);
    GLES20.glVertexAttribPointer(mTexCoordHandle, 2, GLES20.GL_FLOAT, false, 0,
            mUvTexVertexBuffer);

    GLES20.glUniformMatrix4fv(mMatrixHandle, 1, false, mMVPMatrix, 0);
    GLES20.glUniform1i(mTexSamplerHandle, 0);

    GLES20.glDrawElements(GLES20.GL_TRIANGLES, VERTEX_INDEX.length,
            GLES20.GL_UNSIGNED_SHORT, mVertexIndexBuffer);

    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glDisableVertexAttribArray(mTexCoordHandle);

    //Utils.sendImage(mWidth, mHeight);
}
 
Example #2
Source File: HQWaveformVisualizerSurfaceView.java    From android-openslmediaplayer with Apache License 2.0 6 votes vote down vote up
private static void drawWaveForm(
        GL10 gl, int width, int height,
        FloatBuffer vertices, int n, int vposition, float yrange, FloatColor color) {

    gl.glPushMatrix();

    // viewport
    gl.glViewport(0, (height / 2) * (1 - vposition), width, (height / 2));

    // X: [0:1], Y: [-1:+1] (scaled)
    gl.glOrthof(0.0f, 1.0f, -yrange, yrange, -1.0f, 1.0f);

    gl.glColor4f(color.red, color.green, color.blue, color.alpha);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(2, GL10.GL_FLOAT, (2 * Float.SIZE / 8), vertices);
    gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, n);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

    gl.glPopMatrix();
}
 
Example #3
Source File: GlFrameBufferObjectRenderer.java    From CameraRecorder-android with MIT License 6 votes vote down vote up
@Override
public final void onDrawFrame(final GL10 gl) {
    synchronized (runOnDraw) {
        while (!runOnDraw.isEmpty()) {
            runOnDraw.poll().run();
        }
    }
    framebufferObject.enable();

    onDrawFrame(framebufferObject);

    GLES20.glBindFramebuffer(GL_FRAMEBUFFER, 0);

    GLES20.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    normalShader.draw(framebufferObject.getTexName(), null);

}
 
Example #4
Source File: CubeSmallGLUT.java    From opengl with Apache License 2.0 6 votes vote down vote up
void drawSimpleCube (GL10 gl) {
    float vertices[] = {
            -1,1,1, 1,1,1, 1,-1,1, -1,-1,1,
            1,1,-1, -1,1,-1, -1,-1,-1, 1,-1,-1
    };
    byte indices[] = {
            0,1,2, 2,3,0,  1,4,7, 7,2,1,  0,3,6, 6,5,0,
            3,2,7, 7,6,3,  0,1,4, 4,5,0,  5,6,7, 7,4,5
    };
    FloatBuffer vertexBuffer = getFloatBufferFromFloatArray(vertices);
    ByteBuffer indexBuffer = getByteBufferFromByteArray(indices);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
    gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_BYTE, indexBuffer);
    //gl.glDrawElements(GL10.GL_LINE_LOOP, indices.length, GL10.GL_UNSIGNED_BYTE, indexBuffer);
    
}
 
Example #5
Source File: Game.java    From remixed-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    GLES20.glEnable(GL10.GL_BLEND);
    GLES20.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

    GLES20.glEnable(GL10.GL_SCISSOR_TEST);


    SystemText.invalidate();
    TextureCache.reload();

    paused = false;

    if (scene != null) {
        scene.resume();
    }
}
 
Example #6
Source File: GLSurfaceView.java    From NewsMe with Apache License 2.0 6 votes vote down vote up
public synchronized void checkGLDriver(GL10 gl) {
	if (!mGLESDriverCheckComplete) {
		checkGLESVersion();
		String renderer = gl.glGetString(GL10.GL_RENDERER);
		if (mGLESVersion < kGLES_20) {
			mMultipleGLESContextsAllowed = !renderer
					.startsWith(kMSM7K_RENDERER_PREFIX);
			notifyAll();
		}
		mLimitedGLESContexts = !mMultipleGLESContextsAllowed
				|| renderer.startsWith(kADRENO);
		if (LOG_SURFACE) {
			Log.w(TAG, "checkGLDriver renderer = \"" + renderer
					+ "\" multipleContextsAllowed = "
					+ mMultipleGLESContextsAllowed
					+ " mLimitedGLESContexts = " + mLimitedGLESContexts);
		}
		mGLESDriverCheckComplete = true;
	}
}
 
Example #7
Source File: MediaEffectsFragment.java    From android-MediaEffects with Apache License 2.0 6 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {
    if (!mInitialized) {
        //Only need to do this once
        mEffectContext = EffectContext.createWithCurrentGlContext();
        mTexRenderer.init();
        loadTextures();
        mInitialized = true;
    }
    if (mCurrentEffect != R.id.none) {
        //if an effect is chosen initialize it and apply it to the texture
        initEffect();
        applyEffect();
    }
    renderResult();
}
 
Example #8
Source File: TexCubeSmallGLUT.java    From opengl with Apache License 2.0 6 votes vote down vote up
void setTex (GL10 gl, Context c, int textureID, int drawableID) {
mCoordBuffer = getFloatBufferFromFloatArray(texCoords);

mTextureID = textureID;

gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);

Bitmap bitmap = BitmapFactory.decodeResource(c.getResources(), drawableID);
Bitmap bitmap256 = Bitmap.createScaledBitmap(bitmap, 256, 256, false);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap256, 0);
bitmap.recycle();
bitmap256.recycle();

       gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
               GL10.GL_NEAREST);
       gl.glTexParameterf(GL10.GL_TEXTURE_2D,
               GL10.GL_TEXTURE_MAG_FILTER,
               GL10.GL_LINEAR);
       texEnabled = true;
       
   }
 
Example #9
Source File: GLWrapper.java    From PanoramaGL with Apache License 2.0 6 votes vote down vote up
/**init methods*/

public GLWrapper(GL gl, GLSurfaceView glSurfaceView)
{
	mGL = (GL10)gl;
	if(gl instanceof GL10Ext)
	{
           mGL10Ext = (GL10Ext)gl;
       }
       if(gl instanceof GL11)
       {
           mGL11 = (GL11)gl;
       }
       if(gl instanceof GL11Ext)
       {
           mGL11Ext = (GL11Ext)gl;
       }
       if(gl instanceof GL11ExtensionPack)
       {
       	mGL11ExtPack = (GL11ExtensionPack)gl;
       }
       mGLSurfaceView = glSurfaceView;
}
 
Example #10
Source File: LightingRenderer.java    From augmentedreality with Apache License 2.0 6 votes vote down vote up
public final void setupEnv(GL10 gl) {
	gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, ambientLightBuffer0);
	gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, diffuseLightBuffer0);
	gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_SPECULAR, specularLightBuffer0);
	gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPositionBuffer0);
	gl.glEnable(GL10.GL_LIGHT0);
	gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_AMBIENT, ambientLightBuffer1);
	gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_DIFFUSE, diffuseLightBuffer1);
	gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_SPECULAR, specularLightBuffer1);
	gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_POSITION, lightPositionBuffer1);
	gl.glEnable(GL10.GL_LIGHT1);
	gl.glLightfv(GL10.GL_LIGHT2, GL10.GL_AMBIENT, ambientLightBuffer2);
	gl.glLightfv(GL10.GL_LIGHT2, GL10.GL_DIFFUSE, diffuseLightBuffer2);
	gl.glLightfv(GL10.GL_LIGHT2, GL10.GL_SPECULAR, specularLightBuffer2);
	gl.glLightfv(GL10.GL_LIGHT2, GL10.GL_POSITION, lightPositionBuffer2);
	gl.glEnable(GL10.GL_LIGHT2);
	gl.glLightfv(GL10.GL_LIGHT3, GL10.GL_AMBIENT, ambientLightBuffer3);
	gl.glLightfv(GL10.GL_LIGHT3, GL10.GL_DIFFUSE, diffuseLightBuffer3);
	gl.glLightfv(GL10.GL_LIGHT3, GL10.GL_SPECULAR, specularLightBuffer3);
	gl.glLightfv(GL10.GL_LIGHT3, GL10.GL_POSITION, lightPositionBuffer3);
	gl.glEnable(GL10.GL_LIGHT3);
	initGL(gl);
}
 
Example #11
Source File: SolarSystemRenderer.java    From opengl with Apache License 2.0 6 votes vote down vote up
public void onDrawFrame(GL10 gl) 
{
     gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
     gl.glClearColor(0.0f,0.0f,0.0f,1.0f);
     gl.glMatrixMode(GL10.GL_MODELVIEW);
     gl.glLoadIdentity();
	
     gl.glTranslatef(0.0f,(float)Math.sin(mTransY), -4.0f);
	
     gl.glRotatef(mAngle, 1, 0, 0);
     gl.glRotatef(mAngle, 0, 1, 0);
		
     mPlanet.draw(gl);
	     
     mTransY+=.075f; 
     mAngle+=.4;
}
 
Example #12
Source File: OpenGLUtil.java    From MegviiFacepp-Android-SDK with Apache License 2.0 6 votes vote down vote up
public static int createTextureID() {
	int[] texture = new int[1];

	GLES20.glGenTextures(1, texture, 0);
	GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, texture[0]);
	GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
			GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
	GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
			GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
	GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
			GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
	GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
			GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);

	return texture[0];
}
 
Example #13
Source File: GLRender.java    From In77Camera with MIT License 6 votes vote down vote up
@Override
    public void onDrawFrame(GL10 glUnused) {
        long timeStamp=cameraEngine.doTextureUpdate(oesFilter.getSTMatrix());
        //filterGroup.setFboToRebind(fbo);
        filterGroup.onDrawFrame(oesFilter.getGlOESTexture().getTextureId());
        if(mVideoEncoder!=null){
            Log.d(TAG, "onDrawFrame: "+mVideoEncoder.toString());
            mVideoEncoder.frameAvailableSoon();
        }
        //TODO:正确的录像过程,生成的视频可以用MediaPlayer播放
//        fbo.unbind();
//        lastProcessFilter.setSavedTextureId(fbo.getFrameBufferTextureId());
//        screenDrawer.onFilterChanged(surfaceWidth,surfaceHeight);
        //screenDrawer.onDrawFrame(fbo.getFrameBufferTextureId());
        runPostDrawTasks();
    }
 
Example #14
Source File: GSYVideoGLViewCustomRender3.java    From GSYVideoPlayer with Apache License 2.0 6 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
    super.onSurfaceCreated(glUnused, config);

    Bitmap bitmap = BitmapFactory.decodeResource(mSurfaceView.getResources(), R.drawable.video_brightness_6_white_36dp);
    //创建bitmap
    GLES20.glGenTextures(1, mTexturesBitmap, 0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexturesBitmap[0]);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
            GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
            GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
            GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
            GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
    GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
    bitmap.recycle();
}
 
Example #15
Source File: CameraGLView.java    From TimeLapseRecordingSample with Apache License 2.0 6 votes vote down vote up
/**
 * drawing to GLSurface
 * we set renderMode to GLSurfaceView.RENDERMODE_WHEN_DIRTY,
 * this method is only called when #requestRender is called(= when texture is required to update)
 * if you don't set RENDERMODE_WHEN_DIRTY, this method is called at maximum 60fps
 */
@Override
public void onDrawFrame(GL10 unused) {
	GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

	if (requestUpdateTex) {
		requestUpdateTex = false;
		// update texture(came from camera)
		mSTexture.updateTexImage();
		// get texture matrix
		mSTexture.getTransformMatrix(mStMatrix);
	}
	// draw to preview screen
	mDrawer.draw(hTex, mStMatrix);
	flip = !flip;
	if (flip) {	// ~30fps
		synchronized (this) {
			if (mVideoEncoder != null) {
				// notify to capturing thread that the camera frame is available.
				mVideoEncoder.frameAvailableSoon(mStMatrix);
			}
		}
	}
}
 
Example #16
Source File: GLTextureView.java    From MD360Player4Android with Apache License 2.0 6 votes vote down vote up
public synchronized void checkGLDriver(GL10 gl) {
    if (! mGLESDriverCheckComplete) {
        checkGLESVersion();
        String renderer = gl.glGetString(GL10.GL_RENDERER);
        if (mGLESVersion < kGLES_20) {
            mMultipleGLESContextsAllowed =
                    ! renderer.startsWith(kMSM7K_RENDERER_PREFIX);
            notifyAll();
        }
        mLimitedGLESContexts = !mMultipleGLESContextsAllowed;
        if (LOG_SURFACE) {
            Log.w(TAG, "checkGLDriver renderer = \"" + renderer + "\" multipleContextsAllowed = "
                    + mMultipleGLESContextsAllowed
                    + " mLimitedGLESContexts = " + mLimitedGLESContexts);
        }
        mGLESDriverCheckComplete = true;
    }
}
 
Example #17
Source File: MD360VideoTexture.java    From MD360Player4Android with Apache License 2.0 6 votes vote down vote up
@Override
protected int createTextureId() {
    int[] textures = new int[1];

    // Generate the texture to where android view will be rendered
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glGenTextures(1, textures, 0);
    glCheck("Texture generate");

    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[0]);
    glCheck("Texture bind");

    GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
    GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);

    return textures[0];
}
 
Example #18
Source File: MainActivity.java    From Android-9-Development-Cookbook with MIT License 5 votes vote down vote up
public void onDrawFrame(GL10 unused) {
    Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f,
            1.0f, 0.0f);    Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0,
            mViewMatrix, 0);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    float[] tempMatrix = new float[16];
    Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, -1.0f);
    Matrix.multiplyMM(tempMatrix, 0, mMVPMatrix, 0, mRotationMatrix, 0);
    mTriangle.draw(tempMatrix);
}
 
Example #19
Source File: ARSurfaceViewRenderer.java    From geoar-app with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
	/** Set the background clear color to "black" and transparent */
	GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

	/** set up the view matrix */
	GLESCamera.resetViewMatrix();

	/** Enable depth testing */
	GLES20.glEnable(GLES20.GL_DEPTH_TEST);
	GLES20.glClearDepthf(1.0f);
	GLES20.glDepthFunc(GLES20.GL_LESS);
	GLES20.glDepthMask(true);

	/** Enable texture mapping */
	GLES20.glEnable(GLES20.GL_TEXTURE_2D);

	/** Enable blending */
	GLES20.glEnable(GLES20.GL_BLEND);
	GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
	// GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE);

	/**
	 * Backface culling - here back-facing facets are culled when facet
	 * culling is enabled
	 */
	GLES20.glEnable(GLES20.GL_CULL_FACE);
	GLES20.glCullFace(GLES20.GL_BACK); // GL_FRONT_AND_BACK for no facets

	// Resets all cached handlers because the context was lost so that they
	// are recreated later on demand.
	FeatureShader.resetShaders();
	Texture.resetTextures();
	initScene();
}
 
Example #20
Source File: StarWarsRenderer.java    From StarWars.Android with MIT License 5 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl10) {
    logFrame();
    drawGl();
    if (!requestedReveal && mAndroidDataHandle > 0) {
        requestedReveal = true;
        mListener.reveal();
    }
}
 
Example #21
Source File: PLRenderer.java    From PanoramaGL with Apache License 2.0 5 votes vote down vote up
/**render methods*/

protected void renderScene(GL10 gl, PLIScene scene, PLICamera camera)
{
	if(scene != null && camera != null)
	{
		gl.glMatrixMode(GL10.GL_PROJECTION);
		gl.glLoadIdentity();
		GLU.gluPerspective(gl, camera.getFov(), PLConstants.kPerspectiveAspect, PLConstants.kPerspectiveZNear, PLConstants.kPerspectiveZFar);
		gl.glMatrixMode(GL10.GL_MODELVIEW);
		scene.render(gl, this);
	}
}
 
Example #22
Source File: OGLESContext.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) 
{
    logger.info("GL Surface changed, width: " + width + " height: " + height);
    settings.setResolution(width, height);
    listener.reshape(width, height);
}
 
Example #23
Source File: GLCanvasImpl.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
private void setTextureCoords(final float left, final float top, final float right, final float bottom) {
    mGL.glMatrixMode(GL10.GL_TEXTURE);
    mTextureMatrixValues[0] = right - left;
    mTextureMatrixValues[5] = bottom - top;
    mTextureMatrixValues[10] = 1;
    mTextureMatrixValues[12] = left;
    mTextureMatrixValues[13] = top;
    mTextureMatrixValues[15] = 1;
    mGL.glLoadMatrixf(mTextureMatrixValues, 0);
    mGL.glMatrixMode(GL10.GL_MODELVIEW);
}
 
Example #24
Source File: CameraSurfaceView.java    From Paddle-Lite-Demo with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    // Create OES texture for storing camera preview data(YUV format)
    GLES20.glGenTextures(1, camTextureId, 0);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, camTextureId[0]);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
    surfaceTexture = new SurfaceTexture(camTextureId[0]);
    surfaceTexture.setOnFrameAvailableListener(this);

    // Prepare vertex and texture coordinates
    int bytes = vertexCoords.length * Float.SIZE / Byte.SIZE;
    vertexCoordsBuffer = ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder()).asFloatBuffer();
    textureCoordsBuffer = ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder()).asFloatBuffer();
    vertexCoordsBuffer.put(vertexCoords).position(0);
    textureCoordsBuffer.put(textureCoords).position(0);

    // Create vertex and fragment shaders
    // camTextureId->fboTexureId
    progCam2FBO = Utils.createShaderProgram(vss, fssCam2FBO);
    vcCam2FBO = GLES20.glGetAttribLocation(progCam2FBO, "vPosition");
    tcCam2FBO = GLES20.glGetAttribLocation(progCam2FBO, "vTexCoord");
    GLES20.glEnableVertexAttribArray(vcCam2FBO);
    GLES20.glEnableVertexAttribArray(tcCam2FBO);
    // fboTexureId/drawTexureId -> screen
    progTex2Screen = Utils.createShaderProgram(vss, fssTex2Screen);
    vcTex2Screen = GLES20.glGetAttribLocation(progTex2Screen, "vPosition");
    tcTex2Screen = GLES20.glGetAttribLocation(progTex2Screen, "vTexCoord");
    GLES20.glEnableVertexAttribArray(vcTex2Screen);
    GLES20.glEnableVertexAttribArray(tcTex2Screen);
}
 
Example #25
Source File: LessonOneRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawFrame(GL10 glUnused) 
{
	GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);			        
               
       // Do a complete rotation every 10 seconds.
       long time = SystemClock.uptimeMillis() % 10000L;
       float angleInDegrees = (360.0f / 10000.0f) * ((int) time);
       
       // Draw the triangle facing straight on.
       Matrix.setIdentityM(mModelMatrix, 0);
       Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);        
       drawTriangle(mTriangle1Vertices);
       
       // Draw one translated a bit down and rotated to be flat on the ground.
       Matrix.setIdentityM(mModelMatrix, 0);
       Matrix.translateM(mModelMatrix, 0, 0.0f, -1.0f, 0.0f);
       Matrix.rotateM(mModelMatrix, 0, 90.0f, 1.0f, 0.0f, 0.0f);
       Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);        
       drawTriangle(mTriangle2Vertices);
       
       // Draw one translated a bit to the right and rotated to be facing to the left.
       Matrix.setIdentityM(mModelMatrix, 0);
       Matrix.translateM(mModelMatrix, 0, 1.0f, 0.0f, 0.0f);
       Matrix.rotateM(mModelMatrix, 0, 90.0f, 0.0f, 1.0f, 0.0f);
       Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
       drawTriangle(mTriangle3Vertices);
}
 
Example #26
Source File: CameraGLRendererBase.java    From MOAAP with MIT License 5 votes vote down vote up
@Override
public void onSurfaceChanged(GL10 gl, int surfaceWidth, int surfaceHeight) {
    Log.i(LOGTAG, "onSurfaceChanged("+surfaceWidth+"x"+surfaceHeight+")");
    mHaveSurface = true;
    updateState();
    setPreviewSize(surfaceWidth, surfaceHeight);
}
 
Example #27
Source File: GLRenderer.java    From Spectaculum with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
    Log.d(TAG, "onSurfaceCreated");
    GLUtils.init();
    //GLUtils.printSysConfig();

    // set the background color
    GLES20.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);

    // set up the "camera"
    Matrix.setLookAtM(mViewMatrix, 0,
            0.0f, 0.0f, 1.0f,   // eye x,y,z
            0.0f, 0.0f, 0.0f,  // look x,y,z
            0.0f, 1.0f, 0.0f);  // up x,y,z

    if(mExternalSurfaceTexture != null) {
        // Delete input texture from previous context to free RAM
        mExternalSurfaceTexture.delete();
    }

    mExternalSurfaceTexture = new ExternalSurfaceTexture();
    mReadExternalTextureShaderProgram = new ReadExternalTextureShaderProgram();

    mDefaultShaderProgram = new TextureShaderProgram();

    mTextureToScreenShaderProgram = new TextureShaderProgram();

    if(mOnExternalSurfaceTextureCreatedListener != null) {
        mOnExternalSurfaceTextureCreatedListener.onExternalSurfaceTextureCreated(mExternalSurfaceTexture);
    }

    mFrameRateCalculator = new FrameRateCalculator(30);

    mInitializeStuff = true;
}
 
Example #28
Source File: VortexRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceChanged(GL10 gl, int w, int h) {
    Log.i(LOG_TAG, "onSurfaceChanged()");
    _width = w;
    _height = h;
    gl.glViewport(0, 0, w, h);
}
 
Example #29
Source File: CameraGLRendererBase.java    From pasm-yolov3-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {
    //Log.i(LOGTAG, "onDrawFrame start");

    if (!mHaveFBO)
        return;

    synchronized(this) {
        if (mUpdateST) {
            mSTexture.updateTexImage();
            mUpdateST = false;
        }

        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

        CameraTextureListener texListener = mView.getCameraTextureListener();
        if(texListener != null) {
            //Log.d(LOGTAG, "haveUserCallback");
            // texCamera(OES) -> texFBO
            drawTex(texCamera[0], true, FBO[0]);

            // call user code (texFBO -> texDraw)
            boolean modified = texListener.onCameraTexture(texFBO[0], texDraw[0], mCameraWidth, mCameraHeight);

            if(modified) {
                // texDraw -> screen
                drawTex(texDraw[0], false, 0);
            } else {
                // texFBO -> screen
                drawTex(texFBO[0], false, 0);
            }
        } else {
            Log.d(LOGTAG, "texCamera(OES) -> screen");
            // texCamera(OES) -> screen
            drawTex(texCamera[0], true, 0);
        }
        //Log.i(LOGTAG, "onDrawFrame end");
    }
}
 
Example #30
Source File: MyGLRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 unused, EGLConfig config) {

    // Set the background frame color
    GLES30.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    mTriangle = new Triangle();
    mSquare   = new Square();
}