Hello Guest

Repeating Textures?

  • 3 Replies
  • 10516 Views
Repeating Textures?
« 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. I'm using this for the texturing:

Code: [Select]
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;

Code: [Select]
brickTexture = TextureLoader.getTexture("PNG", new FileInputStream("bricktex.png"));
Code: [Select]
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.

Re: Repeating Textures?
« Reply #1 on: August 21, 2011, 07:23:30 »
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

Re: Repeating Textures?
« Reply #2 on: August 21, 2011, 17:09:57 »
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 .
Code: [Select]
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
« Last Edit: August 21, 2011, 17:15:38 by broumbroum »

Re: Repeating Textures?
« Reply #3 on: August 22, 2011, 17:14:02 »
Ok, I'll edit some things and see if I can get it to work...
« Last Edit: August 22, 2011, 17:17:02 by WillSmith190 »