没有用texImage2D渲染的android opengl位图图像

没有用texImage2D渲染的android opengl位图图像,第1张

概述我想创建一个挥动旗帜作为动态壁纸,问题是它不绘制图像(没有错误!)但它成功绘制其他纹理. 我考虑过其他类似的问题和解决方案但没有成功. 这是实现GLSurfaceView.Renderer的StripesSurfaceView的代码: private final class StripesSurfaceView extends GLSurfaceView implements 我想创建一个挥动旗帜作为动态壁纸,问题是它不绘制图像(没有错误!)但它成功绘制其他纹理.
我考虑过其他类似的问题和解决方案但没有成功.

这是实现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

这是当前的结果:

纹理波:

解决方法 使用decodestream解决问题:

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位图图像所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1126036.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存