我想绘制一个图片到窗口,但它只绘制它的一种颜色。Java OpenGL只绘制一种颜色而不是图像中的所有颜色
我的代码张贴如下。
TextureManager: -
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
编辑: -我无法添加图片! :'(
深入,你能帮我考虑你花时间来编辑我的问题吗?我一直等待一个小时,现在有人来帮助我:'( –
我没有回答你的问题,因为我不知道答案,我只是一个初学者程序员,我正在等待某人回答我自己的问题,我花时间编辑你的问题,特别是添加opengl标签,以便其他人可以更好地帮助你。 – Deepend
@TaylorGolden这个问题与你发布的另一个不同:http:// stackoverflow。 com/q/11127334/324625 –