我正在尝试在窗户上画一幅画,但它只画了一种颜色。
我的代码发布在下面。
纹理管理器:-
package oregon.src;
import oregon.client.*;
import java.io.*;
import java.util.*;
import org.newdawn.slick.opengl.*;
public class TextureManager {
private static HashMap<String, Texture> textures = new HashMap<String, Texture>();
public static Oregon oregon = new Oregon();
public static boolean loadTexture(String path, String name) {
Texture texture = null;
try {
if ((texture = TextureLoader.getTexture("PNG", new FileInputStream(path))) != null) {
textures.put(name, texture);
return true;
}
} catch (FileNotFoundException e) {
oregon.stop(e);
} catch (IOException e1) {
oregon.stop(e1);
}
return false;
}
public static Texture getTexture(String name) {
if (textures.containsKey(name)) {
return textures.get(name);
}
return null;
}
}
画:-
package oregon.src;
import static org.lwjgl.opengl.GL11.*;
public class Draw {
public static Settings settings = new Settings();
public static void renderBlock(String path, String name, int coord1, int coord2) {
if (settings.testing) {
path = settings.pathWhilstTesting + path;
} else if (!settings.testing) {
path = settings.pathWhilstUsing + path;
}
TextureManager.loadTexture(path, name);
glBindTexture(GL_TEXTURE_2D, TextureManager.getTexture(name).getTextureID());
glBegin(GL_QUADS);
glVertex2i(coord1, coord1);
glVertex2i(coord1, coord2);
glVertex2i(coord2, coord2);
glVertex2i(coord2, coord1);
glEnd();
}
}
在你问之前,我没有收到任何错误,代码很好,只是图像。:D
编辑:-我无法添加图片!:'(