So i was trying to create an array of textured quads with lwjgl and i got this:
http://s30.postimg.org/ljzytu4c1/duvida.png
can anyone help me?
So i was trying to create an array of textured quads with lwjgl and i got this:
http://s30.postimg.org/ljzytu4c1/duvida.png
can anyone help me?
Can you post the relevant code?
I will post the Block Class:
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();
}
}
Try switching your texture coords to use texture.getWidth(), and texture.getHeight().
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();
}
Thank you very much! it works now
So now i got another problem… here is the pic:
http://s12.postimg.org/pehb8jyzh/duvida.png
Its a problem with the texture?
It appears like it would be. Double check the bottom of your texture and make sure that it isn’t transparent.
It is not transparent
I believe thats texture filtering, basically its because your texture is a low resolution, and scaled up, made to look really ugly.
Try this:
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
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