Repeating Textures?

Started by WillSmith190, August 21, 2011, 03:03:52

Previous topic - Next topic

WillSmith190

I've been looking all day, but I can't find anything on how to make a texture repeating instead of stretch. I'm using this for the texturing:

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


brickTexture = TextureLoader.getTexture("PNG", new FileInputStream("bricktex.png"));


GL11.glBindTexture(GL11.GL_TEXTURE_2D, brickTexture.getTextureID());


My textures are all in one file, and I use GL11.glTexCoord2f(float, float) to assign them to individual faces.

Estraven

Hi,

if I understood right, all you textures for all your scene are in one GL_TEXTURE id.
IMHO, that's your problem.

For your textures too repeat, the best way is to use one texture ID by texture.
Then, use texCoords from 0 to N, and your texture will repeat N times.
However, it only works with TEXTURE_2D not with TEXTURE_RECT

Another way for you would be to code the repeat behavior in your shaders, but it's more complicated, and i'm pretty sure you will get artifacts.

If possible, you might also consider stop using glTexCoord, and use VBO / VAO drawing methods.
They are way more efficient.

Estraven

broumbroum

Quote from: WillSmith190 on August 21, 2011, 03:03:52
I've been looking all day, but I can't find anything on how to make a texture repeating instead of stretch. ...
You ought to set up a GL_REPEAT texture as WRAP (in S,T coords = 2D) parameter before you bind the texture ID .
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

http://www.flipcode.com/archives/Advanced_OpenGL_Texture_Mapping.shtml

and regarding your issue with an "Atlas" as the source for textures, you will have to split your atlas in as many textures samples as it is inside.
http://stackoverflow.com/questions/662107/how-to-use-gl-repeat-to-repeat-only-a-selection-of-a-texture-atlas-opengl

WillSmith190

Ok, I'll edit some things and see if I can get it to work...