各位大侠好:

我在使用open gl es的做显示的时候,发现一个问题,请各位帮助一下,谢谢。

环境:opengl es 1.x,2D的模式显示纹理图片。

在LG-P990,HTC-C510E上显示附件代码可以正常显示图片,

在LG-P920,亚马逊平板上显示附件代码不能正常显示图片,显示为白屏的。

附件地址:

http://download.csdn.net/detail/sukeradrd/4685329

硬件方面

LG-P990使用Nvidia的Tegra2 芯片。

HTC-C510E使用高通的MsM7227。

LG-P920

亚马逊平板均使用的TI的Omap芯片。

// GLImage.java

package com.sk.tstoge1;

import android.content.res.Resources;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.util.Log;

class GLImage {

public static Bitmap mBitmap;

static final String TAG = "OpenGl";

public static int m_nScrnWid;

public static int m_nScrnHei;

public static int m_nBmpWid;

public static int m_nBmpHei;

public static void load(Resources resources) {

mBitmap = BitmapFactory.decodeResource(resources, R.drawable.wood);

Log.i(TAG, "bmp info:" + mBitmap.getWidth() + "," + mBitmap.getHeight());

m_nBmpWid = (mBitmap.getWidth() / 3) * 2;

m_nBmpHei = (mBitmap.getHeight() / 3) * 2;

}

public static void setScreen(int nWid, int nHei) {

m_nScrnWid = nWid;

m_nScrnHei = nHei;

}

}

// TstOpenGlEs1.java

package com.sk.tstoge1;

import android.app.Activity;

import android.app.ActivityManager;

import android.content.Context;

import android.content.pm.ConfigurationInfo;

import android.opengl.GLSurfaceView;

import android.opengl.GLSurfaceView.Renderer;

import android.os.Bundle;

import android.util.Log;

import android.view.Display;

import android.view.Window;

import android.view.WindowManager;

public class TstOpenGlEs1 extends Activity {

final String TAG = "OpenGl"; /* suker OpenGl Es */

Renderer m_cRdr;

public void onCreate(Bundle savedInstanceState) {

Log.i(TAG, "onCreate-start...");

super.onCreate(savedInstanceState);

String strPath1 = getApplicationContext().getFilesDir()

.getAbsolutePath();

Log.i(TAG, "path1:" + strPath1);

String strPath2 = strPath1.substring(0, strPath1.length() - 5);

Log.i(TAG, "path2:" + strPath2);

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

WindowManager.LayoutParams.FLAG_FULLSCREEN);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,

WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

GLImage.load(this.getResources());

WindowManager wm = getWindowManager();

Display display = wm.getDefaultDisplay();

GLImage.setScreen(display.getWidth(), display.getHeight());

GLSurfaceView cGlSfcV = new GLSurfaceView(this);

final ActivityManager cActtMng = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

final ConfigurationInfo cCfgInfo = cActtMng

.getDeviceConfigurationInfo();

Log.i(TAG, "reqGlEsVersion:" + cCfgInfo.reqGlEsVersion);

m_cRdr = new OpenGLRenderer(cGlSfcV);

cGlSfcV.setRenderer(m_cRdr);

cGlSfcV.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

/* cGlSfcV.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY); */

setContentView(cGlSfcV);

Log.i(TAG, "onCreate-end...");

}

public void onPause() {

Log.i(TAG, "onPause-start...");

super.onPause();

Log.i(TAG, "onPause-end...");

}

}

// OpenGLRenderer.java

package com.sk.tstoge1;

import java.io.IOException;

import java.nio.Buffer;

import java.nio.ByteBuffer;

import java.nio.ByteOrder;

import java.nio.FloatBuffer;

import java.nio.IntBuffer;

import java.nio.ShortBuffer;

import javax.microedition.khronos.egl.EGLConfig;

import javax.microedition.khronos.opengles.GL;

import javax.microedition.khronos.opengles.GL10;

import android.graphics.Bitmap;

import android.opengl.GLES20;

import android.opengl.GLSurfaceView;

import android.opengl.GLU;

import android.opengl.GLUtils;

import android.opengl.GLSurfaceView.Renderer;

import android.util.Log;

public class OpenGLRenderer implements Renderer {

static final String TAG = "OpenGl";

FloatBuffer vertices;

FloatBuffer texture;

ShortBuffer indices;

int textureId;

int m_nWid = 800;

int m_nHei = 480;

float m_fPosX;

float m_fPosY;

int nPicWid = 256;

int nPicHei = 256;

byte[] m_bitmapBuf = null;

public OpenGLRenderer(GLSurfaceView mGlSfcV) {

m_nWid = GLImage.m_nScrnWid;

m_nHei = GLImage.m_nScrnHei;

m_fPosX = m_nWid / 2;

m_fPosY = m_nHei / 2;

if (null != GLImage.mBitmap) {

nPicWid = GLImage.m_nBmpWid;

nPicHei = GLImage.m_nBmpHei;

}

Log.i(TAG, "Screen:" + m_nWid + "," + m_nHei + ", Pos:X" + m_fPosX

+ ", Y:" + m_fPosY);

ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4 * 2 * 4);

byteBuffer.order(ByteOrder.nativeOrder());

vertices = byteBuffer.asFloatBuffer();

vertices.put(new float[] { -m_fPosX, -m_fPosY,/* indices:0,1pos */

m_fPosX, -m_fPosY,/* indices:1,1pos */-m_fPosX, m_fPosY,/* indices:0,0pos */

m_fPosX, m_fPosY /* indices:1,0pos */});

ByteBuffer indicesBuffer = ByteBuffer.allocateDirect(6 * 2);

indicesBuffer.order(ByteOrder.nativeOrder());

indices = indicesBuffer.asShortBuffer();

indices.put(new short[] { 0, 1, 2, 1, 2, 3 });

ByteBuffer textureBuffer = ByteBuffer.allocateDirect(4 * 2 * 4);

textureBuffer.order(ByteOrder.nativeOrder());

texture = textureBuffer.asFloatBuffer();

texture.put(new float[] { 0, 1f, 1f, 1f, 0f, 0f, 1f, 0f });

indices.position(0);

vertices.position(0);

texture.position(0);

}

public void onSurfaceCreated(GL10 gl, EGLConfig config) {

Log.d(TAG, "surface created");

}

int m_nW;

int m_nH;

@Override

public void onSurfaceChanged(GL10 gl, int width, int height) {

Log.d(TAG, "surface changed: " + width + "x" + height);

int nPosX = 0;

int nPosY = 0;

int nWid = 0;

int nHei = 0;

if (width > height) {

nPosX = (int) (width - nPicWid) / 2;

nPosY = (int) (height - nPicHei) / 2;

} else {

nPosX = (int) (width - nPicHei) / 2;

nPosY = (int) (height - nPicWid) / 2;

}

Log.i(TAG, "pic pos:" + nPosX + "," + nPosY + "," + nPicWid + ","

+ nPicHei);

gl.glViewport(nPosX, nPosY, nPicWid, nPicHei);

/* gl.glViewport(0, 0, width, width); */

m_nW = width;

m_nH = height;

}

boolean drawflag = false;

public void onDrawFrame(GL10 gl) {

/* here why entry twice? */

if (!drawflag) {

drawflag = true;

return;

}

Log.d(TAG, "onDrawFrame ");

gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

textureId = loadTexture("bobrgb888.png", gl);

gl.glMatrixMode(GL10.GL_PROJECTION);

gl.glLoadIdentity();

gl.glOrthof(-m_fPosX, m_fPosX, -m_fPosY, m_fPosY, 1, -1);

gl.glEnable(GL10.GL_TEXTURE_2D);

gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertices);

gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texture);

gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

}

public int loadTexture(String fileName, GL10 gl) {

Log.d(TAG, "loadTexture ");

int textureIds[] = new int[1];

gl.glGenTextures(1, textureIds, 0);

int textureId = textureIds[0];

gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);

if (null != GLImage.mBitmap) {

GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, GLImage.mBitmap, 0);

}

gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,

GL10.GL_NEAREST);

gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,

GL10.GL_NEAREST);

return textureId;

}

}

7 个解决方案

#1

自己顶一下

#2

纹理白的原因,应该是纹理绑定不成功。  可能是你的代码把不小心纹理删除了,接着又画图。 但你说的是不同的板子用的同一个代码,可以验证下,是不是有些板必须要求图片的尺寸是2N(老板子的要求了,现在少见)次方的,而你的图却不是。

#3

http://www.cnblogs.com/shengdoushi/archive/2011/01/13/1934181.html

仅供参考

#4

谢谢楼上,问题已经解决

#5

引用 4 楼 sukeradrd 的回复:

谢谢楼上,问题已经解决

请问怎么解决的

#6

引用 4 楼 sukeradrd 的回复:

谢谢楼上,问题已经解决

同问,怎么解决的呀,小弟现在也遇到同样的问题~~

#7

部分手机只支持纹理图案大小为2的N次方*2的N次方,比如2*2,4*4,8*8,16*16*32*32

opengl android 纹理贴图 代码,Android 使用opengl es的纹理贴图白屏问题请教。相关推荐

  1. android studio生命周期代码,Android Studio 单刷《第一行代码》系列 06 —— Fragment 生命周期...

    前情提要(Previously) 本系列将使用 Android Studio 将<第一行代码>(书中讲解案例使用Eclipse)刷一遍,旨在为想入坑 Android 开发,并选择 Andr ...

  2. android 图片变颜色代码,Android -对图片Drawable进行变色

    Android 图片DrawableCompat利用setTint()对图片Drawable进行变色 1.利用color资源对Drawable变色 Drawable对象的来源不限制,可以是从资源get ...

  3. Android微信通讯录界面代码,Android中使用Expandablelistview实现微信通讯录界面

    之前的博文<Android 中使用ExpandableListView 实现分组的实例>我简单介绍了使用ExpandableListView实现简单的好友分组功能,今天我们针对之前的所做的 ...

  4. android下拉框代码,Android下拉列表spinner的实例代码

    spinner组件有点类型于HTML中的下拉框的样子,让用户每次从下拉框中选取一个,本文为大家分享了Android下拉列表spinner的具体实现代码,供大家参考,具体内容如下 mian.xml xm ...

  5. android实时监控屏幕代码,Android 屏幕切换监听的实例代码

    昨天,我试着在屏幕切换时,使View显示在不同的位置,在网上搜索了一些资料,自己做了一段时间,终于完成了功能. 由于屏幕切换会调用activity的各个生命周期,所以需要在manifest的activ ...

  6. Android运行ListView的代码,Android ListView组件详解及示例代码

    Android 列表组件 ListView 列表组件是开发中经常用到组件,使用该组件在使用时需要为它提供适配器,由适配器提供来确定显示样式和显示数据. 下面看一个例子: 新建一个项目Lesson8_L ...

  7. android 多闹钟实现代码,Android编程实现闹钟的方法详解

    Android编程实现闹钟的方法详解 发布时间:2020-09-30 10:18:02 来源:脚本之家 阅读:75 作者:Jacob-wj 本文实例讲述了Android编程实现闹钟的方法.分享给大家供 ...

  8. android做拨号程序代码,Android开发手机拨号程序实现实例源码介绍

    Android开发手机拨号程序实现实例源码介绍,在上一篇文章中,我们实现了第一个程序:helloWorld,并成功测试完成.还给大家介绍了Android项目结构和说明.现在写一个手机拨号程序: 首先, ...

  9. android html 字体颜色代码,Android TextView通过解析html显示不同颜色和大小

    先贴一张效果图 效果 介绍 通过SpannableString.SpannableStringBuilder可以很方便的给TextView加上各种各样的样式,比如不同的颜色和大小,这里就不多说了,具体 ...

最新文章

  1. Python的注释及乱码 || 变量及类型
  2. Spring Boot -Shiro配置多Realm
  3. 深入浅出MFC文档/视图架构之文档模板
  4. 本特利3500_本特利技术控的自我修养之 轴位移探头安装
  5. if else if else语句格式_计算机各语言之间if...else区别
  6. 非对称加密提交表单到PHP
  7. mariaDB安装完成后设置root密码等初始化操作
  8. scrum角色及其职责介绍
  9. 如何通过电影种子名选择合适的电影
  10. 百度文库需要使用下载券的文档怎么下载
  11. 一套很好的51单片机教程,云龙51单片机视频教程(王云)
  12. MOS管自举电容工作原理电路设计及其分析
  13. xdb 服务_localhost 8080 XDB服务器需要用户名和密码的问题
  14. 微信小程序学习14--小程序微信支付流程分析及实现
  15. 怎么把epub转换成txt文本
  16. 设计模式之建造者和原型模式
  17. 常用测试软件01——串口调试软件
  18. Go: 模拟一张银行卡存、取、查的功能(综合练习)
  19. unraid虚拟linux系统,UNRAID教程:3分钟 用unraid自带的虚拟机 安装 黑群晖NAS DSM系统 很强大!...
  20. mysql数据库重启、登录mysql数据库、通过命令执行mysql的sql脚本等命令

热门文章

  1. 2020-10-17
  2. 《大规模元搜索引擎技》——第1章 绪言1.1 Web上查找信息
  3. YYText-显示富文本
  4. 小号系统搭建接口教程
  5. Windows内存 之 任务管理器
  6. C语言读书1000字报告,c语言实验一实验报告1000字范文.docx
  7. 一文带你看懂小程序朋友圈广告是什么
  8. pycharm python下载_PyCharm下载|PyCharm(Python开发工具) V2019.2 官方最新版 下载_当下软件园_软件下载...
  9. STM32 BOOT模式配置以及作用
  10. Ubuntu安装Caffe .build_release/tools/caffe: error while loading shared libraries: libcudart.so.8.0