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

Pages: [1]
1
I'm in the latter stages of my application and it is essential that I implement this feature - a modal window popup wherein the user must click a button to proceed with the parent window rendering. I need the pop-up window to remain on top and prevent activity (and focus) on the parent window.

In the following Minimally Reproducible Example, the child popup window correctly requests for focus but whenever one clicks on the parent window, the child window is no longer displayed.

I have searched the forums on how to make a RenderWindow always on top and it seems like it isn't an implemented feature, so I am asking, is there any workaround hacks to implement this manually ? I really need to have this feature otherwise my program is severely disfunctional.

#include <SFML/Graphics.hpp>
using namespace sf;

void drawPopUpWindow(RenderWindow& parentWindow) {
    RenderWindow popUpWindow(VideoMode(200,200), "Select a move", Style::Close);
    popUpWindow.setPosition(parentWindow.getPosition() + Vector2i(100,100));

    Event event;
    while (popUpWindow.isOpen()) {
        popUpWindow.clear(Color::White);

        while(popUpWindow.pollEvent(event)) {
            if(event.type == Event::Closed) popUpWindow.close();
            if(event.type == Event::LostFocus)
                if(parentWindow.hasFocus()) popUpWindow.requestFocus();
        }
        popUpWindow.display();
    }
}

int main() {
    RenderWindow window(VideoMode(500,500),"Parent");

    Event event;
    while (window.isOpen()) {
        window.clear(Color::White);

        window.pollEvent(event);        
        if(event.type == Event::Closed) window.close();
        if(event.type == Event::MouseButtonPressed)
            drawPopUpWindow(window);

        window.display();
    }
    return 0;
}
 

I understand that one solution is to spawn the child window next to the parent window, not on top of it, but I need my application to support full-screen mode.

Any suggestions on how one would implement this ? Thank you very much in advance.

2
I am trying to draw a red circle with outer gradient fading.

I am using this shader code https://github.com/SFML/SFML/wiki/Source:-Radial-Gradient-Shader

Here is a minimally reproducible example outlaying the error
Inside the main.cpp file :
#include <SFML/Graphics.hpp>
const char VertexShader[] =
"void main()"
"{"
        "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"
        "gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;"
        "gl_FrontColor = gl_Color;"
"}";

const char RadialGradient[] =
"uniform vec4 color;"
"uniform vec2 center;"
"uniform float radius;"
"uniform float expand;"
"uniform float windowHeight;"
"void main(void)"
"{"
"vec2 centerFromSfml = vec2(center.x, windowHeight - center.y);"
"vec2 p = (gl_FragCoord.xy - centerFromSfml) / radius;"
        "float r = sqrt(dot(p, p));"
        "if (r < 1.0)"
        "{"
                "gl_FragColor = mix(color, gl_Color, (r - expand) / (1 - expand));"
        "}"
        "else"
        "{"
                "gl_FragColor = gl_Color;"
        "}"
"}";

using namespace sf;
void drawCircle(sf::RenderWindow&);

int main(){
    sf::RenderWindow window(sf::VideoMode(600, 480), "SFML window");

    while (window.isOpen()){
        window.clear(Color(218, 224, 241));
        sf::Event event;
        while (window.pollEvent(event)){
            if (event.type == sf::Event::Closed) window.close();
        }
        drawCircle(window);
        window.display();
    }
    return 0;
}

void drawCircle(sf::RenderWindow& window) {
    Shader shader;
    shader.loadFromMemory(VertexShader, RadialGradient);
        shader.setUniform("windowHeight", static_cast<float>(window.getSize().y));

    CircleShape c(60);
        c.setFillColor(sf::Color::Transparent);
    c.setRadius(c.getLocalBounds().width/2);
        c.setOrigin(c.getRadius(), c.getRadius());
    c.setPosition(100,100);

    shader.setUniform("color", Glsl::Vec4(245,80,65,100));
    shader.setUniform("center", c.getPosition());
    shader.setUniform("radius", c.getRadius());
    shader.setUniform("expand", 0.f);
    window.draw(c, &shader);
}
 

The error that I am getting is

Failed to compile fragment shader:
0:1(331): error: could not implicitly convert operands to arithmetic operator
0:1(315): error: operands to arithmetic operators must be numeric
0:1(294): error: no matching function for call to `mix(vec4, vec4, error)'; candidates are:
0:1(294): error:    float mix(float, float, float)
0:1(294): error:    vec2 mix(vec2, vec2, float)
0:1(294): error:    vec3 mix(vec3, vec3, float)
0:1(294): error:    vec4 mix(vec4, vec4, float)
0:1(294): error:    vec2 mix(vec2, vec2, vec2)
0:1(294): error:    vec3 mix(vec3, vec3, vec3)
0:1(294): error:    vec4 mix(vec4, vec4, vec4)


Does anyone know what I am doing wrong ? I switched from
Code: [Select]
setParameters() to
Code: [Select]
stUniform() since the former is deprecated. I have also used
Code: [Select]
Glsl::Vec4(245,80,65,100) instead of
Code: [Select]
sf::Color::Red since that is the syntax as per the SFML Shader documentation.

I don't know what to do here. Thank you in advance for help.

3
General / SFML adding a menu bar to my project
« on: January 16, 2022, 12:30:56 am »
Hello people, I developed a chess game using SFML and now I'm stuck on trying to add a menu bar at the top (with buttons). I am asking you guys for help on how should I approach this problem.

From my understanding, I need an extra panel on top of my preexisting window, wherein I will add the buttons under a certain layout. So maybe extend the height of my window, and draw my chess board with a vertical offset downwards? But then, in my chess game I use the
event.mouseButton.y
coordinates all the time so will I have to subtract the height offset? That seems like an incorrect approach.

What is a good approach to this problem, can anyone guide me? I used
RenderWindow window(VideoMode(640,640), "Chess Game", style::Titlebar | Style::Close)
to generate my window object.

4
General / WSL 2 OpenGL context error causing visual tearing
« on: January 08, 2022, 03:52:24 am »
When running my executable I get the following Warning :

Warning: The created OpenGL context does not fully meet the settings that were requested
Requested: version = 1.1 ; depth bits = 0 ; stencil bits = 0 ; AA level = 0 ; core = false ; debug = false ; sRGB = false
Created: version = 0.0 ; depth bits = 0 ; stencil bits = 0 ; AA level = 0 ; core = false ; debug = false ; sRGB = false
Setting vertical sync failed
sfml-graphics requires support for OpenGL 1.1 or greater
Ensure that hardware acceleration is enabled if available
OpenGL extension SGIS_texture_edge_clamp unavailable
Artifacts may occur along texture edges
Ensure that hardware acceleration is enabled if available
 

  • I am running WSL 2 Ubuntu subsystem in VsCode
  • My SFML version is 2.5.1+dfsg-1build1.
  • I am running an integrated GPU Intel UHD 620.
  • My OpenGL version is 4.6.0

This effectively creates unbearable visual lag in my application. The application works correctly and is fluid on my friend's machine (mac), where he does not get the aforementioned warning.

I have tried to enable hardware acceleration, but that option is not available for my machine, it seems. I looked at posts on this forum with similar issue but they weren't of help.

What options do I have?  Can anyone help ?

5
solved -> Had to turn xServer via xLaunch  :D

6
General / Running the minimal example for WSL Ubuntu Subsystem in VS Code
« on: January 05, 2022, 11:10:28 pm »
I am running a WSL 2 Ubuntu Windows subsystem in VS Code and I am trying to run the Linux Minimal example.

I performed the following operations
  • sudo apt-get install libsfml-dev
which successfully installed SFML in /usr/include/SFML wherein resides ./Audio , ./Window , etc.

Then on my c++ project on VS Code, inside the main.cpp file I have the minimal example code :
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}
 

I then perform
  • g++ -c main.cpp
  • g++ main.o -o sfml-app -L /usr/include/SFML/lib -lsfml-graphics -lsfml-window -lsfml-system
  • ./sfml-app
but nothing shows up. It's stuck on a loop.

Troubleshooting
I have tried to run instead
  • g++ main.o -o sfml-app -L /usr/include/SFML/ -lsfml-graphics -lsfml-window -lsfml-system
I have further tried to manually download the .gz file, extracted it and used instead
  • g++ main.o -o sfml-app -L C:/Users/mihail/Documents/SFML/SFML-2.5.1/lib -lsfml-graphics -lsfml-window -lsfml-system

but nothing really works, it's always stuck and doesn't show the window.

Also, besides the /usr/include/SFML folder that I'm using, I get this additional folders when I run dpkg -L libsfml-dev :
Code: [Select]
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/cmake
/usr/lib/x86_64-linux-gnu/cmake/SFML
/usr/lib/x86_64-linux-gnu/cmake/SFML/SFMLConfig.cmake
/usr/lib/x86_64-linux-gnu/cmake/SFML/SFMLConfigDependencies.cmake
/usr/lib/x86_64-linux-gnu/cmake/SFML/SFMLConfigVersion.cmake
/usr/lib/x86_64-linux-gnu/cmake/SFML/SFMLSharedTargets-none.cmake
/usr/lib/x86_64-linux-gnu/cmake/SFML/SFMLSharedTargets.cmake
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/lib/x86_64-linux-gnu/pkgconfig/sfml-audio.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/sfml-graphics.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/sfml-network.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/sfml-system.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/sfml-window.pc
/usr/share
/usr/share/doc
/usr/share/doc/libsfml-dev
/usr/share/doc/libsfml-dev/copyright
/usr/lib/x86_64-linux-gnu/libsfml-audio.so
/usr/lib/x86_64-linux-gnu/libsfml-graphics.so
/usr/lib/x86_64-linux-gnu/libsfml-network.so
/usr/lib/x86_64-linux-gnu/libsfml-system.so
/usr/lib/x86_64-linux-gnu/libsfml-window.so
/usr/share/doc/libsfml-dev/changelog.Debian.gz
_______

Could anyone help understand what I am doing wrong ? Thank you very much for your time.

Pages: [1]