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

Pages: [1]
1
Graphics / Re: What is the default z-value on SFML?
« on: July 05, 2012, 09:14:02 am »
I am using the OpenGL lighting system in SFML.
I am aware that SFML is 2D, but must have a z-value.

2
Graphics / What is the default z-value on SFML?
« on: July 05, 2012, 07:23:59 am »
Good night...
I read this topic and I have the same question about Z axis default value on sfml 2.0
Thanks..

3
Graphics / Re: sf::Shader + sf::RenderTexture = Malfunction
« on: April 10, 2012, 02:06:51 pm »
Of course  ;)

4
Graphics / Re: class sf::Shader doesn't load Vertex & Fragment Shader
« on: April 10, 2012, 01:45:10 pm »
Oh my goodness!
I change the code of the Vertex Shader to:
void main(){
       
        gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
        gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
 
and.... It works!
I think I was using a deprecated way of calculating the gl_TexCoord [ 0], which strangely worked well in Shader Designer.

Thanks!

5
Graphics / Re: sf::Shader + sf::RenderTexture = Malfunction
« on: April 10, 2012, 01:16:02 pm »
Excuse me.. my case is if i don't call
    shaderTexture.display();
 
When I draw another sf:Sprite into the renderTexture, they  are drawing in sf::Window upside down.

If I make the call to the method, the issue with the Sprites.... disappears but  the relief generated by the shader is turned upside down and flip horizontal.


6
Graphics / class sf::Shader doesn't load Vertex & Fragment Shader
« on: April 10, 2012, 12:58:38 pm »
 Hello!
My problem starts when I use this way to load a shader:
sf::Shader miShader;
miShader.loadFromFile("shader/bumpmap.vert","shader/bumpmap.frag");
 

Vertex Shader:
void main(){
        gl_TexCoord[0] = gl_MultiTexCoord0;
        gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
 
Fragment Shader:
// Textura y Bumpmap
uniform sampler2D normalTexture;
uniform sampler2D texture;
//variables internas
uniform vec3 position;

void main()
{
        // El color del pixel actual en el Normal Map
        vec4 normColor = texture2D(normalTexture, gl_TexCoord[0].st);
       
        // El color del pixel actual en la Textura
        vec4 texColor = texture2D(texture, gl_TexCoord[0].st );
       
        // El vector normal al Normal Map
        vec3 normalMapVector = 2.0 *(normColor.rgb - 0.5);
       
        // Calculamos el vector de la Luz
        vec3 light = normalize(gl_LightSource[0].position.xyz - position);
       
        // Calculamos el vector del Ojo
        vec3 E = normalize(-position); // we are in Eye Coordinates, so EyePos is (0,0,0)  
       
        // Calculamos el vector ??
        vec3 R = normalize(-reflect(light,normalMapVector));    
       
        // Calculamos el efecto de diffuse
    vec4 Idiff = gl_LightSource[0].diffuse * max(dot(normalMapVector,light), 0.0);  
    Idiff = clamp(Idiff, 0.0, 1.0);
   
    // Calculamos el efecto de ambient
    vec4 Iamb = gl_LightSource[0].ambient;
   
    // calculate Specular Term:
    vec4 Ispec = gl_LightSource[0].specular * pow(max(dot(R,E),0.0),0.3*gl_FrontMaterial.shininess);
    Ispec = clamp(Ispec, 0.0, 1.0);
   
    //
        gl_FragColor = Idiff*texColor + Iamb + Ispec;  
}
 
If i only use the fragment shader, no problem, but if i use both then only paints a rectangle of a color similar to the diffuse map.

7
Graphics / Re: sf::Shader + sf::RenderTexture = Malfunction
« on: April 10, 2012, 12:42:52 pm »
This is not a problem, have you read the comments in the issue?
I read the comments and YES it is a problem for the shader that the image is upside down with a horizontally flip, modifying the normal way it works...


A patch solution to this abnormal behavior is to invest in the same sense the image of the bump map, which I think is inappropriate and impractical.


8
Graphics / Re: sf::Shader + sf::RenderTexture = Malfunction
« on: April 09, 2012, 01:19:26 am »
My code is now like this:

// Inclusion de OpenGL
#include <SFML/OpenGL.hpp>

#include <SFML/Graphics.hpp>

#define NORMAL_OTHER "shader/otro_normal.png"
#define TEXTURE_OTHER "shader/otro_texture.png"

int main() {

        sf::RenderWindow window(sf::VideoMode(1280, 720), "window!!!");

        sf::Shader miShader;
        miShader.loadFromFile("shader/bumpmap.frag",sf::Shader::Fragment);

        glShadeModel (GL_SMOOTH);
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
       
        GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
        GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
        GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
        GLfloat mat_shininess[] = { 100.0 };
        GLfloat light_position[] = { 200.0, 200.0, 800.0, 0.0 };

        glLightfv(GL_LIGHT0, GL_POSITION, light_position);
        glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
        glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
        glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
        glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

       
        // Normal Map
        sf::Texture texturaOtra; 8)
        if (!texturaOtra.loadFromFile(NORMAL_OTHER)) {
                return EXIT_FAILURE;
        }
        // Load a sprite to display
        sf::Texture otra;
        if (!otra.loadFromFile(TEXTURE_OTHER)) {
                return EXIT_FAILURE;
        }
        sf::Sprite spriteOtra(otra);
       
        spriteOtra.setPosition(150,150);
        sf::Vector2f p;
        p = spriteOtra.getPosition();
        sf::Vector3f p2 = sf::Vector3f(p.x,p.y,0.0);
        miShader.setParameter("position",p2);
        miShader.setParameter("normalTexture", texturaOtra);
        miShader.setParameter("texture", sf::Shader::CurrentTexture);

        sf::RenderTexture shaderTexture;
        if(!shaderTexture.create(1280,720))
                return -1;

    // Start the game loop
        bool done = false;

        while (!done) {                
                // Process events
                sf::Event Event;
                while (window.pollEvent(Event)) {
            // Close window : exit
                        if (Event.type == sf::Event::Closed) {
                                done = true;
                        }
        }

        // Clear screen
                window.clear();
               
                shaderTexture.clear();          
                shaderTexture.draw(spriteOtra);
                shaderTexture.display();

                window.draw(sf::Sprite(shaderTexture.getTexture()),&miShader);
               
                window.display();

                }
        window.close();
    return EXIT_SUCCESS;
}
 

With this code, the lights and the shader works, but another problem arises: Bad News

9
Graphics / Re: sf::Shader + sf::RenderTexture = Malfunction
« on: April 08, 2012, 09:35:20 pm »
the shader's code is:
// Textura y Bumpmap
uniform sampler2D normalTexture;
uniform sampler2D texture;
//variables internas
uniform vec3 position;

void main()
{
        // El color del pixel actual en el Normal Map
        vec4 normColor = texture2D(normalTexture, gl_TexCoord[0].st);
       
        // El color del pixel actual en la Textura
        vec4 texColor = texture2D(texture, gl_TexCoord[0].st );
       
        // El vector normal al Normal Map
        vec3 normalMapVector = 2.0 *(normColor.rgb - 0.5);
       
        // Calculamos el vector de la Luz
        vec3 light = normalize(gl_LightSource[0].position.xyz - position);
       
        // Calculamos el vector del Ojo
        vec3 E = normalize(-position); // we are in Eye Coordinates, so EyePos is (0,0,0)  
       
        // Calculamos el vector ??
        vec3 R = normalize(-reflect(light,normalMapVector));    
       
        // Calculamos el efecto de diffuse
    vec4 Idiff = gl_LightSource[0].diffuse * max(dot(normalMapVector,light), 0.0);  
    Idiff = clamp(Idiff, 0.0, 1.0);
   
    // Calculamos el efecto de ambient
    vec4 Iamb = gl_LightSource[0].ambient;
   
    // calculate Specular Term:
    vec4 Ispec = gl_LightSource[0].specular * pow(max(dot(R,E),0.0),0.3*gl_FrontMaterial.shininess);
    Ispec = clamp(Ispec, 0.0, 1.0);
   
    //
        gl_FragColor = Idiff*texColor + Iamb + Ispec;  
}
 

PD: I find another issue with renderTexture.

10
Graphics / Re: sf::Shader + sf::RenderTexture = Malfunction
« on: April 07, 2012, 10:35:05 pm »
The problem is simple, I can not apply the bump map. I tried shaders only change the color and working but not with the following fragment shader.
And the problem with the OpenGL light is solved by putting the following lines
sf::RenderTexture shaderTexture;
        if(!shaderTexture.create(1280,720))
                return -1;
 
below the shader creation.

11
Graphics / sf::Shader + sf::RenderTexture = Malfunction
« on: April 07, 2012, 08:52:36 pm »
Hello!
I'm trying to draw the resulting texture after applying a shader, into a new texture.
But the problem is that after doing this:
shaderTexture.create(1280,720);
 
the area where he painted the resulting texture now is just white.

My code is :
// Inclusion de OpenGL
#include <SFML/OpenGL.hpp>

#include <SFML/Graphics.hpp>

#define NORMAL_OTHER "shader/otro_normal.png"
#define TEXTURE_OTHER "shader/otro_texture.png"

int main() {
        sf::RenderWindow window(sf::VideoMode(1280, 720), "window!!!");
        sf::Shader miShader;
        miShader.loadFromFile("shader/bumpmap.frag",sf::Shader::Fragment);

        sf::RenderTexture shaderTexture;
        if(!shaderTexture.create(1280,720))
                return -1;

        glShadeModel (GL_SMOOTH);
       
        GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
        GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
        GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
        GLfloat mat_shininess[] = { 100.0 };
        GLfloat light_position[] = { 200.0, 200.0, 800.0, 0.0 };

        glLightfv(GL_LIGHT0, GL_POSITION, light_position);
        glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
        glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
        glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
        glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);

        // Normal Map
        sf::Texture texturaOtra;
        if (!texturaOtra.loadFromFile(NORMAL_OTHER)) {
                return EXIT_FAILURE;
        }
        // Load a sprite to display
        sf::Texture otra;
        if (!otra.loadFromFile(TEXTURE_OTHER)) {
                return EXIT_FAILURE;
        }
        sf::Sprite spriteOtra(otra);
       
        spriteOtra.setPosition(150,150);
        sf::Vector2f p;
        p = spriteOtra.getPosition();
        sf::Vector3f p2 = sf::Vector3f(p.x,p.y,0.0);
        miShader.setParameter("position",p2);
        miShader.setParameter("normalTexture", texturaOtra);
        miShader.setParameter("texture", sf::Shader::CurrentTexture);

    // Start the game loop
        bool done = false;

        while (!done) {                
                // Process events
                sf::Event Event;
                while (window.pollEvent(Event)) {
            // Close window : exit
                        if (Event.type == sf::Event::Closed) {
                                done = true;
                        }
        }

        // Clear screen
                window.clear();
               
                shaderTexture.clear();         
                shaderTexture.draw(spriteOtra,&miShader);
                shaderTexture.display();
                window.draw(sf::Sprite(shaderTexture.getTexture()));
               
                window.display();

                }
        window.close();
    return EXIT_SUCCESS;
}
 

My system specifications are:
OS: Windows 7 Professional 64bits
Video Card: AMD Radeon HD 6670
IDE: Visual Studio 2008 Professional.
SFML version: 2.0 (downloaded from the official site in early March).

Sorry for my terrible English....

Pages: [1]
anything