0
OK 코드는 여기에 있습니다. 좋아요. 그냥 질감이 보이지 않습니다. 나는 화이트 스퀘어가 정확히 내가 지정한 크기를 보았습니다. 단지 텍스처가 아닙니다.왜 내 OPEN GL ES 텍스처가 보이지 않습니까?
public class MeshRect {
MyRect rect;
final int VERTEX_SIZE = (2 + 4 + 2) * 4;
FloatBuffer vertices;
ShortBuffer indices;
long MyID;
public MeshRect(MyRect rect, long ID) {
super();
this.rect = rect;
MyID = ID;
Assemble();
}
private void Assemble() {
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4 * VERTEX_SIZE);
byteBuffer.order(ByteOrder.nativeOrder());
vertices = byteBuffer.asFloatBuffer();
float x1 = (float) rect.BottomLeftCorner.x;
float x2 = (float) rect.BottomRightCorner.x;
float x3 = (float) rect.TopRightCorner.x;
float x4 = (float) rect.TopLeftCorner.x;
float y1 = (float) rect.BottomLeftCorner.y;
float y2 = (float) rect.BottomRightCorner.y;
float y3 = (float) rect.TopRightCorner.y;
float y4 = (float) rect.TopLeftCorner.y;
vertices.put(new float[] { x1, y1, 1, 1, 1, 1, 0.0f, 1.0f,
x2, y2, 1, 1, 1, 1, 1.0f, 1.0f,
x3, y3, 1, 1, 1, 1, 1.0f, 0.0f,
x4, y4, 1, 1, 1, 1, 0.0f, 0.0f });
// x y r g b A u|s v|t
vertices.flip();
byteBuffer = ByteBuffer.allocateDirect(6 * 2);
byteBuffer.order(ByteOrder.nativeOrder());
indices = byteBuffer.asShortBuffer();
indices.put(new short[] { 0, 1, 2,
2, 3, 0 });
indices.flip();
}
public FloatBuffer getVertices() {
return vertices;
}
public ShortBuffer getIndices() {
return indices;
}
public long getMyID() {
return MyID;
}
public void Draw(int primitiveType, GL10 gl) {
int numVertices = 6;
//set vertex array
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
vertices.position(0);
gl.glVertexPointer(2, GL10.GL_FLOAT, VERTEX_SIZE, vertices);
//set color
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
vertices.position(2);
gl.glColorPointer(4, GL10.GL_FLOAT, VERTEX_SIZE, vertices);
// set texture coords
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
vertices.position(6);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, VERTEX_SIZE, vertices);
//set indices
indices.position(0);
gl.glDrawElements(primitiveType, numVertices, GL10.GL_UNSIGNED_SHORT, indices);
//reset
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
}
}
과는
public void Render(GL10 gl, long deltaTime) {
//render all
Log.d("Game", "Render");
gl.glViewport(0, 0, Screen.SCREEN_WIDTH, Screen.SCREEN_HEIGHT);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrthof(0, Screen.WIDTH_SCALE, 0, Screen.HEIGHT_SCALE, 1, -1);
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
/**
* so psuedo would look something like this
*
* *.Update();
* gl.glEnable(GL10.GL_TEXTURE_2D);
* Textures.BindTexture(*.getCurrentTextureFileID);
* MeshRects.draw((*.getMyRect) ,GL10.GL_TRIANGLES, gl);
*
* update();
* bind texture;
* draw rect;
*/
ball.Update(deltaTime);
gl.glEnable(GL10.GL_TEXTURE_2D);
texture.bind(gl);
MeshRect mRect = new MeshRect(ball.getMyRect(), 1);
mRect.Draw(GL10.GL_TRIANGLES, gl);
}
및 텍스처 바인드 방법
public void bind(GL10 gl) {
Log.d("Texture", "Bind");
gl.glBindTexture(GL10.GL_TEXTURE_2D, TextureID);
}
내가 도움을 기울인다 그러나 나는 뭔가를 놓치고 생각 렌더링합니다. 이것이 OPEN GL의 세계로의 첫 잠수입니다. 그리고 인터넷에서 온 모든 코드를 읽고 테스트하여 작성한이 모든 것입니다. 방법에 대한 쉬운 정보는 없었습니다. 그래서 오랫동안 그것을 재사용 할 수 있도록 배우면서 제 2D 엔진을 만들었습니다.
몇 줄을 재 배열하고 내가 놓친 줄을 추가해야했습니다. 감사 – WIllJBD