LWJGL/Slick-Util Image not displaying

Hi,

I am trying to load an image in LWJGL and am using Slick-Util, however, it is just displaying a white box, no image.

Here is my code (I am using states), also if anyone has an easier way of doing this, go right ahead and suggest it.

	private void render() {
		switch (state) {
		case INTRO:

			try {
				texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/nac.png"));
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			texture.bind(); // or GL11.glBind(texture.getTextureID());
			
			GL11.glBegin(GL11.GL_QUADS);
				GL11.glTexCoord2f(0,0);
				GL11.glVertex2f(100,100);
				GL11.glTexCoord2f(1,0);
				GL11.glVertex2f(100+texture.getTextureWidth(),100);
				GL11.glTexCoord2f(1,1);
				GL11.glVertex2f(100+texture.getTextureWidth(),100+texture.getTextureHeight());
				GL11.glTexCoord2f(0,1);
				GL11.glVertex2f(100,100+texture.getTextureHeight());
			GL11.glEnd();
		//	glColor3f(1.0f, 0.0f, 0.0f);
		//	glRectf(0, 0, width, height);
			break;
		case MAIN_MENU:
			glColor3f(0.0f, 0.0f, 1.0f);
			glRectf(0, 0, width, height);
			break;
		case GAME:
			gameState.draw();
			break;
		case RAND:
			new RandomTerrain();
			break;
		}
	}

Thanks,

  • Dan

Have you enabled 2d textures using [icode]GL11.glEnable(GL11.GL_TEXTURE_2D);[/icode] in your initialization? Also, move your texture loading to initialization or else you’re loading the texture every frame. :wink:

Thanks very much thats mostly worked, however, my image is upside down and now my gamestates are not displaying anything? here is the quad it is drawing in:

			public static void draw() {
		texture();
		GL11.glEnable(GL11.GL_TEXTURE_2D);

		texture.bind(); // or GL11.glBind(texture.getTextureID());
		GL11.glBegin(GL11.GL_QUADS);
			GL11.glTexCoord2f(0,0);
			GL11.glVertex2f(100,100);
			GL11.glTexCoord2f(1,0);
			GL11.glVertex2f(100+texture.getTextureWidth(),100);
			GL11.glTexCoord2f(1,1);
			GL11.glVertex2f(100+texture.getTextureWidth(),100+texture.getTextureHeight());
			GL11.glTexCoord2f(0,1);
			GL11.glVertex2f(100,100+texture.getTextureHeight());
		GL11.glEnd();
	}

And here are the gamestates which worked before I added that?

	private void render() {
		switch (state) {
		case INTRO:
			IntroState.draw();
		//	glColor3f(1.0f, 0.0f, 0.0f);
		//	glRectf(0, 0, width, height);
			break;
		case MAIN_MENU:
			glColor3f(0.0f, 0.0f, 1.0f);
			glRectf(0, 0, width, height);
			break;
		case GAME:
			gameState.draw();
			break;
		case RAND:
			new RandomTerrain();
			break;
		}
	}

Thanks very much for your help,

  • Dan

You need to change which texture coordinates you give to which vertex. You just need to flip the image upside down yourself. This is probably caused, because you’re rendering the wrong way. It really all depends on the way you render things…

If your Y axis is positive to up of the screen, I think you should be rendering vertices in the opposite order (anti clockwise) instead of clockwise.

Yeah, but any idea why the states dont work? they dont display but they do load :confused:

Thanks,

  • Dan

Hi,
So sorry to pester, but any idea why the states are not working? See my above post for more detail

Thanks,

  • Dan

What does that even mean? :smiley:

It really is hard to help when you cut out the code out of the big picture…

Like all the states load, but all I see is a black screen.

The only one that isnt a black screen is the INTRO state, which is the one I just fixed.

This seems to be whats causing the problem, but its also the solution :confused:

GL11.glEnable(GL11.GL_TEXTURE_2D);

Any ideas? Sorry if thats hard to understand, I know its worded badly,

  • Dan

Ow man… This isn’t even a game…
You just lack so much experience…
Ow may gad… Im kinda ripping my hair right now…
Can’t you use the same rendering code for all the states? Why would you do glRectf? Why not use the same method as in intro state?

The problem is that glRectf doesn’t specify any texture coordinates probably, so naturally, it is rendered black, since no coordinates are specified. Before you do glRectf you need to do glDisable(GL_TEXTURE_2D) and after you do glRectf you need to enable glEnable(GL_TEXTURE_2D) again.

I’m learning, give me a break. And thanks that works :slight_smile:

  • Dan

Yes. Just make sure that you move your texture loading to initialization code somewhere where it’s only called once. That texture method looks a little suspicious to me :slight_smile: also, you only have to enable texture2d once.