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?
|
I am just a guy
|
|
|
Longarmx
|
 |
«
Reply #1 - Posted
2014-05-24 17:02:45 » |
|
Can you post the relevant code?
|
|
|
|
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(); }
} |
|
I am just a guy
|
|
|
Games published by our own members! Check 'em out!
|
|
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(); } |
|
|
|
|
death_angel
|
 |
«
Reply #4 - Posted
2014-05-24 17:17:21 » |
|
Thank you very much! it works now 
|
I am just a guy
|
|
|
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? 
|
I am just a guy
|
|
|
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.
|
|
|
|
death_angel
|
 |
«
Reply #7 - Posted
2014-05-26 21:58:51 » |
|
It is not transparent 
|
I am just a guy
|
|
|
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); |
|
|
|
|
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 
|
I am just a guy
|
|
|
Games published by our own members! Check 'em out!
|
|
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".
|
|
|
|
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 
|
I am just a guy
|
|
|
|