私が作業している単純な2dタイルベースのエンジンに問題があります。私の家庭用コンピュータ(Windows 7 64bit、jogl 1.1.1)では、テクスチャはタイルに正しくバインドされますが、ラップトップ(Windows Vidta 32bit、jogl 1.1.1)では壊れているようです。テクスチャアトラスは別のコンピュータでレンダリングが異なります
スプライトイメージは600x100です(各スプライトは100x100です)。
ここに私が使用しているtextureManagerクラスがあります。
public class TextureManager {
private static Texture textureAtlas;
private static Map<String, TextureCoords> locations;
private static String imageName;
public TextureManager() {
locations = new HashMap<String, TextureCoords>();
}
public static void loadAtlas(String name) {
if(textureAtlas != null) {
if(imageName == name) return;
textureAtlas.dispose();
}
imageName = name;
try {
textureAtlas = TextureIO.newTexture(new File("textures/" + name + ".png"), true);
}
catch (GLException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
setAtlasLocations();
}
private static void setAtlasLocations() {
locations.put("blank", textureAtlas.getSubImageTexCoords(0, 0, 100, 100));
locations.put("tree1", textureAtlas.getSubImageTexCoords(100, 0, 200, 100));
locations.put("tree2", textureAtlas.getSubImageTexCoords(200, 0, 300, 100));
locations.put("tree3", textureAtlas.getSubImageTexCoords(300, 0, 400, 100));
locations.put("rock", textureAtlas.getSubImageTexCoords(400, 0, 500, 100));
}
public static void bindTexture() {
textureAtlas.bind();
}
public static TextureCoords getCoords(String name) {
return locations.get(name);
}
}
これはレンダリングコードです:
public void draw(GL gl) {
gl.glEnable(GL.GL_TEXTURE_2D);
TextureManager.bindTexture();
int width = map.width();
int height = map.height();
float x = InterfaceManager.mapX;
float y = InterfaceManager.mapY;
gl.glTranslatef(x, y - height, 0);
gl.glBegin(GL.GL_QUADS);
gl.glNormal3f(0.0f, 0.0f, 1.0f);
gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
for(int w = 0; w < width; w++) {
for(int h = 0; h < height; h++) {
TextureCoords coords = getCoord(map.getTileType(w, h));
gl.glTexCoord2f(coords.left(), coords.bottom());
gl.glVertex3i(w, h, 0);
gl.glTexCoord2f(coords.right(), coords.bottom());
gl.glVertex3i(w+1, h, 0);
gl.glTexCoord2f(coords.right(), coords.top());
gl.glVertex3i(w+1, h+1, 0);
gl.glTexCoord2f(coords.left(), coords.top());
gl.glVertex3i(w, h+1, 0);
}
}
gl.glEnd();
gl.glTranslatef(-x, -y + height, 0);
gl.glDisable(GL.GL_TEXTURE_2D);
}
private TextureCoords getCoord(int tileType) {
if(tileType == 0) return TextureManager.getCoords("blank");
else if(tileType == 1) return TextureManager.getCoords("rock");
else if(tileType == 2) return TextureManager.getCoords("tree1");
else if(tileType == 3) return TextureManager.getCoords("tree2");
else if(tileType == 4) return TextureManager.getCoords("tree3");
else return TextureManager.getCoords("blank");
}
私は、OpenGLはプラットフォームに依存しないことになっている知っている、と私は両方でのOpenGLの同じバージョンを使用していているので、私はおそらくありますと仮定しています私のコードのバグ。
うまくいけば、この問題を経験してくれた方がいらっしゃいます。ありがとう!
EDIT:ここに歪んだ結果の写真があります。
上面と右側に沿って木を実際以下スプライトでロックすることになっています。
これはスプライトファイルです:
どのように壊れているように見えますか?あなたはイメージを置くことができますか?それは診断するのに役立ちます。 – Tim
私はいくつかの画像を含むように編集しました! – Mick
ごめんなさい、まだ心配することはありません。あなたが現在それをチェックしていない場合は、glGetErrorを投げるかもしれませんか?それが何かを捕まえるかどうかはわかりませんが、時にはあなたが奇妙な方法であなたのレンダリングを台無しにするファンキーな問題を見つけるのを助けることができます。 – Tim