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

Pages: [1]
1
General / Re: Help with basic fragment-shadered full-screen sprite
« on: February 13, 2019, 08:55:34 am »
I see, just a minimal drawable and the address of a sf::Shader instanciated object does the trick.
Thanks too.

hi

no need to use sprite and texture to draw fragment shader. just use sf::RectangleShape to get fullscreen to draw on it. also, no need to provide the vertex shader. like so:

#include <SFML/Graphics.hpp>


#define GLSL120(src) "#version 120 core\n" #src

static const char* frag = GLSL120(

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.);
        }
}

);

int main()
{
        sf::RenderWindow window({ 800, 600 }, "SFML Shader Example");
        window.setMouseCursorVisible(false);

        sf::RectangleShape fullscreen({ 800, 600 });
        sf::Shader shader;
        if (!shader.loadFromMemory(frag, sf::Shader::Fragment))
                return -1;

        shader.setUniform("resolution", sf::Vector2f({ 800, 600 }));

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

                shader.setUniform("time", clock.getElapsedTime().asSeconds());

                window.clear();
                window.draw(fullscreen, &shader);
                window.display();
        }
}

2
General / Re: Help with basic fragment-shadered full-screen sprite
« on: February 12, 2019, 06:01:09 pm »
Yaaay...  :-[ Thanks Laurent and eXpl0it3r!

Yes, I just need the fragment stuff, and let the full-screen sized sprite draw by himself.
 No Geometry shader needed the coords are totally ok as by default in sf::Sprite rasterization in this case.

So I must remove the Geometry shader, having a GLSL code wrong or not, It's useless and breaks things :

  std::string CodiSharedQUADFixe = "void main(void)       {       gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;                 }";                    
                        if (sh.loadFromMemory(CodiSharedQUADFixe, sf::Shader::Geometry))
                                ShaderGeom_isOk = true;

Thanks! Now my gamedev can go on!

3
General / Re: A possible bug in sf::Shader and a thing that not works
« on: February 12, 2019, 04:30:09 pm »
OK, I recognize that was a bit rush exposition of my problems.
I've ended up with wrong load error handling, on my own.
So, yes, loadFromFile from sf::Shader works perfectly.

Fine but I still can't see the fullscreen sprite-shader because, I guess, using a totally bad vertex shader (it does even load with a TRUE return).

My question: is this Vertex shader ok with SFML internals in order to render a full screen sprite with a fragment shader as texture?

   std::string CodiSharedQUADFixe = "void main(void)    {   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;         }";         
        sh.loadFromMemory(CodiSharedQUADFixe, sf::Shader::Geometry);
 
Isolated GLSL :
void main(void)    {   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;         }

The Sprite-fragment shaded code, a class to render a full screen sized sprite with a fragment-shader texture :

#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);
                       
                        //loadFromMemory
                        //if (sh.loadFromFile("Data/gfx/baseVertex.glsl", sf::Shader::Geometry))
                        std::string CodiSharedQUADFixe = "void main(void)       {       gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;                 }";                    
                        if (sh.loadFromMemory(CodiSharedQUADFixe, sf::Shader::Geometry))
                                ShaderGeom_isOk = true;

                        if (sh.loadFromFile("Data/gfx/CampDestels.glsl", sf::Shader::Fragment))                        
                                ShaderFrag_isOk = true;
                }
                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

Thanks eXpl0it3r, for the "collaterals" idea. Now I've rebuild a simple alone main() c++, for testing, so now my problems are located in the improper vertex shader, I guess.

#include <SFML/Graphics.hpp>
#include <list>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <string>

#include "FondosFX.h"
int main()
{
        sf::RenderWindow window;
        window.create(
                sf::VideoMode(
                        640,
                        480,
                        32), "PLanet Busters",
                sf::Style::None);

window.setVerticalSyncEnabled(true);
window.setFramerateLimit(30);
sf::WindowHandle handle = window.getSystemHandle();
window.setMouseCursorVisible(false);

FonsFX::FonsEfecte *ELFonsDestelsFx;

ELFonsDestelsFx = new FonsFX::FonsEfecte(
        window.getSize().x, window.getSize().y);

sf::Clock clock;
                       
while (window.isOpen())
{
        sf::Event event;
        while (window.pollEvent(event))
        {
                switch (event.type)
                {
                case sf::Event::Closed:
                        window.close();
                        break;
                case sf::Event::KeyPressed:
                        if (event.key.code == sf::Keyboard::Escape)
                        {
                                window.close();
                        }
                }
        }
        window.clear(sf::Color(180, 180, 180, 255));

        ELFonsDestelsFx->UpdateFXvar("time", clock.getElapsedTime().asSeconds());
        ELFonsDestelsFx->UpdateFXvar("resolution", sf::Vector2f(window.getSize().x, window.getSize().y));

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

and the CampDestels.glsl fragment shader file :
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.);
        }
}
 

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

5
Feature requests / Re: Making SFML work with web assembly?
« on: February 05, 2019, 08:21:36 pm »
Well this is a really nice great idea, for this reasons:

  • C++ is a more friendly language to work with, as javascript is a selfish pain in the ass for the sake of its own philosophy and semantics.
  • Will solve the hard task of building the 5 binaries (iOS,OSx,Win,Android,Linux) and always demanding a constant upgrade due to google policies or SDK deprecations.

But the bad points on browsers are : less optimization and worse performance then more CPU requeriments needed, full-screen issues, browser peculiarities.


6

Thank Apple for restricting their products so much. ::)
You can basically setup Travis to build on macOS and for iOS, but to actually test and fix issues with these platforms, you will have to buy an Apple device.
Travis services are for free in case of a non-profit videogame? What If i'm charging like 1.5€ on itch.io?

...and agree also in this. Finally I've got by myself to this conclusion, after days of dependencies/wmake fighting with almost no useful results :
you can also find the funding to buy/rent/ask a friend for a macOS machine. ;)

Anyway, the testing must be done on the real OS/hardware. That touch input multi-finger issues,etc...

7
Ok. Well, this is pretty discouraging. Neither I owe a Mac to build iOS OsX :

https://github.com/SFML/SFML/wiki/Tutorial%3A-SFML-for-iOS

Let me ask : Is there no other way to build a regular example/pong.cpp for the Apple hardware?

I mean, once you've coded and tested the game playability bugs and design robustness, debugged in realtime on your favourite IDE and host platform, what's left?!¿ the building, so, it's there no way to make this easy? or even automatic? seems not.  :-[
 
Compared to the music industry is like, the producer and musician had to deal with the mechanics of the vinyl press machine, the industrial CDR duplicator drivers, or even that old Polish cassette tape replicator maintenance.

 :-\ :'(


8
I already have experience in Win32 (demoscene, custom C++, OpenGL GLSL demo-engine)
Just got tired of upgrading by myself ffmpeg/Bass/GLSL wrappers to build perfectly every time Windows updates itself and breaks everything.

So I've found SFML, and works perfectly for me, as I'm not in the mood of re-doing all the basics again plus all the multiplatform configurations and library compiling and linkage.

Yes, was a crazy idea: maintaining 5 diferent Virtualized Machine images, with perfect and ready compiling environments, and 5 by-demand calls per every user uploading a MyGame.cpp, to generate the 5 binaries.
It's crazy.

So, basically this morning I've spend 12 hours reading and understanding all the API documentation, and got myself with an example/PONG.CPP and it's basically the same in the 5 snapshots https://artifacts.sfml-dev.org/by-branch/master/ <- this is pretty useful!

So that's the point : 1 single sourcecode and 5 cmake configurations to build it 5 times for each platform.

Thank you a lot for the TIP : "See how SFML is built on all five major platforms with Travis: https://travis-ci.org/SFML/SFML/builds/483426120"

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