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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| try { grass = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/grass.png")); } catch (IOException e) { e.printStackTrace(); } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); grassWidth = grass.getImageWidth(); grassHeight = grass.getImageHeight();
grass.bind();
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:
1
| grassWidth = grass.getImageWidth(); |
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