|
'wrap' a texture (in the shader I'd think) |
A. van Patmos
Member #15,349
October 2013
|
The following code gives an updated bmp to my program except where the wave "runs out of space" and it does not fill the other side of the target. So previously written portions remain there (i.e. stripes). al_set_target_bitmap(bmp); al_use_shader(waves); al_set_shader_sampler("tex", wtr, 0); al_set_shader_float("tx" , tx); al_draw_bitmap(wtr, 0, 0, 0); al_use_shader(NULL); al_set_target_backbuffer(display); al_clear_to_color(al_map_rgb(215, 255, 255)); al_draw_bitmap(bmp, 0, 0, 0); etc..
// Vertex varying vec2 v_texCoord; void main() { v_texCoord = gl_MultiTexCoord0; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
1//Fragment
2varying vec2 v_texCoord;
3uniform sampler2D tex; // used texture unit
4uniform float tx; // x wave's phase
5
6vec2 SineWave( vec2 p )
7{
8 float x = sin( (p.y - tx)/256 * 6.28318) * 0.05;
9 return vec2(p.x+x, p.y);
10}
11
12void main()
13{
14 gl_FragColor = texture2D(tex,SineWave(v_texCoord));
15}
I don't know what to do about this. |
A. van Patmos
Member #15,349
October 2013
|
Thanks, it gives "no matching overloaded function found" which I can fix by using this rx = (p.x+x) - 1.0f * floor((p.x+x) / 1.0f); return vec2(rx, p.y);
What do I need for fmod? Should it run through a C preprocessor? |
SiegeLord
Member #7,827
October 2006
|
mod in GLSL is equivalent to C's fmod. Does that resolve your issue? "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
A. van Patmos
Member #15,349
October 2013
|
It does thanks, return vec2(mod(p.x+x , 1.0f), mod(p.y+y , 1.0f)); I send an offset (p.x = p.x + delta_x) with every shader call. Can older GLSL versions (like 2.1) have such a 'counter' running inside them? |
Bob
Free Market Evangelist
September 2000
|
Shouldn't this just be a texture wrapping mode change? That's going to be far more efficient than using the mod() function. -- |
A. van Patmos
Member #15,349
October 2013
|
I searched for that before asking, "texture wrapping mode" like e.g. GL_REPEAT right? |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Uncle Bob said: Shouldn't this just be a texture wrapping mode change? That's going to be far more efficient than using the mod() function. Bob, how do you do that with a sub texture without the use of mod? Say, in the case of a sprite atlas? My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Erin Maus
Member #7,537
July 2006
|
Yeah I use mod in my game for maps because all the map tiles are on the same texture. RuneScape does the same thing for its giant texture atlases. --- |
Bob
Free Market Evangelist
September 2000
|
Yes, fixed-function texture wrapping (like GL_REPEAT) doesn't work for atlases. It wasn't clear from the OP that atlases were involved. FWIW, texture arrays are preferred if you can fit your atlas as equally-sized textures. Using mod() has some edge cases that need to be handled: large coordinates, negative coordinates, correct padding for anisotropic filters, ... which you don't need to think about with the HW-provided features. -- |
Erin Maus
Member #7,537
July 2006
|
Yeah, my solution for those problems is don't worry about it. Haha. --- |
|