LWJGL
May 22, 2013, 17:40:43 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL is now using GitHub
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: Repeating Textures?  (Read 1858 times)
WillSmith190
Newbie
*
Posts: 9


« on: August 20, 2011, 20: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:
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;

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

Code:
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.
Logged
Estraven
Regular nerd
**
Posts: 53


« Reply #1 on: August 21, 2011, 00: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
Logged
broumbroum
Prolific Timewaster
****
Posts: 316



WWW
« Reply #2 on: August 21, 2011, 10: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:
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
Logged

Sf3JSwing project, code repo (Apache License) -  http://www.sourceforge.net/p/sf3jswing
Sf3jswing Project Forum - http://apps.sourceforge.net/phpbb/sf3jswing/
WillSmith190
Newbie
*
Posts: 9


« Reply #3 on: August 22, 2011, 10:14:02 »

Ok, I'll edit some things and see if I can get it to work...
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!