Java OpenGL仅绘制一种颜色,而不是图像中的所有颜色

Java OpenGL仅绘制一种颜色,而不是图像中的所有颜色,java,image,opengl,Java,Image,Opengl,我想在窗户上画一幅画,但它只画了一种颜色 我的代码贴在下面 纹理管理员:- 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 =

我想在窗户上画一幅画,但它只画了一种颜色

我的代码贴在下面

纹理管理员:-

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;
    }
}
在您询问之前,我没有收到任何错误,代码很好,只是图像D


编辑:-我无法添加图像!:'(

首先需要使用

    glEnable(GL_TEXTURE_2D)
另外:),您没有向OpenGL提供纹理坐标(请参见此处)。您的抽签呼叫应如下所示:

    glBegin(GL_QUADS);
        glTexcoord2f(0, 0);
        glVertex2i(coord1, coord1);

        glTexcoord2f(0, 1);
        glVertex2i(coord1, coord2);

        glTexcoord2f(1, 1);
        glVertex2i(coord2, coord2);

        glTexcoord2f(1, 0);
        glVertex2i(coord2, coord1);
    glEnd();

希望这能有所帮助。

Deepend,考虑到您花时间编辑了我的问题,您能帮助我吗?我已经等了一个小时了,等着有人来帮我:'(我没有回答你的问题,因为我不知道答案,我自己只是一个初学者,我正在等待有人回答我自己的问题。我花时间编辑你的问题,特别是添加opengl标记,以便其他人能够更好地帮助你。@TaylorGolden这个问题与你发布的另一个问题不同吗艾德:很乐意帮忙。如果它解决了你的问题,请把它标记为答案,这样其他来这里的人都会知道。
    glBegin(GL_QUADS);
        glTexcoord2f(0, 0);
        glVertex2i(coord1, coord1);

        glTexcoord2f(0, 1);
        glVertex2i(coord1, coord2);

        glTexcoord2f(1, 1);
        glVertex2i(coord2, coord2);

        glTexcoord2f(1, 0);
        glVertex2i(coord2, coord1);
    glEnd();