Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Slick2D problem, getting an image size / making a grid  (Read 2506 times)
0 Members and 1 Guest are viewing this topic.
Offline Longarmx
« Posted 2012-03-30 02:03:01 »

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();
      }
     
      // 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:


1  
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

Offline davedes
« Reply #1 - Posted 2012-03-30 02:26:14 »

See this:
http://www.java-gaming.org/topics/lwjgl-trouble-new-to-opengl-all-together/26105/msg/227480/view.html#msg227480

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

Offline Longarmx
« Reply #2 - Posted 2012-03-30 02:40:56 »

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

Haha... I just got over 45,000 fps.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (37 views)
2014-07-18 06:55:21

Zero Volt (35 views)
2014-07-17 23:47:54

danieldean (28 views)
2014-07-17 23:41:23

MustardPeter (31 views)
2014-07-16 23:30:00

Cero (46 views)
2014-07-16 00:42:17

Riven (47 views)
2014-07-14 18:02:53

OpenGLShaders (36 views)
2014-07-14 16:23:47

Riven (36 views)
2014-07-14 11:51:35

quew8 (32 views)
2014-07-13 13:57:52

SHC (69 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!