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.


Topics - exoloner

Pages: [1]
1
General / Help with basic fragment-shadered full-screen sprite
« on: February 12, 2019, 02:13:29 pm »
Hello!
I'm trying desperately to run a simply 2D fragment shader, just a starfield, using SFML 2.5 (2018-2019)

It's a pretty minimalistic scenario:

A class that uses fragment shader as an in-game background, and the main() using that class.

The class code implementing this special shadered-backgrounds is this :
#pragma once
#include <SFML/Graphics.hpp>
#include <list>
#include <iterator>
#include <string>
#include <fstream>
#include <streambuf>

#ifndef FONSFX_H
#define FONSFX_H

#include <SFML/Graphics.hpp>

namespace FonsFX
{
        class FonsEfecte
        {
        private:
                sf::Image img;
                sf::Texture tex;
               
                bool ShaderGeom_isOk = false;
                bool ShaderFrag_isOk = false;
        public:
                sf::Sprite sprite;
                sf::Shader sh;         

                FonsEfecte(unsigned int Ample, unsigned int Alt) {
                        img.create(Ample , Alt );
                        tex.loadFromImage(img);
                        sprite.setTexture(tex);
                       
                        std::string CodiSharedQUADFixe = "void main(void)       {       gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;                 }";
                        if (sh.loadFromMemory(CodiSharedQUADFixe, sf::Shader::Geometry))
                                ShaderGeom_isOk = true;
                       
                       
                                std::ifstream t("Data/gfx/CampDestels.glsl");
                                std::string CodiFragment((std::istreambuf_iterator<char>(t)),
                                std::istreambuf_iterator<char>());[/color]

                        if (sh.loadFromFile( CodiFragment, sf::Shader::Fragment))
                                ShaderFrag_isOk = true;
/*
[b][color=red]This might be a bug inside loadFromFile method, I assure that, because
 as the std::ifstream code demonstrates, it's not a path/permission rights file access issue:
then the loadFromFile is not working properly when a // // path is given.
[/color][/b] */

                }
                void UpdateFXvar(std::string FXVarName, sf::Vector2f FXValue)
                {
                        sf::Shader::bind(&sh);
                        sh.setUniform(FXVarName, FXValue);
                }
                void UpdateFXvar(std::string FXVarName,float FXValue)
                {
                        sf::Shader::bind(&sh);
                        sh.setUniform(FXVarName, FXValue);
                }
                void Render(sf::RenderWindow *window)
                {
                        sf::RenderStates r;
                        r.shader = &sh;
                        sf::Shader::bind(&sh);
                        window->draw(sprite, r);
                }
                ~FonsEfecte() {
                }
        };
}

#endif
 

Now the main() and the only thing I get is a black drawing, assuming it's the sprite.

int main()
{
sf::RenderWindow window;
FonsFX::FonsEfecte *ELFonsDestelsFx;
sf::Clock clock;

        while (window.isOpen())
        {
.
... other stuff,...events and so...
                ELFonsDestelsFx->UpdateFXvar("time", clock.getElapsedTime().asSeconds());
                ELFonsDestelsFx->UpdateFXvar("resolution", sf::Vector2f(window.getSize().x, window.getSize().y));
               
                window.clear(sf::Color(180, 180, 180, 255));

                ELFonsDestelsFx->Render(&window);
                window.display();
        }

        return 0;
}

and the code on the fragment shader is like this, assuming it compiles ok, because the sf::Shader loadFromFile returns a true :

CampdEstels.glsl

uniform float time;
uniform vec2 resolution;

float h(float i){
        return fract(pow(3., sqrt(i/2.)));
}

void main(void){
       
        vec2 p=gl_FragCoord.xy*2.-resolution;
       
        float a=floor(degrees(4.+atan(p.y,p.x))*2.)/4.;
       
        float d=pow(2.,-10.*fract(0.1*time*(h(a+.5)*-.1-.1)-h(a)*1000.));
       
        if(abs(length(p)-d*length(resolution)) < d*35.){
                gl_FragColor=vec4(d*(h(a+.5)*3.));
        }else{
                gl_FragColor=vec4(0.);
        }
}

So, I'm trying to report a bug in the loadFromFile at sf::Shader when the path contains slashes.
and also I'm trying to get help, because this code shows a 640x480 black sprite, although the both shaders are loading ok, and the uniforms are being updated regurarly.

Anyoen could find this an interesting phenomena. or help?...please?

2
This "framework" is really powerful, complete and yet it gives absolute freedoom to prototype & design tasks.
The worst part is the building. Lots of hours trying to setup the 5 build scenarios, and still solving problems.

Don't know if it's technically possible to make a source code upload, to the SFML server, wait for 5 minutes and then the sml-dev site offers you the 5 binaries ready to download.

Additional : Upload the source code, a RAR/ZIP with your data files (API need a Resource class manager), ..wait for the server to build and download the binaries and publish your game.

The registered user on the SFML site, just upload the source code! No deep Cmake/Shell/Dependencies/Preprocessor knowledge needed.

Offcourse, limited only to source code using straight and official SFML classes and API, no user-custom extended stuff.

This could help raising SFML popularity, just a few knowledge of a programming language and the API, having your game build in the main 5 platforms with no effort.

Is this a good idea?  ::) :-[

Pages: [1]
anything