We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Repeating texture? (Read 1015 times)
Repeating texture?
Feb 25th, 2008, 5:50pm
 
Short: Is there a way to take an image and make it repeat as a texture?

Long: I want to make an infinite grid. By "infinite" I mean that as I zoom out of my sketch, there is always more grid to see. The way I thought to do this was to make a small grid image that would tile, and then use it as a texture that repeats on a shape that fills the background? Sounds easy, but I can't figure out how to tell processing/opengl to tile the texture. This seems like something simple that should be easy to do, but I can't find anything about it.
Re: Repeating texture?
Reply #1 - Mar 5th, 2008, 6:06am
 
you should be able to find some answers looking through these texture examples.

http://processing.org/learning/3d/index.html
Re: Repeating texture?
Reply #2 - Mar 14th, 2008, 9:23pm
 
I wanted the same thing, but also didnt find a way to do it in processing. I guess you could do it with pure gl statements but I just wrote myself a method which returns a PImage with the tiled image.

You put in the desired x1,x2,y1,y2 rectangle dimensions of the resulting tiled image, the original image to tile over that space, and a tint value. You´ll get a new tiled PImage in result.

Quote:
private PImage getTiledImageFromSingleImage(int x1, int y1, int x2, int y2,  PImage texture, float tint){


float planeWidth = x2 - x1;
float planeHeight = y2 - y1;

int textureWidth = texture.width;

int textureHeight = texture.height;

if(planeWidth<texture.width)
planeWidth = texture.width;
if(planeHeight<texture.height)
planeHeight = texture.height;

int timesWidth = (int)(planeWidth/textureWidth);

int timesHeight = (int)(planeHeight/textureHeight);

double restWidth = (planeWidth%textureWidth);

double restHeight = (planeHeight%textureHeight);

PImage tiledImage = new PImage((int)planeWidth, (int)planeHeight, PImage.ARGB);


for (int i = 0; i < timesWidth; i++) {

int startX = i * textureWidth;

for (int j = 0; j < timesHeight; j++) {

int startY = j * textureHeight;


tiledImage.copy(texture, 0, 0, texture.width, texture.height, startX, startY,  textureWidth,  textureHeight);  


if(restWidth > 0 && !((i+1) < timesWidth)){ //rest zeichnen, der ganz nicht hinpasste


tiledImage.copy(texture, 0, 0, (int)restWidth, texture.height , startX + textureWidth, startY, (int)restWidth,  textureHeight);

}


if(restHeight > 0 && !((j+1) < timesHeight)){

tiledImage.copy(texture, 0, 0, texture.width,(int)restHeight , startX, startY + textureHeight,  textureWidth,  (int)restHeight);

}


if((restHeight > 0 && !((j+1) < timesHeight)) && (restWidth > 0 && !((i+1) < timesWidth)) ){


tiledImage.copy(texture, 0, 0, (int)restWidth,(int)restHeight , startX + textureWidth , startY + textureHeight, (int)restWidth, (int)restHeight);
}

}

}

return tiledImage;

}
Re: Repeating texture?
Reply #3 - Apr 26th, 2008, 1:42pm
 
This is exactly what I need; however, I can't seem to get it working. If I copy and paste the code into a new Processing sketch, it shows the following error: expecting "class", found 'PImage'. Obviously, I'm doing something wrong. Just a little help?
Page Index Toggle Pages: 1