'wrap' a texture (in the shader I'd think)
A. van Patmos

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
return vec2(fmod(p.x+x , 1.0f), p.y);

A. van Patmos

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

mod in GLSL is equivalent to C's fmod. Does that resolve your issue?

A. van Patmos

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

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

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
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

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

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

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

Thread #618083. Printed from Allegro.cc