나는 OpenGL ES를 처음 사용한다고 말하기 시작했다. (나는 어제 시작했다.) 그러나 나는 몇몇 자바와 다른 언어 경험을 가지고있다.타일을 생성하는 더 좋은 방법
저는 많은 자습서를 보았습니다. 물론 Nehe의 것들도 많이 보았습니다. 제 작품은 주로 그것을 기반으로합니다.
테스트로서 나는 작은 젤다와 비슷한 게임을 만들기 위해 "타일 생성기"를 만들기 시작했습니다. 질감이있는 사각형에서 친구를 움직이는 것이 좋을 수도 있습니다 : p). ,
private char[][] map = {
{0, 0, 20, 11, 11, 11, 11, 4, 0, 0},
{0, 20, 16, 12, 12, 12, 12, 7, 4, 0},
{20, 16, 17, 13, 13, 13, 13, 9, 7, 4},
{21, 24, 18, 14, 14, 14, 14, 8, 5, 1},
{21, 22, 25, 15, 15, 15, 15, 6, 2, 1},
{21, 22, 23, 0, 0, 0, 0, 3, 2, 1},
{21, 22, 23, 0, 0, 0, 0, 3, 2, 1},
{26, 0, 0, 0, 0, 0, 0, 3, 2, 1},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
};
그것은 일하고하지만 난 그것에 더 행복 해요 :
는 지금까지 내가 작업 타일 생성기를 달성, 나는 문자지도 느릅 나무 타일을 저장하기 위해 [] [] 배열에 정의 나는 그 일을 할 수있는 BETER 방법이 확신 :
1)로드 텍스처 :
01 : 나는 그지도에 사용하려는 타일을 포함하는 추한 찾고 배열을 만들private int[] textures = {
R.drawable.herbe, //0
R.drawable.murdroite_haut, //1
R.drawable.murdroite_milieu, //2
R.drawable.murdroite_bas, //3
R.drawable.angledroitehaut_haut, //4
R.drawable.angledroitehaut_milieu, //5
};
23,516,이 논문의 모든 그리기 가능 폴더에 저장됩니다
(나는 나는 현재 27 개 타일을로드, 목적에이의 cutted), 각 하나는 16 * 16 타일입니다.
그때 텍스처를 생성하고 나중에 사용하기 위해는 HashMap에 저장이 배열을 사용
int[] tmp_tex = new int[textures.length];
gl.glGenTextures(textures.length, tmp_tex, 0);
texturesgen = tmp_tex; //Store the generated names in texturesgen
for(int i=0; i < textures.length; i++)
{
//Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), textures[i]);
InputStream is = context.getResources().openRawResource(textures[i]);
Bitmap bitmap = null;
try {
//BitmapFactory is an Android graphics utility for images
bitmap = BitmapFactory.decodeStream(is);
} finally {
//Always clear and close
try {
is.close();
is = null;
} catch (IOException e) {
}
}
// Get a new texture name
// Load it up
this.textureMap.put(new Integer(textures[i]),new Integer(i));
int tex = tmp_tex[i];
gl.glBindTexture(GL10.GL_TEXTURE_2D, tex);
//Create Nearest Filtered Texture
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);
bitmap.recycle();
}
나는 그것을 처리하는 더 나은 방법이 확신 해요 ... 난 그냥했다 그것을 이해할 수 없다. 누군가가 아이디어를 가지고 있다면, 나는 모두 귀입니다. 타일 그리기
2) 단일 광장과 하나의 텍스처 맵 작성했다 내가했던
:
/** The initial vertex definition */
private float vertices[] = {
-1.0f, -1.0f, 0.0f, //Bottom Left
1.0f, -1.0f, 0.0f, //Bottom Right
-1.0f, 1.0f, 0.0f, //Top Left
1.0f, 1.0f, 0.0f //Top Right
};
private float texture[] = {
//Mapping coordinates for the vertices
0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f
};
그런 다음 내 그리기 기능에, 나는지도를 통해 루프가 정의를 사용할 텍스처 (버퍼를 가리키고 활성화 한 후) :
for(int y = 0; y < Y; y++){
for(int x = 0; x < X; x++){
tile = map[y][x];
try
{
//Get the texture from the HashMap
int textureid = ((Integer) this.textureMap.get(new Integer(textures[tile]))).intValue();
gl.glBindTexture(GL10.GL_TEXTURE_2D, this.texturesgen[textureid]);
}
catch(Exception e)
{
return;
}
//Draw the vertices as triangle strip
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length/3);
gl.glTranslatef(2.0f, 0.0f, 0.0f); //A square takes 2x so I move +2x before drawing the next tile
}
gl.glTranslatef(-(float)(2*X), -2.0f, 0.0f); //Go back to the begining of the map X-wise and move 2y down before drawing the next line
}
이것은 정말 멋지게 작동합니다. 1000 * 10 00 또는 그 이상의지도가 있으면 지옥으로 뒤덮여있을 것입니다 (이것은 전형적인 젤다 세계지도 인 : http://vgmaps.com/Atlas/SuperNES/LegendOfZelda-ALinkToThePast-LightWorld.png).
Vertex Buffer Object 및 DisplayList에 대한 내용을 읽었지만 좋은 튜토리얼을 찾지 못했고 nodoby가 가장 좋았습니다/더 나은 지원이 있습니다 (T1 및 Nexus One은 이미 오래되었습니다) .
많은 코드가 있지만 생각보다 도움이된다고 생각합니다.
미리 감사드립니다.