我考虑过其他类似的问题和解决方案但没有成功.
这是实现GLSurfaceVIEw.Renderer的StripesSurfaceVIEw的代码:
private final class StripesSurfaceVIEw extends GLSurfaceVIEw implements GLSurfaceVIEw.Renderer { private Context context; private int textures[]; private OpenGLFlag flag; private boolean paused = false; public StripesSurfaceVIEw(Context context) { super(context); this.context = context; setRenderer(this); setRenderMode(GLSurfaceVIEw.RENDERMODE_CONTINUOUSLY); } @OverrIDe public final SurfaceHolder getHolder() { return WallpaperEngine.this.getSurfaceHolder(); } public final voID onDestroy() { super.onDetachedFromWindow(); } @OverrIDe public final voID onDrawFrame(GL10 gl) { GLES20.glClear(GLES20.GL_color_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); gl.glPushmatrix(); // rotate gl.glrotatef(Constants.FLAG_ROTATION_X,1.0f,0.0f,0.0f); gl.glrotatef(Constants.FLAG_ROTATION_Y,0.0f); gl.glrotatef(Constants.FLAG_ROTATION_Z,1.0f); // draw flag.draw(gl,paused); gl.glPopMatrix(); } @OverrIDe public final voID onSurfaceChanged(GL10 gl,int wIDth,int height) { float ratio = (float) wIDth / height; // flag flag = new OpenGLFlag(textures[0],ratio * 2,ratio); gl.glShadeModel(GL10.GL_SMOOTH); GLES20.glClearDepthf(1.0f); GLES20.glEnable(GLES20.GL_DEPTH_TEST); GLES20.glDepthFunc(GLES20.GL_LEQUAL); GLES20.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,GLES20.GL_NICEST); GLES20.glEnable(GLES20.GL_BLEND); GLES20.glEnable(GL10.GL_POINT_SMOOTH); GLES20.glBlendFunc(GLES20.GL_ONE,GLES20.GL_ONE_MINUS_SRC_Alpha); // https://www.opengl.org/sdk/docs/man2/xhtml/glBlendFunc.xml GLES20.glVIEwport(0,wIDth,height); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIDentity(); gl.glFrustumf(-ratio,ratio,-1,1,3,7); // https://www.opengl.org/sdk/docs/man2/xhtml/glFrustum.xml gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIDentity(); glu.gluLookAt(gl,3.5f,0); // https://www.opengl.org/sdk/docs/man2/xhtml/gluLookAt.xml } @OverrIDe public final voID onSurfaceCreated(GL10 gl,EGLConfig config) { // bind texture textures = new int[1]; GLES20.glEnable(GLES20.GL_TEXTURE_2D); GLES20.glGenTextures(textures.length,textures,0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,textures[0]); Log.d("gfd",context.getResources()+" :: "+ Constants.FLAG_TEXTURE); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.s); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,GLES20.GL_TEXTURE_MIN_FILTER,GLES20.GL_NEAREST); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,GLES20.GL_TEXTURE_MAG_FILTER,GLES20.GL_NEAREST); glutils.texImage2D(GLES20.GL_TEXTURE_2D,bitmap,0); bitmap.recycle(); } }}
这里是StripesSurfaceVIEw调用的地方:
private final class WallpaperEngine extends Engine { private StripesSurfaceVIEw mGLSurfaceVIEw; @OverrIDe public voID onCreate(SurfaceHolder surfaceHolder) { super.onCreate(surfaceHolder); mGLSurfaceVIEw = new StripesSurfaceVIEw(getApplicationContext()); } // ..... etc
这是当前的结果:
纹理波:
private Bitmap getBitmapFromAssets(Context context,String filename,int height) { AssetManager asset = context.getAssets(); inputStream is; try { is = asset.open(filename); BitmapFactory.Options options = new BitmapFactory.Options(); Bitmap bit=BitmapFactory.decodeStream(is,null,options); return bit; } catch (IOException e) { e.printstacktrace(); return null; } }
我在这里发布了源码:
https://github.com/ataafarin/android-live-wallpaper-wavingflag
以上是内存溢出为你收集整理的没有用texImage2D渲染的android opengl位图图像全部内容,希望文章能够帮你解决没有用texImage2D渲染的android opengl位图图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)