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

Pages: 1 [2]
16
Graphics / RenderTexture and Shapes: Fantoms Pixels
« on: May 22, 2014, 10:08:50 am »
Helllo!

I have a problem when I use 2 RenderTexture and a CircleShape.
If I draw the on the first RenderTexture, this on the second RenderTexture and then on the screen and if I move the Circle, I obtain som pixels where the circle was and shouldn't be.

I use the last version of sfml 32 bits. I'm on Windows 7 and I use a Nvidia 650M GT (up-to-date). I have tried with last sdk and last version of github. I don't have tried with 64 bits version.

Here is my code:

#include "stdafx.h"
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(500, 500), "SFML works!");
        sf::RenderTexture t1,t2;
        sf::Sprite s1,s2;
    sf::CircleShape shape(10.f);
    shape.setFillColor(sf::Color::Green);

        t1.create(500,500);
        t2.create(500,500);
        s1.setTexture(t1.getTexture());
        s2.setTexture(t2.getTexture());

        int i = 5;

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

                t1.clear();
                t2.clear();
                t1.draw(shape);
                t1.display();
                t2.draw(s1);
                t2.display();

                i += 5;
                shape.setPosition(i,0);

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

    return 0;
}
 

and the result:



Thanks a lot!

17
Java / Re: Use Shader With Text
« on: May 13, 2014, 10:39:16 pm »
:D

You response when I find the solution!
Yes, I've found that Shapes don't have texture, and so my code works now.

I have discovered Shaders yesterday, and I'm very intersted... I'm learning step by step.
I know now how that work in graphic card, how pass parameter, how load it in app, I must learn how write in glsl, but I can do some things now^^

Ask to someone is contrary to my thoughts, I prefer learning.
Wait for implements of antialiasing may be very long, last report is of 2011....

Thx for your response, I continue to learn so!

18
Java / Re: Use Shader With Text
« on: May 13, 2014, 10:22:37 pm »
hum, I have try another shader, found on this forum:

uniform sampler2D samp;

void main()
{
    vec4 texel = texture2D(samp,gl_TexCoord[0].st);
    vec4 pixel = texel * gl_Color;

    // On calcule son niveau de gris
    float gray = pixel.r * 0.39 + pixel.g * 0.50 + pixel.b * 0.11;

    // On écrit enfin le pixel final, en utilisant 50% du pixel de l'écran et 50% de sa version colorée

    gl_FragColor = vec4(gray,gray,gray,pixel.a);
}

My text is gray! It's ok!
But my circle became fully black :/

19
Java / Re: Use Shader With Text
« on: May 13, 2014, 05:25:38 pm »
Ok, now, i try to use this shader:

#version 120
#define FXAA_REDUCE_MIN (1.0/128.0)
#define FXAA_REDUCE_MUL (1.0/8.0)
#define FXAA_SPAN_MAX 8.0
uniform sampler2D sampler0;
uniform vec2 resolution;

void main(){
   vec2 inverse_resolution=vec2(1.0/resolution.x,1.0/resolution.y);
   vec3 rgbNW = texture2D(sampler0, (gl_FragCoord.xy + vec2(-1.0,-1.0)) * inverse_resolution).xyz;
   vec3 rgbNE = texture2D(sampler0, (gl_FragCoord.xy + vec2(1.0,-1.0)) * inverse_resolution).xyz;
   vec3 rgbSW = texture2D(sampler0, (gl_FragCoord.xy + vec2(-1.0,1.0)) * inverse_resolution).xyz;
   vec3 rgbSE = texture2D(sampler0, (gl_FragCoord.xy + vec2(1.0,1.0)) * inverse_resolution).xyz;
   vec3 rgbM  = texture2D(sampler0,  gl_FragCoord.xy  * inverse_resolution).xyz;
   vec3 luma = vec3(0.299, 0.587, 0.114);
   float lumaNW = dot(rgbNW, luma);
   float lumaNE = dot(rgbNE, luma);
   float lumaSW = dot(rgbSW, luma);
   float lumaSE = dot(rgbSE, luma);
   float lumaM  = dot(rgbM,  luma);
   float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
   float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
   vec2 dir;
   dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
   dir.y =  ((lumaNW + lumaSW) - (lumaNE + lumaSE));
   float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL),FXAA_REDUCE_MIN);
   float rcpDirMin = 1.0/(min(abs(dir.x), abs(dir.y)) + dirReduce);
   dir = min(vec2( FXAA_SPAN_MAX,  FXAA_SPAN_MAX),max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),dir * rcpDirMin)) * inverse_resolution;
   vec3 rgbA = 0.5 * (texture2D(sampler0,   gl_FragCoord.xy  * inverse_resolution + dir * (1.0/3.0 - 0.5)).xyz + texture2D(sampler0,   gl_FragCoord.xy  * inverse_resolution + dir * (2.0/3.0 - 0.5)).xyz);
   vec3 rgbB = rgbA * 0.5 + 0.25 * (texture2D(sampler0,  gl_FragCoord.xy  * inverse_resolution + dir *  - 0.5).xyz + texture2D(sampler0,  gl_FragCoord.xy  * inverse_resolution + dir * 0.5).xyz);
   float lumaB = dot(rgbB, luma);
   if((lumaB < lumaMin) || (lumaB > lumaMax)) {
      gl_FragColor = vec4(rgbA,1.0);
   } else {
      gl_FragColor = vec4(rgbB,1.0);
   }
}

and the code of my application is now:

package main;

//import

public
class Main
{
        public static Font FONT = new Font();
       
        public static RenderWindow window = new RenderWindow();
        public static RenderTexture rdrTxt = new RenderTexture();
        public static Text text;
        public static CircleShape cir;
       
        public static Shader FXAA;
       
        public static void main(String[] args)
        {
                try {
                        FONT.loadFromFile(Paths.get("fonts/arial.ttf"));
                        window.setKeyRepeatEnabled(false);
                        ContextSettings settings = new ContextSettings(8);
                        window.create(new VideoMode(680,560), "Crazy-Colors", WindowStyle.RESIZE, settings);
                        window.setVerticalSyncEnabled(true);
                       
                        if (!Shader.isAvailable()) {
                                System.out.println("shader no available");
                        }
                       
                        FXAA = new Shader();
                        Path ShaderPath = FileSystems.getDefault().getPath("FXAA3.txt");
                        FXAA.loadFromFile(ShaderPath, Shader.Type.FRAGMENT);
                        try{
                                FXAA.setParameter("sampler0", Shader.CURRENT_TEXTURE);
                                FXAA.setParameter("resolution", 1,1);
                        }
                        catch (Exception e) {
                                System.out.println("erreur d'argument");
                        }

                        text = new Text("Ceci est un test", FONT);
                        text.setColor(Color.RED);
                        cir = new CircleShape();
                        cir.setRadius(100);
                        cir.setFillColor(Color.BLUE);
                        cir.setPointCount(16);
                        cir.setPosition(50, 50);
                        rdrTxt.draw(cir, new RenderStates(FXAA));
                        rdrTxt.create(680, 560);
                        rdrTxt.draw(text, new RenderStates(FXAA));
                        rdrTxt.display();
                        Sprite result = new Sprite(rdrTxt.getTexture());
                       
                       
                        while (window.isOpen()) {
                                rdrTxt.clear();
                                rdrTxt.draw(cir, new RenderStates(FXAA));
                                rdrTxt.draw(text, new RenderStates(FXAA));
                            rdrTxt.display();

                            window.clear();
                            window.draw(result/*, new RenderStates(FXAA)*/);
                            window.display();
                        }
                       
                } catch (Exception e) {
                        StringWriter errors = new StringWriter();
                        e.printStackTrace(new PrintWriter(errors));
                        System.out.println(errors.toString());
                        window.close();
                }
        }
}
 

but my circle doesn't appear (it appear without the shader).
Any idea?
Do I have pass the good arguments to the shader?

20
Java / Re: Use Shader With Text
« on: May 13, 2014, 04:05:40 pm »
Oooook, I don't have understand that, sorry

I'm going to do more tests with other shaders so

21
Java / Re: Use Shader With Text
« on: May 13, 2014, 03:37:57 pm »
Ok...

There is an full example:

The shader:

void main()
{
    //Compute level of gray
    float gray = dot(gl_Color.rgb, vec3(0.299, 0.587, 0.114));

    //Write destination color
    gl_FragColor = vec4(gray, gray, gray, gl_Color.a);
}

package main;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.jsfml.graphics.Color;
import org.jsfml.graphics.Font;
import org.jsfml.graphics.RectangleShape;
import org.jsfml.graphics.RenderStates;
import org.jsfml.graphics.RenderTexture;
import org.jsfml.graphics.RenderWindow;
import org.jsfml.graphics.Shader;
import org.jsfml.graphics.Sprite;
import org.jsfml.graphics.Text;
import org.jsfml.window.ContextSettings;
import org.jsfml.window.VideoMode;
import org.jsfml.window.WindowStyle;

public class Main
{
        public static Font FONT = new Font();
       
        public static RenderWindow window = new RenderWindow();
        public static RenderTexture rdrTxt = new RenderTexture();
        public static Text text;
       
        public static Shader FXAA;
       
        public static void main(String[] args)
        {
                try {
                        FONT.loadFromFile(Paths.get("fonts/arial.ttf"));
                        window.setKeyRepeatEnabled(false);
                        ContextSettings settings = new ContextSettings(8);
                        window.create(new VideoMode(680,560), "test Shader", WindowStyle.RESIZE, settings);
                        window.setVerticalSyncEnabled(true);
                       
                        if (!Shader.isAvailable()) {
                                System.out.println("shader no available");
                        }
                       
                        FXAA = new Shader();
                        Path ShaderPath = FileSystems.getDefault().getPath("shadertest.txt");
                        FXAA.loadFromFile(ShaderPath, Shader.Type.FRAGMENT);
                        //FXAA.setParameter("blink_alpha", 125);

                        text = new Text("Ceci est un test", FONT);
                        text.setColor(Color.RED);
                        rdrTxt.create(680, 560);
                        rdrTxt.draw(text, new RenderStates(FXAA));
                        rdrTxt.display();
                        Sprite result = new Sprite(rdrTxt.getTexture());
                       
                       
                        while (window.isOpen()) {
                                rdrTxt.clear();
                                rdrTxt.draw(text, new RenderStates(FXAA));
                            rdrTxt.display();

                           
                            window.clear();
                            window.draw(result);
                            window.display();
                        }
                       
                } catch (Exception e) {
                        System.out.println("rtrt");
                        StringWriter errors = new StringWriter();
                        e.printStackTrace(new PrintWriter(errors));
                        window.close();
                }
        }
}
 

and the result without shader:



with shader:



Where is the error?

22
Java / Re: Use Shader With Text
« on: May 13, 2014, 11:42:31 am »
Are you doing allusion to the setParameter of shader?

It's the first time I use Shaders, yes... I'm a little lost...

Can you link maybe a good tutorial website?

I've already read some texts, but they don't help me.
I think that I have understood how they work, but not why greyscale fail...
Ok for the first, I have forgotten to link the texture, I know it now, but for the second shader?

23
Java / Re: Use Shader With Text
« on: May 13, 2014, 10:09:24 am »
No, I don't understand.

I check the samples :

// ... (create window)

//Ensure that shaders are available on this system
if(!Shader.isAvailable()) {
    System.err.println("Sorry, your hardware does not support shaders!");
    return;
}

//Create the shader and attempt to load the program
Shader grayscale = new Shader();
try {
    grayscale.loadFromFile(new File("grayscale.frag"), Shader.Type.FRAGMENT);
} catch(IOException|ShaderSourceException ex) {
    ex.printStackTrace();
    return;
}

//Attempt to create the render texture
RenderTexture rtex = new RenderTexture();
try {
    rtex.create(window.getSize().x, window.getSize().y);
} catch(TextureCreationException ex) {
    ex.printStackTrace();
    return;
}

//Create a sprite with the result texture
Sprite resultSprite = new Sprite(rtex.getTexture());

//Main loop
while(window.isOpen()) {
    rtex.clear();
    rtex.display();

    //Draw the result sprite on the window using the grayscale shader
    window.clear();
    window.draw(resultSprite, grayscale);
    window.display();
}

And I do exaclty the same thing.
The grayscale don't take a texture in argument. So, why pass a texture in argument?
The difference is window.draw(resultSprite, grayscale); where I canno't pass a shader as 2nd argument, but a RenderStates only...

I'm really lost

24
Java / Re: Use Shader With Text
« on: May 13, 2014, 12:06:18 am »
hoooo,

I understand nothing now... I'm so tired... I go sleep, I'll see that tomorrow... Thx Laurent, and sorry

25
Java / Re: Use Shader With Text
« on: May 12, 2014, 11:52:45 pm »
How can i do that?

I have tried this:

states = new RenderStates(FXAA);
                        states.texture = RenderTexture;

but "texture" is a final member of states

26
Java / Use Shader With Text
« on: May 12, 2014, 11:20:19 pm »
Hi,

First: sorry for my bad English^^

Here is my problem: I would like to enable antialiasing on renderTexture. It seems to be impossible. So, Laurent Gomila say me to use shaders.
But they don't work...
I test with that shader:

uniform sampler2D texture;
uniform float blink_alpha;

void main()
{
    vec4 pixel = gl_Color;
    pixel.a = blink_alpha;
        gl_FragColor = pixel;
}

And here is my shader loading:

public static Shader FXAA;
if (!Shader.isAvailable()) {
        Log.OutError("Impossible de prendre en charge les shader...");
}
                       
FXAA = new Shader();
Path ShaderPath = FileSystems.getDefault().getPath("blink.frag");
FXAA.loadFromFile(ShaderPath, Shader.Type.FRAGMENT);
FXAA.setParameter("blink_alpha", 125);

RenderTexture.draw(obj, new RenderStates(FXAA));

But i get a black screen. Without shader, all is fine.
If I use the shader test of jsfml :

void main()
{
    //Compute level of gray
    float gray = dot(gl_Color.rgb, vec3(0.299, 0.587, 0.114));

    //Write destination color
    gl_FragColor = vec4(gray, gray, gray, gl_Color.a);
}

I get this: All is good, but not the text:



Really thanks to you to help me...

Pages: 1 [2]