Java 阵列中的所有纹理都相同
所以我制作了一个纹理数组作为参考,这样我就可以从渲染循环外部使用它们,但是所有的图像在数组内部都是相同的Java 阵列中的所有纹理都相同,java,arrays,opengl,lwjgl,Java,Arrays,Opengl,Lwjgl,所以我制作了一个纹理数组作为参考,这样我就可以从渲染循环外部使用它们,但是所有的图像在数组内部都是相同的 Texture[] loadTextures(){ //Loading Textures Texture[] textures = new Texture[56]; for (int ii = 0; ii < 56; ii++) { System.out.println(ii); try
Texture[] loadTextures(){
//Loading Textures
Texture[] textures = new Texture[56];
for (int ii = 0; ii < 56; ii++) {
System.out.println(ii);
try {
//*// textures[ii] = TextureLoader.getTexture("png",
new FileInputStream(new File("res/Cards/"+ii+".png")));
} catch (FileNotFoundException e) {
e.printStackTrace();
Display.destroy();
System.exit(1);
} catch (IOException e) {
e.printStackTrace();
Display.destroy();
System.exit(1);
}
}
return textures;
}
public TileChanger(GridHandler grid){
this.grid = grid;
this.types = new TileType[2];
this.types[0] = TileType.stone;
this.types[1] = TileType.dirt;
this.index = 0;
}
Texture[]loadTextures(){
//加载纹理
纹理[]纹理=新纹理[56];
对于(int ii=0;ii<56;ii++){
系统输出打印(二);
试一试{
//*//纹理[ii]=TextureLoader.getTexture(“png”,
新文件输入流(新文件(“res/Cards/”+ii+“.png”));
}catch(filenotfounde异常){
e、 printStackTrace();
Display.destroy();
系统出口(1);
}捕获(IOE异常){
e、 printStackTrace();
Display.destroy();
系统出口(1);
}
}
返回纹理;
}
如果您需要我的代码的其余部分,请告诉我,我怀疑问题出在第*行
//我寻找自己答案的记录//
VOID——可能的解决方案//我一直在看opengl文档,绑定纹理时会调用一个名为数组纹理的东西,但我不理解文档中的大部分术语。
(这一页对我来说很清楚:)我在游戏中做了以下几点 -我在游戏中使用了“快速加载器”方法 代码: loadTexture方法:
public static Texture loadTexture(String path, String fileType){
Texture tex = null;
InputStream in = ResourceLoader.getResourceAsStream(path);
try {
tex = TextureLoader.getTexture(fileType, in);
} catch (IOException e) {
e.printStackTrace();
}
return tex;
}
创建枚举以存储所有类型的纹理(平铺)
括号中的第一个文本是图像的文件名
stone("stone", true),
“stone”是文件名
然后我使用了一个“tile”类来完成所有的定位、纹理和绘图
private float x, y, width, height;
private Texture texture;
private TileType type;
public Tile(float x, float y, float width, float height, TileType tile){
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.texture = quickLoad(tile.textureName);
this.type = tile;
}
public void draw(){
drawQuadTex(texture, x, y, width, height);
}
drawQuadTex方法:
public static void drawQuadTex(Texture tex, float x, float y, float quadWidth, float quadHeight){
tex.bind();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTranslatef(x, y, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(1, 0);
glVertex2f(quadWidth, 0);
glTexCoord2f(1, 1);
glVertex2f(quadWidth, quadHeight);
glTexCoord2f(0, 1);
glVertex2f(0, quadHeight);
glEnd();
glLoadIdentity();
}
所以现在我们有了一个很好的基础来处理纹理瓷砖。现在是数组
Texture[] loadTextures(){
//Loading Textures
Texture[] textures = new Texture[56];
for (int ii = 0; ii < 56; ii++) {
System.out.println(ii);
try {
//*// textures[ii] = TextureLoader.getTexture("png",
new FileInputStream(new File("res/Cards/"+ii+".png")));
} catch (FileNotFoundException e) {
e.printStackTrace();
Display.destroy();
System.exit(1);
} catch (IOException e) {
e.printStackTrace();
Display.destroy();
System.exit(1);
}
}
return textures;
}
public TileChanger(GridHandler grid){
this.grid = grid;
this.types = new TileType[2];
this.types[0] = TileType.stone;
this.types[1] = TileType.dirt;
this.index = 0;
}
请记住,您必须在这里和那里调整一些值
你可以想出一些方法让他们在屏幕上画图,但我在一个名为“map”(map[][])的双整数数组中使用它们,并使用数组列表中的数字来制作贴图,所以我真的不能帮你
我希望这对你有所帮助,或者至少让你更进一步
编辑:哎呀,这篇文章已经有一年了