Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - happy11

Pages: [1]
1
Graphics / Re: binding vertex array with both texture and shaders
« on: August 15, 2023, 09:09:12 pm »
The fragment shader determines the final colour for the pixel.

If it doesn't know about the texture, the texture cannot be included.

You need to pass the texture to the shader and then use the texture colour (for that fragment) and combine it with your fragment colour.

Also note that OpenGL use an opposite y direction from SFML (OpenGL fragments have 0,0 at bottom-left and SFML has 0,0 at top-left - by default) so you need to invert the y co-ordinate; this is why the radial gradient shader requires the window height.

and how do I pass the texture to the shader? to which one I should pass it to, the vertex or the fragment?

2
Graphics / Re: binding vertex array with both texture and shaders
« on: August 15, 2023, 12:16:13 pm »
No it does'nt. I tried to write a shader that only draws pixels around a certain point (https://en.sfml-dev.org/forums/index.php?topic=29148.0), and turns any pixel that is too far from that point to black.

Vertex shader -
void main()
{
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

    gl_FrontColor = gl_Color;
}

fragment shader -
uniform vec2 lightPos;
uniform float lightRadius;

void main()
{
    if (lightPos[0] < gl_FragCoord.x + 150.0 && lightPos[0] > gl_FragCoord.x - 150.0 && lightPos[1] > gl_FragCoord.y - 150.0 && lightPos[1] < gl_FragCoord.y + 150.0)
    {
        float distanceFromSource = abs(gl_FragCoord.x - lightPos[0]) * abs(gl_FragCoord.x - lightPos[0]);
        distanceFromSource += abs(gl_FragCoord.y - lightPos[1]) * abs(gl_FragCoord.y - lightPos[1]);
        distanceFromSource = sqrt(distanceFromSource);
        if (lightRadius > distanceFromSource)
        {
            gl_FragColor = gl_Color;
        }
        else
        {
            gl_FragColor = vec4(0, 0, 0, 1);
        }
    }
    else
    {
        gl_FragColor = vec4(0, 0, 0, 1);  
    }
}

3
Graphics / binding vertex array with both texture and shaders
« on: August 15, 2023, 04:38:54 am »
I have managed to grasp a bit shaders and textures.
if I want to draw Vertex array and use a texture on its triangles I write

Texture my_texture;
// load my texture here
RenderState rs;
rs.texture = &my_texture;
VertexArray my_vertexArray;
// initialize my vertex value here
...
my_window.draw(my_vertexArray, rs);

It draws the triangles with the texture as intended.

if I want to draw Vertex array and use a shader effect on its triangles I write

Shader my_shader;
// load and compile my shader here
RenderState rs;
rs.shader = my_shader;
VertexArray my_vertexArray;
// initialize my vertex value here
...
my_window.draw(my_vertexArray, rs);

it also works as intended.

But when I combine the two and make the shader effect work on the texturized triangles -
...
RenderState rs;
rs.shader = my_shader;
rs.texture = &my_texture;
...

The program acts as I only used the shader and it doesnt seem to texture the triangles.
What am I doing wrong?

I tried-
1) to go throw the tutorial in learnOpenGl about shaders. it seems as they bind textures there differently then in SFML and I dont quite get it.
2) tweak the shader code, send texture to the shader (using Sampler2D), it didnt seem to work.
3) read the documentation about shaders and GLSL

4
Graphics / Re: Draw only what's inside a certain shape
« on: August 13, 2023, 07:34:13 pm »
Ah. The shader I mentioned will only work with untextured objects.
It could be adjusted to work with textured objects but if you're new to shaders, this is a big ask.
Maybe one day, I'll make a version for textured objects; I didn't really think about that previously...

The render texture approaches are solid ways to do it. I'd likely do it one of those ways myself just because it's more obvious what you're doing (and render textures are cool once you get used to them!)

I see, thank you!

5
Graphics / Re: Draw only what's inside a certain shape
« on: August 13, 2023, 06:41:05 pm »
A common way to do this is to use a shader. The shader calculates where it is from the point in question and decides whether it should draw the thing or not (or something else like black).
For a shader that can do that with circular regions, you could try this one:
https://github.com/SFML/SFML/wiki/Source%3A-Radial-Gradient-Shader
That can do it. It can also add a gradient (light fall-off if considered a visible area) to the edge, smoothing the appearing and giving the impression that it's less clear at a distance (from the point).

Some other ways will use a render texture.

For example, you can draw the shape - in white on black - of what you want to be visible on a render texture that will be drawn over the entire window (so, it's a white/black mask) and the draw the render texture to the window with multiple blend and the white bits will remain and the black bit will become black.

You can also draw to that render texture with alpha instead of white/black and use that in the blend instead. This way you can use the alpha of images.

Also, you can draw everything to the render texture, then apply the mask, and only then draw the render texture to the window.

An example of this in use to 'clip' a specific image to another image is shown in this post:
https://en.sfml-dev.org/forums/index.php?topic=19505.msg140615#msg140615


ah shaders... I'll have to learn more about them if I want to use them.
Will it also work when I use Sprite objects and other textured objects?

I think shaders are something that is directly linked to vertex arrays.

6
Graphics / Draw only what's inside a certain shape
« on: August 13, 2023, 05:32:53 pm »
Hello, new to SFML and to programming in general.
Im trying to achive an effect where only a certain area around the mouse is visible and the rest is masked.

Something like this -



I went through the documentation of Drawable and Shape and nothing really stood out to me. Does anyone has a solution to this problem?

7
Graphics / draw triangles primitives as wires?
« on: August 11, 2023, 05:40:32 am »
I noticed that opening and drawing through RenderWindow with VertexArray and the primitive TRIANGLES produces a filled triangle.

How can I make it draw the triangle as wires/lines instead?

obviously I can draw using lines or linestrips but it is importent for me the keep the structure of the array so using these primitives defeats the purpose.

looking for something similar to 'glPolygonMode'

Pages: [1]
anything