Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » 'wrap' a texture (in the shader I'd think)

This thread is locked; no one can reply to it. rss feed Print
'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;
}

#SelectExpand
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.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

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?
(Sorry this is not in the right forum.)

SiegeLord
Member #7,827
October 2006
avatar

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
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

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
avatar

Shouldn't this just be a texture wrapping mode change? That's going to be far more efficient than using the mod() function.

--
- Bob
[ -- All my signature links are 404 -- ]

A. van Patmos
Member #15,349
October 2013

I searched for that before asking, "texture wrapping mode" like e.g. GL_REPEAT right?
https://learnopengl.com/Getting-started/Textures says that's repeating a texture within a bitmap I understand.
I'm looking for Doom's Wall of Faces: https://www.youtube.com/watch?v=xhs0Gk7E-U8

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

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?

Erin Maus
Member #7,537
July 2006
avatar

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.

---
ItsyRealm, a quirky 2D/3D RPG where you fight, skill, and explore in a medieval world with horrors unimaginable.
they / she

Bob
Free Market Evangelist
September 2000
avatar

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.

--
- Bob
[ -- All my signature links are 404 -- ]

Erin Maus
Member #7,537
July 2006
avatar

Yeah, my solution for those problems is don't worry about it. ;D Haha.

---
ItsyRealm, a quirky 2D/3D RPG where you fight, skill, and explore in a medieval world with horrors unimaginable.
they / she

Go to: