user6053405
user6053405

Reputation:

Rendering a textured quad in LWJGL is rendering White?

I am trying to render a textured quad onto the screen as a start menu button for my new game. But when rendering it just renders as a white quad, i have searched for days over the internet and i havent found a single answer that has fixed the problem.

My texture is wood.png and it is in a "res" folder inside a resources source folder in the project. it is a 128 * 128 pixel image.

The code for rendering textures is as follows:

public static void renderTexture(Texture texture, float width, float height, float x, float y) {

    texture.bind();

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    texture.bind();
        glTranslatef(x, y, 0);
        glBegin(GL_QUADS);
        glTexCoord2f(0, 0);
        glVertex2f(0, 0);
        glTexCoord2f(1, 0);
        glVertex2f(width, 0);
        glTexCoord2f(1, 1);
        glVertex2f(width, height);
        glTexCoord2f(0, 1);
        glVertex2f(0, height);
        glLoadIdentity();
    glEnd();

    glDisable(GL_BLEND);
}

The code that i use to load the textures is:

    public static Texture loadTexture(String fileName){
    try {
        Texture texture = TextureLoader.getTexture("PNG",Class.class.getResourceAsStream("/res/"+fileName+".png"));
        return texture;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

I have a static Texture storing private static Texture startTex = Loader.loadTexture("wood"); and i render it every frame by doing:

RenderSystem.renderTexture(startTex, 200, 200, 0, 0);

Upvotes: 1

Views: 139

Answers (1)

user6053405
user6053405

Reputation:

The Answer is that i did glBegin(GL_TEXTURE_2D); instead of glEnable(GL_TEXTURE_2D); Sorry the code for that part wasnt shown.

Upvotes: 1

Related Questions