我无法使用GL_REPEAT在我的Android Galaxy Tab 10.1上进行纹理处理,但可以在我的手机和模拟器上使用

如何解决我无法使用GL_REPEAT在我的Android Galaxy Tab 10.1上进行纹理处理,但可以在我的手机和模拟器上使用

嗨,我是Android和OpenGLES开发的新手。我正在尝试使用OpenGL开发一个简单的Android游戏。我游戏的背景图像是一个平铺,我想使用纹理映射环绕将其设置为“ 0”。在我的Samsung Galaxy S和平台3.0的仿真器中,它运行良好。问题出在我的Samsung 10.1 Galaxy Tab上,我无法使其重复纹理。它始终使用纹理夹边缘。我找到了一个纹理教程,当我修改纹理映射并包装本教程的参数时,纹理会按预期重复,因此我知道它不是数位板中的数位板错误。问题是我的代码有什么问题,而这仅仅是平板电脑的问题? 我正在实现
GLSurfaceView.Renderer
的类中进行所有纹理设置。这有问题吗?
package com.droidev.games.bubbilliards;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.opengl.GLSurfaceView;
import android.opengl.GLUtils;

import android.util.Log;

public class BBGLRenderer implements GLSurfaceView.Renderer {

    private BBGame game;
    private int width;
    private int height;
    private float ratio_w_h;
    private ShortBuffer indicesBuffer;
    private FloatBuffer vertexBuffer;
    private FloatBuffer textureBuffer;
    private FloatBuffer backgroundVertexBuffer;
    private FloatBuffer backgroundTextureBuffer;

    private Context context;
    private BBGLSurfaceView glSurfaceView;
    private int ball_textures[];
    private int hole_open_textures[];
    private int hole_closed_textures[];
    private int background_textures[];
    private float length;

    private boolean texture_set;
    private Bitmap green_ball;
    private Bitmap orange_ball;
    private Bitmap purple_ball; 
    private Bitmap green_hole_open;
    private Bitmap orange_hole_open;
    private Bitmap purple_hole_open;
    private Bitmap green_hole_closed;
    private Bitmap orange_hole_closed;
    private Bitmap purple_hole_closed;
    private Bitmap background;



    public BBGLRenderer(Context context_,BBGLSurfaceView sv){
        super();
        context = context_; 
        glSurfaceView = sv;
        game = new BBGame(sv);
        texture_set = false;
    }



    public void onSurfaceCreated(GL10 gl,EGLConfig config){



        gl.glClearColor(0.0f,0.0f,1.0f);
        gl.glEnable(GL10.GL_BLEND);
        gl.glDisable(GL10.GL_DEPTH_TEST);
        gl.glBlendFunc(GL10.GL_ONE,GL10.GL_ONE_MINUS_SRC_ALPHA);
        gl.glEnable(GL10.GL_TEXTURE_2D);

        // reading images from resources        
        green_ball         = BitmapFactory.decodeResource(context.getResources(),R.drawable.green_ball);
        orange_ball        = BitmapFactory.decodeResource(context.getResources(),R.drawable.orange_ball);
        purple_ball        = BitmapFactory.decodeResource(context.getResources(),R.drawable.purple_ball);

        green_hole_open    = BitmapFactory.decodeResource(context.getResources(),R.drawable.green_hole_open);
        orange_hole_open   = BitmapFactory.decodeResource(context.getResources(),R.drawable.orange_hole_open);
        purple_hole_open   = BitmapFactory.decodeResource(context.getResources(),R.drawable.purple_hole_open);

        green_hole_closed  = BitmapFactory.decodeResource(context.getResources(),R.drawable.green_hole_closed);
        orange_hole_closed = BitmapFactory.decodeResource(context.getResources(),R.drawable.orange_hole_closed);
        purple_hole_closed = BitmapFactory.decodeResource(context.getResources(),R.drawable.purple_hole_closed);

        background         = BitmapFactory.decodeResource(context.getResources(),R.drawable.tile);

        // creating textures IDS
        int num_colors = BBColor.values().length;

        ball_textures        = new int[num_colors];
        hole_open_textures   = new int[num_colors];
        hole_closed_textures = new int[num_colors];
        background_textures  = new int[1];

        gl.glGenTextures(num_colors,ball_textures,0);


        // balls
        initializeTexture(gl,green_ball,(int)BBColor.GREEN.ordinal());
        initializeTexture(gl,orange_ball,(int)BBColor.ORANGE.ordinal());
        initializeTexture(gl,purple_ball,(int)BBColor.PURPLE.ordinal());

        gl.glGenTextures(num_colors,hole_open_textures,0);

        // holes open
        initializeTexture(gl,green_hole_open,orange_hole_open,purple_hole_open,hole_closed_textures,0);

        // holes closed
        initializeTexture(gl,green_hole_closed,orange_hole_closed,purple_hole_closed,(int)BBColor.PURPLE.ordinal());

        gl.glGenTextures(1,background_textures,0);      
        initializeTexture(gl,background,0);


//      initializeBuffers();

    }

    public void initializeTextures(GL10 gl){
        int num_colors = BBColor.values().length;
        gl.glGenTextures(num_colors,0);
        gl.glGenTextures(num_colors,0);
        gl.glGenTextures(1,0);

        // balls
        initializeTexture(gl,(int)BBColor.PURPLE.ordinal());
        // holes open
        initializeTexture(gl,(int)BBColor.PURPLE.ordinal());
        // holes closed
        initializeTexture(gl,(int)BBColor.PURPLE.ordinal());

        initializeTexture(gl,0);
        texture_set = true;
    }

    public void initializeTexture(GL10 gl,Bitmap bmp,int textures[],int color){
        gl.glBindTexture(GL10.GL_TEXTURE_2D,textures[color]);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MAG_FILTER,GL10.GL_LINEAR);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MIN_FILTER,GL10.GL_TEXTURE_WRAP_S,GL10.GL_REPEAT);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_WRAP_T,GL10.GL_REPEAT);
        GLUtils.texImage2D(GL10.GL_TEXTURE_2D,bmp,0);

//      gl.glTexImage2D(GL10.GL_TEXTURE_2D,GL10.GL_RGBA,bmp.getWidth(),bmp.getHeight(),GL10.GL_,pixels)
    }

    public void initializeBuffers(int w,int h){

        length = Math.min(ratio_w_h/(float)game.getWidth(),1.0f/(float)game.getHeight());
        // Vertices Position //////////////////////////////////////////////////////////
        float vertices[] = {0.0f,length,0.0f};

        ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(vertices.length * 4);
        vertexByteBuffer.order(ByteOrder.nativeOrder());

        vertexBuffer = vertexByteBuffer.asFloatBuffer();
        vertexBuffer.put(vertices);
        vertexBuffer.position(0);

        // indices ////////////////////////////////////////////////////////////////////

        short[] indices = new short[] { 0,1,2,3,2 };

        ByteBuffer indicesByteBuffer = ByteBuffer.allocateDirect(indices.length * 2);
        indicesByteBuffer.order(ByteOrder.nativeOrder());
        indicesBuffer = indicesByteBuffer.asShortBuffer();
        indicesBuffer.put(indices);
        indicesBuffer.position(0);

        // Texture Coords /////////////////////////////////////////////////////////////
        float coords[] = {0.0f,1.0f,0.0f};

        ByteBuffer textureByteBuffer = ByteBuffer.allocateDirect(coords.length * 4);
        textureByteBuffer.order(ByteOrder.nativeOrder());

        textureBuffer = textureByteBuffer.asFloatBuffer();
        textureBuffer.put(coords);
        textureBuffer.position(0);


        //////////////////////////////////////////////////////////////////////
        // Vertices Position //////////////////////////////////////////////////////////
        float verticesBackground[] = {0.0f,game.getWidth()*length,game.getHeight()*length,0.0f};

        ByteBuffer backgroundVertexByteBuffer = ByteBuffer.allocateDirect(verticesBackground.length * 4);
        backgroundVertexByteBuffer.order(ByteOrder.nativeOrder());

        backgroundVertexBuffer = backgroundVertexByteBuffer.asFloatBuffer();
        backgroundVertexBuffer.put(verticesBackground);
        backgroundVertexBuffer.position(0);

        // Texture Coords /////////////////////////////////////////////////////////////
        float coordsBackground[] = {0.0f,game.getHeight(),game.getWidth(),0.0f};

        ByteBuffer backgroundTextureByteBuffer = ByteBuffer.allocateDirect(coordsBackground.length * 4);
        backgroundTextureByteBuffer.order(ByteOrder.nativeOrder());

        backgroundTextureBuffer = backgroundTextureByteBuffer.asFloatBuffer();
        backgroundTextureBuffer.put(coordsBackground);
        backgroundTextureBuffer.position(0);
        //////////////////////////////////////////////////////////////////////




        game.setResolution(w,h);
        game.setRatio_W_H(ratio_w_h);
        game.setSquareLength(length);
    }

    public void onSurfaceChanged(GL10 gl,int w,int h){
        width = w;
        height = h;
        ratio_w_h = (float)width/(float)height;
        gl.glViewport(0,w,h);
        gl.glMatrixMode(GL10.GL_PROJECTION);
        gl.glLoadIdentity();
        gl.glOrthof(0.0f,ratio_w_h*1.0f,-1.0f,1.0f);
        gl.glMatrixMode(GL10.GL_MODELVIEW);
        initializeBuffers(w,h);
    }

    public void onDrawFrame(GL10 gl){

        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

        gl.glLoadIdentity();

        gl.glEnable(GL10.GL_TEXTURE_2D);
        gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
        gl.glTexCoordPointer(2,GL10.GL_FLOAT,backgroundTextureBuffer);
        gl.glBindTexture(GL10.GL_TEXTURE_2D,background_textures[0]);
        //gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_REPEAT);
        //gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_REPEAT);
//      if(!texture_set){
//          initializeTextures(gl);
//          initializeBuffers(width,height);
//      }
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);       
        gl.glVertexPointer(3,backgroundVertexBuffer);





//      gl.glTexParameterx(GL10.GL_TEXTURE_2D,GL10.GL_LINEAR);
//      gl.glTexParameterx(GL10.GL_TEXTURE_2D,GL10.GL_CLAMP_TO_EDGE);
//      gl.glTexParameterx(GL10.GL_TEXTURE_2D,GL10.GL_CLAMP_TO_EDGE);


//      gl.glDrawArrays(GL10.GL_TRIANGLE_FAN,4);
        gl.glDrawElements(GL10.GL_TRIANGLES,6,GL10.GL_UNSIGNED_SHORT,indicesBuffer);

        gl.glVertexPointer(3,vertexBuffer);
        gl.glTexCoordPointer(2,textureBuffer);

        for(BBHole h: game.getHoles()){
            gl.glPushMatrix();
            gl.glTranslatef(h.getX()*length,h.getY()*length,0.0f);
            gl.glBindTexture(GL10.GL_TEXTURE_2D,(h.isOpen())?hole_open_textures[h.getColor().ordinal()]:hole_closed_textures[h.getColor().ordinal()]);
//          gl.glDrawArrays(GL10.GL_TRIANGLE_FAN,4);    
            gl.glDrawElements(GL10.GL_TRIANGLES,indicesBuffer);
            gl.glPopMatrix();
        }


        for(BBBubble b: game.getBubbles()){
            synchronized (b) {
                gl.glPushMatrix();
                gl.glTranslatef(b.getX()*length+b.getTx(),b.getY()*length+b.getTy(),0.0f);
                gl.glBindTexture(GL10.GL_TEXTURE_2D,ball_textures[b.getColor().ordinal()]);
//              gl.glDrawArrays(GL10.GL_TRIANGLE_FAN,4);        
                gl.glDrawElements(GL10.GL_TRIANGLES,indicesBuffer);
                gl.glPopMatrix();
                b.notifyAll();
            }
        }




//      gl.glColor4f(1.0f,1.0f);


        gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glDisable(GL10.GL_TEXTURE_2D);
//      gl.glFlush();
//      Log.i(\"GL_ERROR = \",Integer.toString( gl.glGetError()));
        glSurfaceView.setDirty(false);
    }

    public BBGame getGame(){
        return game;
    }
}
所以我基本上有一个
Activity
扩展extends4ѭ的类,上面介绍的实现
GLSurfaceView.Renderer
的类以及具有游戏规则的类,等等。 提前致谢!     

解决方法

        我认为GL_REPEAT仅适用于POT(两种幂)纹理,并且drawable-xyz可能会放大或缩小为非POT大小。     ,        好的,我找到了解决我问题的方法,但是对我来说这没有意义。在eclipse中创建的项目在res文件夹中仅包含drawable-hdpi,drawable-mdpi和drawable-ldpi文件夹,而没有诸如我之前提到的教程中那样的drawable文件夹。 因此,解决方案是创建此\“ drawable \”文件夹并将图像放在此处。然后GL_REPEAT“神奇地”为星系选项卡工作。由于该文件夹问题,我浪费了2天:(。 我很好奇它是否有意义,是否应该将所有纹理始终放在这些drawable文件夹中。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-