android opengl glutils.teximage2d,没有用texImage2D渲染的android opengl位图图像

我想创建一个挥动旗帜作为动态壁纸,问题是它不绘制图像(没有错误!)但它成功绘制其他纹理.

我考虑过其他类似的问题和解决方案但没有成功.

这是实现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, 1.0f, 0.0f);

gl.glRotatef(Constants.FLAG_ROTATION_Z, 0.0f, 0.0f, 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], 0, 0, 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, 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, 0, 0, 3.5f, 0, 0, 0, 0, 1.0f, 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, 0, 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

这是当前的结果:

x17Ko.jpg

纹理波:

bmADV.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值