按钮和用户界面OpenGL [+概念]

时间:2014-01-16 05:45:37

标签: android button opengl-es interface camera

我的问题与此非常相似...... Adding button on an OPENGL Screen 我希望有一个摄像头预览和一些按钮,用户也可以插入一些其他图片到相框,并拍摄一切照片。有两个选项:在Open GL中创建此选项或使用android预按钮。我想使用这些预按钮。在此之前我设置了这些东西:Camera View,Surface over camera视图和绘制立方体的类。如何将这些预按钮与相机视图上的表面结合使用?

  

CameraProjectActivity

public class CameraProjectActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate( Bundle savedInstanceState ) {
    super.onCreate( savedInstanceState );

    // When working with the camera, it's useful to stick to one orientation.
    setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE );

    // Next, we disable the application's title bar...
    requestWindowFeature( Window.FEATURE_NO_TITLE );
    // ...and the notification bar. That way, we can use the full screen.
    getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN,
                            WindowManager.LayoutParams.FLAG_FULLSCREEN );

    // Now let's create an OpenGL surface.
    GLSurfaceView glView = new GLSurfaceView( this );
    // To see the camera preview, the OpenGL surface has to be created translucently.
    // See link above.
    glView.setEGLConfigChooser( 8, 8, 8, 8, 16, 0 );
    glView.getHolder().setFormat( PixelFormat.TRANSLUCENT );
    // The renderer will be implemented in a separate class, GLView, which I'll show next.
    glView.setRenderer( new GLClearRenderer() );
    // Now set this as the main view.
    setContentView( glView );

    // Now also create a view which contains the camera preview...
    CameraView cameraView = new CameraView( this );
    // ...and add it, wrapping the full screen size.
    addContentView( cameraView, new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT ) );
    } 
}
  

GLClearRenderer

public class GLClearRenderer implements Renderer {

 private Cube mCube = new Cube();
 private float mCubeRotation;

public void onDrawFrame( GL10 gl ) {
    // This method is called per frame, as the name suggests.
    // For demonstration purposes, I simply clear the screen with a random translucent gray.
    //float c = 1.0f / 256 * ( System.currentTimeMillis() % 256 );
    //gl.glClearColor( c, c, c, 0.5f );
    //gl.glClear( GL10.GL_COLOR_BUFFER_BIT );
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);        
    gl.glLoadIdentity();

    gl.glTranslatef(0.0f, 0.0f, -10.0f);
    gl.glRotatef(mCubeRotation, 1.0f, 1.0f, 1.0f);

    mCube.draw(gl);

    gl.glLoadIdentity();                                    

    mCubeRotation -= 0.15f; 

    gl.glTranslatef(0.0f, 0.0f, -10.0f);
    gl.glRotatef(mCubeRotation, 1.0f, 1.0f, 1.0f);

    gl.glLoadIdentity();      

}



public void onSurfaceChanged( GL10 gl, int width, int height ) {
    // This is called whenever the dimensions of the surface have changed.
    // We need to adapt this change for the GL viewport.
    gl.glViewport( 0, 0, width, height );
    //gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    GLU.gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 100.0f);
    gl.glViewport(0, 0, width, height);

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
}


public void onSurfaceCreated( GL10 gl, EGLConfig config ) {
    // No need to do anything here.
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 

    gl.glClearDepthf(1.0f);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glDepthFunc(GL10.GL_LEQUAL);

    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,
              GL10.GL_NICEST);
}

}

0 个答案:

没有答案