Slick2D problem, getting an image size / making a grid

Hey everybody,

I just started on a new game. This time, I’m trying to use LWJGL and Slick2D instead of just the java native libraries.
I’ve got the basic framework down, but when I try to make a grid of grass, the grass has black borders and don’t line up. This is what I’ve come up with.

try {
			grass = TextureLoader.getTexture("PNG",
					ResourceLoader.getResourceAsStream("res/grass.png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		// Clearing the screen and the depth
				glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
				
				grassWidth = grass.getImageWidth(); // I've also tried using grass.getTextureWidth(), and grass.getWidth()
				grassHeight = grass.getImageHeight();

				grass.bind();

				// Drawing the background
				for (int i = 0; i < Display.getWidth() / grassWidth; i++) {
					for (int b = 0; b < Display.getHeight() / grassHeight; b++) {
						glPushMatrix();

						glBegin(GL_QUADS);
						GL11.glTexCoord2f(0, 0);
						GL11.glVertex2f(i * grassWidth,b * grassHeight);
						GL11.glTexCoord2f(0.99f, 0);
						GL11.glVertex2f(i * grassWidth + grassWidth, b* grassHeight);
						GL11.glTexCoord2f(0.99f, 0.99f);
						GL11.glVertex2f(i * grassWidth + grassWidth,b * grassHeight + grassHeight);
						GL11.glTexCoord2f(0, 0.99f);
						GL11.glVertex2f(i * grassWidth,b * grassHeight + grassHeight);
						glEnd();

						glPopMatrix();
					}
				}

This is my problem I believe:

grassWidth = grass.getImageWidth(); // I've also tried using grass.getTextureWidth(), and grass.getWidth()

I think I’m just getting the wrong sizes and so that is why the images are having a black border.
If you could reply back, that would be great!

Thanks,
Longarmx

See this:

Also:

  • Don’t bother with glPush/PopMatrix
  • Don’t call glBegin/glEnd inside each iteration – instead, call glBegin once before the loop, and glEnd once after the loop to improve performance
  • Be sure to call GL11.glEnable(GL11.GL_TEXTURE_2D) before texture loading to avoid running into the same problems at the thread above

Thank you! It works now a lot better than it did before, and it runs faster.

Haha… I just got over 45,000 fps.