LWJGL slick texture problem

Started by Bingo90, June 14, 2013, 11:34:55

Previous topic - Next topic

Bingo90

When I'm loading a texture, it automatically binds it. When I want to bind a texture manually, it won't work. When I want to bind a color manually it'll work. How to get textures to work?

My Texture loading code:
ex = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(System.getenv("APPDATA") + "\\Test\\Resources\\Textures\\image.png"));
        tex2 = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(System.getenv("APPDATA") + "\\Test\\Resources\\Textures\\image2.png"));


Drawing Code:

while (!Display.isCloseRequested())
        {



            GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_COLOR_BUFFER_BIT);
            glEnable(GL_BLEND);

            GL11.glEnable(GL11.GL_DEPTH_TEST);
            GL11.glBegin(GL11.GL_POLYGON);

            glEnable(GL_TEXTURE_2D);
            glColor3f(0f, 1f, 1f);

            Color.white.bind(); // This works
            ResourceManager.tex.bind(); //This not
            GL11.glTexCoord2f(1, 1);


            GL11.glVertex3f(0.0f, 0.0f, 0.0f);
            GL11.glVertex3f(0.0f, 1.0f, 0.0f);
            GL11.glVertex3f(1.0f, 1.0f, 0.0f);
            GL11.glVertex3f(2.25f, 0.6f, 0.0f);
            GL11.glVertex3f(2.75f, 0.25f, 0.0f);
            GL11.glVertex3f(2.5f, 0.0f, 0.0f);

            GL11.glEnd();

            //Color.white.bind();

            GL11.glBegin(GL11.GL_POLYGON);



            GL11.glVertex3f(2.5f, 0.0f, 0.0f);
            GL11.glVertex3f(2.75f, 0.25f, 0.0f);


            GL11.glVertex3f(2.75f, 0.25f, 1.0f);
            GL11.glVertex3f(2.5f, 0.0f, 1.0f);



            GL11.glEnd();

            GL11.glBegin(GL11.GL_POLYGON);

            GL11.glVertex3f(2.25f, 0.6f, 0.0f);
            GL11.glVertex3f(2.25f, 0.6f, 1.0f);

            GL11.glVertex3f(2.75f, 0.25f, 1.0f);


            GL11.glVertex3f(2.75f, 0.25f, 0.0f);

            GL11.glEnd();

            GL11.glBegin(GL11.GL_POLYGON);
	
            GL11.glVertex3f(0.0f, 0.0f, 1.0f);
            GL11.glVertex3f(0.0f, 1.0f, 1.0f);
            GL11.glVertex3f(1.0f, 1.0f, 1.0f);
            GL11.glVertex3f(2.25f, 0.6f, 1.0f);
            GL11.glVertex3f(2.75f, 0.25f, 1.0f);
            GL11.glVertex3f(2.5f, 0.0f, 1.0f);

            GL11.glEnd();

            GL11.glBegin(GL11.GL_POLYGON);


            GL11.glVertex3f(1.0f, 1.0f, 0.0f);
            GL11.glVertex3f(1.0f, 1.0f, 1.0f);
            GL11.glVertex3f(2.25f, 0.6f, 1.0f);
            GL11.glVertex3f(2.25f, 0.6f, 0.0f);

            GL11.glEnd();

            GL11.glBegin(GL11.GL_POLYGON);


            GL11.glVertex3f(0.0f, 0.0f, 0.0f);
            GL11.glVertex3f(0.0f, 0.0f, 1.0f);
            GL11.glVertex3f(2.5f, 0.0f, 1.0f);
            GL11.glVertex3f(2.5f, 0.0f, 0.0f);

            GL11.glEnd();

            GL11.glBegin(GL11.GL_POLYGON);


            GL11.glVertex3f(0.0f, 1.0f, 0.0f);
            GL11.glVertex3f(0.0f, 1.0f, 0.2f);
            GL11.glVertex3f(1.0f, 1.0f, 0.2f);
            GL11.glVertex3f(1.0f, 1.0f, 0.0f);

            GL11.glEnd();

            GL11.glBegin(GL11.GL_POLYGON);


            GL11.glVertex3f(0.0f, 1.0f, 0.8f);
            GL11.glVertex3f(0.0f, 1.0f, 1.0f);
            GL11.glVertex3f(1.0f, 1.0f, 1.0f);
            GL11.glVertex3f(1.0f, 1.0f, 0.8f);

            GL11.glEnd();

            GL11.glBegin(GL11.GL_POLYGON);


            GL11.glVertex3f(0.6f, 1.0f, 0.8f);
            GL11.glVertex3f(0.6f, 1.0f, 0.2f);
            GL11.glVertex3f(1.0f, 1.0f, 0.2f);
            GL11.glVertex3f(1.0f, 1.0f, 0.8f);

            GL11.glEnd();

            GL11.glBegin(GL11.GL_POLYGON);
	

            GL11.glVertex3f(0.0f, 1.0f, 0.8f);
            GL11.glVertex3f(0.0f, 1.0f, 1.0f);
            GL11.glVertex3f(0.0f, 0.0f, 1.0f);
            GL11.glVertex3f(0.0f, 0.0f, 0.8f);

            GL11.glEnd();

            GL11.glBegin(GL11.GL_POLYGON);

            //GL11.glColor3f(0.75f,0.25f,0.25f);	

            GL11.glVertex3f(0.0f, 1.0f, 0.2f);
            GL11.glVertex3f(0.0f, 1.0f, 0.0f);
            GL11.glVertex3f(0.0f, 0.0f, 0.0f);
            GL11.glVertex3f(0.0f, 0.0f, 0.2f);



            GL11.glEnd();
            glDisable(GL_BLEND);

            Display.update();

            GL11.glLoadIdentity();

        }

Fool Running

Your code only specifies one texture coordinate (that I saw). You need to specify the texture coordinate at each vertex (i.e. before each call to GL11.glVertex3f).
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Bingo90

This doesn't work. The textures loaded are green (image.png) and blue(image2.png). Changing the texture coordinates doesn't work. I would see if texture loading works if the face would be green, but it's blue

Fool Running

We need to see the rest of your code, then (at least the rest of your ResourceManager class).

P.S. Why are you using a texture for what you should be using glColor3f() for?
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Bingo90

It's just for testing, I want to use better textures later. Here's the ResourceManager class:
package net.test.manage;

import java.io.IOException;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;

public class ResourceManager
{
    public static Texture tex;
    public static Texture tex2;

    public static void LoadContent() throws IOException
    {
        tex = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(System.getenv("APPDATA") + "\\Test\\Resources\\Textures\\image.png"));
        tex2 = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(System.getenv("APPDATA") + "\\Test\\Resources\\Textures\\image2.png"));
    }
}

Fool Running

Ah! I paid closer attention to your code this time.
You are attempting to bind the texture inside of a glBegin/glEnd. You can't do this. Basically, you can only call glColor, glTexCoord, and glVertex inside a begin/end block. Setting the color can be done inside the begin/end which is why it works.

P.S. GL_POLYGON is not the best way to draw. Use GL_TRIANGLES whenever possible.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Bingo90

Ah, I see. Thank you, this works well!   ;D