gpt4 book ai didi

android - 无法使用纹理

转载 作者:行者123 更新时间:2023-11-29 16:10:49 28 4
gpt4 key购买 nike

我得到一个白色方框,而不是屏幕上显示的纹理。哦,我认为这无关紧要,但以防万一我先放置线性布局 View ,然后再放置表面 View 。

这是我的代码:

public class GameEngine {

private float vertices[];
private float textureUV[];

private int[] textureId = new int[1];

private FloatBuffer vertextBuffer;
private FloatBuffer textureBuffer;

private short indices[] = {0,1,2,2,1,3};
private ShortBuffer indexBuffer;

private float x, y, z;
private float rot, rotX, rotY, rotZ;


public GameEngine() {

}

public void setEngine(float x, float y, float vertices[]){
this.x = x;
this.y = y;
this.vertices = vertices;

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

vertextBuffer = vbb.asFloatBuffer();
vertextBuffer.put(this.vertices);
vertextBuffer.position(0);
vertextBuffer.clear();


ByteBuffer ibb = ByteBuffer.allocateDirect(indices.length * 2);
ibb.order(ByteOrder.nativeOrder());

indexBuffer = ibb.asShortBuffer();
indexBuffer.put(indices);
indexBuffer.position(0);
indexBuffer.clear();
}



public void draw(GL10 gl){
gl.glLoadIdentity();
gl.glTranslatef(x, y, z);
gl.glRotatef(rot, rotX, rotY, rotZ);

gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId[0]);

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);


gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertextBuffer);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);



gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_SHORT, indexBuffer);


gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

}

public void LoadTexture(float textureUV[], GL10 gl, InputStream is) throws IOException{

this.textureUV = textureUV;

ByteBuffer tbb = ByteBuffer.allocateDirect(this.textureUV.length * 4);
tbb.order(ByteOrder.nativeOrder());
textureBuffer = tbb.asFloatBuffer();
textureBuffer.put(this.textureUV);
textureBuffer.position(0);
textureBuffer.clear();

Bitmap bitmap = null;

try{
bitmap = BitmapFactory.decodeStream(is);

}finally{
try{
is.close();
is = null;
gl.glGenTextures(1, textureId,0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId[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_LINEAR);

//Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);

//Use the Android GLUtils to specify a two-dimensional texture image from our bitmap
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);


gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

//Clean up
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId[0]);

bitmap.recycle();
}catch(IOException e){

}

}

}



public void setVector(float x, float y, float z){
this.x = x;
this.y = y;
this.z = z;
}

public void setRot(float rot, float x, float y, float z){
this.rot = rot;
this.rotX = x;
this.rotY = y;
this.rotZ = z;
}

public float getZ(){
return z;
}
}

最佳答案

确保您的纹理是二次方大小。您不能将 NPO2 纹理与 GL_REPEAT 一起使用。

此外,我在任何地方都看不到 glEnable(GL_TEXTURE_2D)

关于android - 无法使用纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13589281/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com