Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Problem in Array of Quads  (Read 1324 times)
0 Members and 1 Guest are viewing this topic.
Offline death_angel
« Posted 2014-05-24 16:27:56 »

So i was trying to create an array of textured quads with lwjgl and i got this:

can anyone help me?

Like a Boss Hacker
Offline Longarmx
« Reply #1 - Posted 2014-05-24 17:02:45 »

Can you post the relevant code?

Offline death_angel
« Reply #2 - Posted 2014-05-24 17:05:41 »

I will post the Block Class:
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  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
package net.eternalaiden.world;

import java.io.FileNotFoundException;
import java.io.IOException;

import static org.lwjgl.opengl.GL11.*;

import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;

public class Block{

   private float x, y;
   public BlockID id = BlockID.AR;
   private Texture texture = null;
   
   public Block(BlockID id, float x, float y) {
      this.x = x;
      this.y = y;
      this.id = id;
      try {
         this.texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(id.location));
         System.out.println("Texture loaded: "+texture);
         System.out.println(">> Image width: "+texture.getImageWidth());
         System.out.println(">> Image height: "+texture.getImageHeight());
         System.out.println(">> Texture width: "+texture.getTextureWidth());
         System.out.println(">> Texture height: "+texture.getTextureHeight());
         System.out.println(">> Texture ID: "+texture.getTextureID());
      } catch (FileNotFoundException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }
   }
   
   public void render(){
      texture.bind();
      glPushMatrix();
      glTranslatef(x, y, 0);
      glBegin(GL_QUADS);
         glTexCoord2f(0,0);
         glVertex2d(0,0);
         glTexCoord2f(1,0);
         glVertex2d(BlockID.b_size, 0);
         glTexCoord2f(1,1);
         glVertex2d(BlockID.b_size, BlockID.b_size);
         glTexCoord2f(0,1);
         glVertex2d(0, BlockID.b_size);
      glEnd();
      glPopMatrix();
   }

}

Like a Boss Hacker
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Longarmx
« Reply #3 - Posted 2014-05-24 17:09:05 »

Try switching your texture coords to use texture.getWidth(), and texture.getHeight().

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
public void render(){
      texture.bind();
      glPushMatrix();
      glTranslatef(x, y, 0);
      glBegin(GL_QUADS);
         glTexCoord2f(0,0);
         glVertex2d(0,0);
         glTexCoord2f(texture.getWidth(),0);
         glVertex2d(BlockID.b_size, 0);
         glTexCoord2f(texture.getWidth(),texture.getHeight());
         glVertex2d(BlockID.b_size, BlockID.b_size);
         glTexCoord2f(0,texture.getHeight());
         glVertex2d(0, BlockID.b_size);
      glEnd();
      glPopMatrix();
   }

Offline death_angel
« Reply #4 - Posted 2014-05-24 17:17:21 »

Thank you very much! it works now Cheesy

Like a Boss Hacker
Offline death_angel
« Reply #5 - Posted 2014-05-26 21:19:20 »

So now i got another problem... here is the pic:


Its a problem with the texture?  Sad

Like a Boss Hacker
Offline Longarmx
« Reply #6 - Posted 2014-05-26 21:57:08 »

It appears like it would be. Double check the bottom of your texture and make sure that it isn't transparent.

Offline death_angel
« Reply #7 - Posted 2014-05-26 21:58:51 »

It is not transparent  Wink

Like a Boss Hacker
Offline Spacebeans
« Reply #8 - Posted 2014-05-26 22:29:40 »

I believe thats texture filtering, basically its because your texture is a low resolution, and scaled up, made to look really ugly.

Try this:

1  
2  
3  
glEnable(GL_TEXTURE_2D);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
Offline death_angel
« Reply #9 - Posted 2014-05-27 16:49:47 »

I believe thats texture filtering, basically its because your texture is a low resolution, and scaled up, made to look really ugly.

Try this:

1  
2  
3  
glEnable(GL_TEXTURE_2D);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

I had tried that but it didn't work Sad

Like a Boss Hacker
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Spacebeans
« Reply #10 - Posted 2014-05-27 19:39:55 »

Are you sure, thats the main reason it wouldn't be working. Just paste that in before you load your textures. Otherwise; google "LWJGL Blurry Textures".
Offline death_angel
« Reply #11 - Posted 2014-05-27 20:18:40 »

Are you sure, thats the main reason it wouldn't be working. Just paste that in before you load your textures. Otherwise; google "LWJGL Blurry Textures".
Sorry men i put the code in wrong place... now it is working Cheesy

Like a Boss Hacker
Pages: [1]
  ignore  |  Print  
 
 

 

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

The first screenshot will be displayed as a thumbnail.

BurntPizza (14 views)
2014-09-19 03:14:18

Dwinin (31 views)
2014-09-12 09:08:26

Norakomi (58 views)
2014-09-10 13:57:51

TehJavaDev (79 views)
2014-09-10 06:39:09

Tekkerue (40 views)
2014-09-09 02:24:56

mitcheeb (62 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (30 views)
2014-09-07 01:12:14

Longarmx (36 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!