2013年8月26日星期一

android opengles phone wake graphical interface textures are gone,graphics white

When the phone from the lock screen to unlock and found a running program to draw graphics all turned white;
original graphic textures are gone;
If you exit the program and reopen it then appears normal;

I want to lock the screen, then it should go through onSurfaceChanged method; method so I suspect a problem;
below the main posting my renderer code


public abstract class AbstractRender implements Renderer{

AnimationCallback mCallback ;
int viewWidth ;
int viewHeight ;
int[] mViewport = null ;

float scale = 0.5f ;
public int[] textures ;
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glEnable(GL10.GL_TEXTURE_2D); //Enable Texture Mapping ( NEW )
gl.glShadeModel(GL10.GL_SMOOTH); //Enable Smooth Shading
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); //Black Background
gl.glClearDepthf(1.0f); //Depth Buffer Setup
gl.glEnable(GL10.GL_DEPTH_TEST); //Enables Depth Testing
gl.glDepthFunc(GL10.GL_LEQUAL); //The Type Of Depth Testing To Do

//Really Nice Perspective Calculations
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
//纹理相关       
//        IntBuffer textureBuffer = IntBuffer.allocate(6); 
//        gl.glGenTextures(6, textureBuffer); 
//       
//        textures = textureBuffer.array();
//        bindTexture(gl);
       
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
viewWidth = width ;
viewHeight = height ;
mViewport = new int[]{0,0,width,height};
Log.d("onSurfaceChanged", "onSurfaceChanged,");
gl.glViewport(0, 0, width, height);
float ratio = (float)width/height;
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity(); //Reset The Projection Matrix
gl.glFrustumf(-ratio, ratio, -1, 1, 2, 12);
((CubeActivity)mCallback).mGrabber.getCurrentProjection(gl);
gl.glMatrixMode(GL10.GL_MODELVIEW); //Select The Modelview Matrix
gl.glLoadIdentity(); //Reset The Modelview Matrix
gl.glDisable(GL10.GL_DITHER);
        gl.glActiveTexture(GL10.GL_TEXTURE0);
}
float angleX = 30f ;

float angleY = -45f ;

@Override
public void onDrawFrame(GL10 gl) {
if(mCallback != null ){
//Log.d("onDrawFrame", "onDrawFrame");
mCallback.updateTime() ;
mCallback.worldRotate() ;
mCallback.layerRotate() ;
}
gl.glDisable(GL10.GL_DITHER);
// gl.glClearColor(0.5f,0.5f,0.5f,1);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
// gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
// 设置观察点位置
GLU.gluLookAt(gl, 0, 0, 1.0f, 0, 0, 0, 0, 1, 0);
gl.glTranslatef(0, 0, -3.0f);
gl.glScalef(scale, scale, scale);
// 旋转魔方,绕X轴旋转30度,然后绕Y轴旋转45度
gl.glRotatef(angleX, 1, 0, 0);
gl.glRotatef(angleY, 0, 1, 0);
gl.glColor4f(0.7f, 0.7f, 0.7f, 1.0f);
// gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
// gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
//
// gl.glEnable(GL10.GL_TEXTURE_2D);
// gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY) ;
//
// gl.glEnable(GL10.GL_CULL_FACE);
// gl.glFrontFace(GL10.GL_CW);
//     gl.glShadeModel(GL10.GL_SMOOTH);
//     gl.glEnable(GL10.GL_DEPTH_TEST);
    ((CubeActivity)mCallback).mGrabber.getCurrentModelView(gl);
    // 绑定纹理
// gl.glBindTexture(GL10.GL_TEXTURE_2D, texture);
draw(gl);
// 禁用顶点、纹理坐标数组
// gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
// gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
// gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
// gl.glDisable(GL10.GL_DEPTH_TEST);
//        gl.glDisableClientState(GL10.GL_CULL_FACE);
//angle++ ;
}

protected abstract void draw(GL10 gl);

public interface AnimationCallback{
void worldRotate();
void layerRotate();
void updateTime();
}

public void  setScale(float _scale){
scale = scale *_scale ;
if(scale > 0.85f){
scale = 0.85f ;
}else if(scale < 0.1f){
scale = 0.1f ;
}
//缩放后要重新将立体点转换成2维的平面坐标,因为立方体大小改变了
((CubeActivity)mCallback).isPoint2DProjected = false ;
}
}


To be honest for some method calls are not very clear ...


Here is the draw method:

public void draw(GL10 gl,int[] texture){
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
// mIndexBuffer.position(0);
// mVertexBuffer.position(0);
// mColorBuffer.position(0);
// mTextureBuffer.position(0);
// gl.glEnable(GL10.GL_CULL_FACE);
gl.glFrontFace(GL10.GL_CCW);
// gl.glShadeModel(GL10.GL_FLAT);
gl.glCullFace(GL10.GL_BACK);
// gl.glEnable(GL10.GL_DEPTH_TEST); //不会画被挡住的图形部分
// gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer);
//gl.glColorPointer(4, GL10.GL_FIXED, 0, mColorBuffer);

//gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTextureBuffer);
for(int i = 0 ;i < 27 ;i++){
mWorldCubeList.get(i).draw(gl);
}
// gl.glDisable(GL10.GL_DEPTH_TEST);
//      gl.glDisableClientState(GL10.GL_CULL_FACE);
      gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
      gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
//gl.glDrawElements(GL10.GL_TRIANGLES, mIndexCount, GL10.GL_UNSIGNED_SHORT, mIndexBuffer);
}



mWorldCubeList.get (i). draw (gl);

then a draw is as follows:

public void draw(GL10 gl){

if(this.bInitTexture){
this.loadGLTexture(gl);
bInitTexture = false;
}


//gl.glColor4f(mFaceColor.red, mFaceColor.green, mFaceColor.blue, mFaceColor.alpha);

//if(!mFaceColor .equals(UtilHelper.BLACK) ){
// Enable the texture state
// gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
// Point to our buffers
gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureId);
 
FloatBuffer textureBuffer = getTextureBuffer();
textureBuffer.position(0);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
//}else{
//}

ShortBuffer indicesBuffer = getIndicesBuffer();
indicesBuffer.position(0);
        gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 4, GL10.GL_UNSIGNED_SHORT, indicesBuffer);
       // if (!mFaceColor .equals(UtilHelper.BLACK)) {
        //gl.glDisable(GL10.GL_TEXTURE_2D);
   // gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
  
      // }
}



really do not know the screen from the lock screen to unlock the need to deal with what, how texture is gone ...

hope someone can answer!!
------ Solution ---------------------------- ----------------

detailed looked under public void onSurfaceCreated (GL10 gl, EGLConfig config)
This method, when using OpenGL ES, once stopped rendering thread, the context will be lost, the program which will be used to image resources are recycled, so you need public void onSurfaceCreated (GL10 gl, EGLConfig config) This method loads the resources in the picture
------ reference ---------------------------- -----------
I think you need to AbstractRender class which override onResume () method, using OpenGL on the picture to reload
------ reference ----- ----------------------------------

detailed looked under public void onSurfaceCreated (GL10 gl, EGLConfig config)   
This method, when using OpenGL ES, once stopped rendering thread, the context will be lost, the program which will be used to image resources are recycled, so you need public void onSurfaceCreated (GL10 gl, EGLConfig config) This method loads the resources in the picture  


problems found, now replies, the original lock screen and then unlock trigger onSurfaceCreated method, resulting in a picture before initializing resources are recovered, and I did not regenerate those pictures, always thought only trigger lock screen unlock onSurfaceChanged method, originally did not think it wrong way more than this one has been handled well, thank you!

没有评论:

发表评论