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

Pages: [1]
1
Graphics / Combining two or more shaders?
« on: November 24, 2010, 07:14:03 pm »
Hi,

Is it possible to apply two different shaders to the same sprite/image?

Something like App.Draw(Draw(mySprite, shaderA), shaderB); (I know that's not proper c++ notation)

Thanks,
Xorlium

2
Graphics / [Bug] Using the same shader for two different things.
« on: November 03, 2010, 08:39:08 pm »
Hi,

If I try to use the same sf::Shader to draw two different things, and then I try not to use the shader, I get a bug.

Here's a minimal example that doesn't work. For this example, you need three images of the same size. Make them very distinct, so that you can see the problem. I include main.cpp and then a file called MyShader.frag

Code: [Select]

#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    if (sf::Shader::IsAvailable() == false)
        return EXIT_SUCCESS;

    sf::RenderWindow App(sf::VideoMode(1024, 768), "SFML Shader test");
    App.UseVerticalSync(true);

    sf::Image SomeImage, AnotherImage, Image;
    SomeImage.LoadFromFile("someimage.png");
    AnotherImage.LoadFromFile("anotherimage.png");
    Image.LoadFromFile("image.png");

    sf::Shader myShader;
    myShader.LoadFromFile("MyShader.frag");
    myShader.SetTexture("imageA", sf::Shader::CurrentTexture);
    myShader.SetTexture("imageB", AnotherImage);

    sf::Sprite sprite1,sprite2,sprite3;
    sprite1.SetImage(SomeImage);
    sprite2.SetImage(SomeImage);
    sprite3.SetImage(Image);

    sprite2.Move(SomeImage.GetWidth(),0);
    sprite3.Move(SomeImage.GetWidth(),SomeImage.GetHeight());


    // Start the game loop
    while (App.IsOpened())
    {
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            // Escape key : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();
        }

        // Clear screen
        App.Clear();

        App.Draw(sprite1, myShader);
        App.Draw(sprite2, myShader);

        App.Draw(sprite3);

        // Finally, display the rendered frame on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}


and MyShader.frag, which is a simple multiply shader
Code: [Select]

uniform sampler2D imageA;
uniform sampler2D imageB;

void main()
{
    vec4 A = texture2D(imageA, gl_TexCoord[0].xy);
    vec4 B = texture2D(imageB, gl_TexCoord[0].xy);

    gl_FragColor = A*B;
}


This compiles and runs, but if you notice the sprite on the bottom-right, the one that is drawn without a shader, it takes the image of the other two (but not the shader effect).

This is very strange, because if I comment just one of the App.Draw(sprite1, myShader); (or with sprite2), then it works fine.

So basically, the fact that I draw sprite1 AND sprite2 (which have shaders) affects how sprite 3 is drawn, even if sprite3 has no shader!

Am I misunderstanding something?

BTW, I'm using latest sfml2 svn checkout, on Kubuntu Linux 10.10, x86_64, but this bug has been present for a while, I just hadn't written a minimal example in which this didn't work, because I was assuming I was doing something wrong.

Xorlium

3
Graphics / [Bug?] sf::Shader, CurrentImage and SetSubRect
« on: November 03, 2010, 07:47:18 am »
Hi,

I'm sorry, my problem is a bit complicated to explain, let me try.

In SFML 2, I'm having the following problem:

I have two images, say Big and Small. Say Big is 200x200 and Small is 100x100.

Then I have a sprite Sprite. I set the image of Sprite to Big, but tell it to only use SubRect of size 100x100 (with sf::Sprite::SetSubRect). Then, I have a shader, which accepts two "variables" of type uniform sampler2D. The two variables are "current" and "other".

I set the "current" to be sf::Shader::CurentImage(). I set "other" to be 'Small'.

Then I do App.Draw(Sprite, Shader).

What you'd expect is that since both images are of size 100x100 (because I chose a subrect of Big of size 100x100), the shader would match them. But the shader actually resizes Small and takes only a quarter of Small, enlarges it, and matches it with Big.

Let me know if any of this makes sense, and if this is indeed the wanted behaviour.

Xorlium

4
Graphics / sf::Image SaveToFile doesn't work in sfml2
« on: October 17, 2010, 10:04:31 pm »
Hi,

I'm using latest svn, freshly svn-updated and compiled.

Here is minimal code that doesn't work:
Code: [Select]
#include <SFML/Graphics.hpp>

int main()
{
    sf::Image myImage;
    myImage.Create(100,100,sf::Color::Blue);

    myImage.SaveToFile("myfile.png");

    return EXIT_SUCCESS;
}


This gives "Segmentation Fault".

I'm using Kubuntu linux, 10.04, x86_64.

I think it used to work in sfml 1.6 :)

Xorlium

Edit: Oh, and saving to .bmp or .jpg DOES work.

5
SFML wiki / [Sources] Video Integration with ffmpeg (Updated: 1.03)
« on: August 25, 2010, 09:25:00 pm »
Hello everyone,

I just posted an object oriented wrapper for ffmpeg and avcodec using SFML on the wiki. Check it out: http://www.sfml-dev.org/wiki/en/sources/video_integration

Comments, suggestions and criticism are very welcome. Specially about code quality. I'm just learning programming. So if I did anything wrong, let me know.

Edit: Version 1.01 now posted. Fixed the choppy-video bug.
Edit: Version 1.02 now posted. Fixed a terrible memory leak.

Also, if you are using SFML 1.6 or earlier, you should replace UpdatePixels by LoadFromPixels in UpdateImage.

6
Feature requests / MNG support?
« on: July 19, 2010, 02:46:13 am »
Hi!

Maybe it's a long shot, but mng support would be nice, to have animated sprites.
http://sourceforge.net/projects/libmng/

Thanks!
Xorlium

7
Graphics / Cover an image except for a little part
« on: July 04, 2010, 08:34:14 pm »
I'm developing a game, and I have a question that I can't figure out how to do it.

Say I have a sf::Sprite displaying a sf::Image in the 'background'. I have thousands of little circles floating on top of that sf::Sprite, and I want the image to display ONLY where those circles are.

In other words, I'm thinking of the little circles as "loopholes" where you can peek into the image.

Can anyone think of a quick way to do this?

What I tried was making the little circles all have images in the shape of round white circles, and then changing those images to copy from the background image (using GetPixel and SetColor).

That was terribly slow. I'm talking about a reduction from ~1500 frames per second I was getting to ~17, and it looked terrible, since the whole solid circle (even if pretty small) became one color.

I'm sure there is a way with blend modes or something. Maybe with anti-alpha?

8
General / Adding a new sf::Vector2f constructor?
« on: May 11, 2010, 04:20:47 am »
Hi,

I'm working on a project using sfml, and I have a Vector2r (vector 2 real) with tons of different functions that I like. sf::Vector2f doesn't have many, so I prefer to use mine. My problem is that the sf functions all accept sf::Vector2f, but not of course Vector2r. I already made a constructor of Vector2r(sf::Vector2f), but how can I do it the other way around, so that I can cast implicitly the vectors?

My solution for now is to define a function
sf::Vector2f r2f(Vector2r v);
and use it everywhere, but that doesn't seem very clean. Is there another way?

Thanks!

9
General discussions / Changing video mode
« on: May 07, 2010, 03:31:02 am »
Hi,

I'm new to SFML, but I'm liking it so far. Just one quick (perhaps newbie) question:

How can I change video mode while the app is running?

I want that if the user presses F o something, it toggles full screen. I've looked through all the possibilities of
a sf::RenderWindow, but I can't find one that says SetVideoMode.

When you create the sf::RenderWindow you need to set video mode, but then how to change it after, I can't figure it out.

Thanks!

Pages: [1]
anything