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

Pages: [1]
1
Graphics / [SFML 2.0] Simple color changing frag-shader does not work
« on: October 13, 2012, 07:49:56 pm »
Hey

I would like to change the color palette as an effect.
So I could replace all colors with just two different colors, so basically changing the color depth to 1 bit.
I decided to use the fragment shader :

uniform vec4 on_bit;
uniform vec4 off_bit;

void main()
{
        vec4 pixel = gl_Color;
        if (pixel.r < 255 || pixel.g < 255 || pixel.b < 255)
                pixel = on_bit;
        else
                pixel = off_bit;
       
        gl_FragColor = pixel;
}

 

And the sfml-part :

    if (!sf::Shader::isAvailable() ||
        !m_ShaderContainer[0].loadFromFile("data//Shader//1bbp.frag", sf::Shader::Fragment))
    {
          // error messages
    }
    else
    {

        std::cout << "Engine : Shader OK !\n";

        m_ShaderContainer[SHADER_1BPP].setParameter("on_bit", sf::Color::Black);
        m_ShaderContainer[SHADER_1BPP].setParameter("off_bit",sf::Color::White);
    }

But all what happens is that the the sprite applied with this shader goes black.
Any help would be appreciated!

2
Graphics / Rendering clear text (SFML 2.0)
« on: September 02, 2012, 10:50:55 pm »
I know there are many post about blurry text, but I feel the need to open a new Thread, since there are things I don't understand yet.

So, I tried to print a small text and discovered  that (with the font I used) SFML can only draw clear texts , when certain sizes are used.
In my case SFML only prints clear, if I use the size 8 or a multiple of it.
Here is image which shows 9 sf::Text object starting with the character size 8 and incrementing to 16.

As you can see, all texts are printed clear(but some still ugly). To achieve this I used the object with the size 8 and scaled every string with it and had to turn smooth of the Font off. Note that all multiples of 8 would draw fine without such a trick. (btw the font used is Pokemon GB.ttf from http://www.fontspace.com/jackster-productions/pokemon-gb)



On the right there are two screenshots from notepad written with the same font.
The top extract is drawn with the size 6 and the bottom one is written with the size 12, so that charactersize 8 is linked to font size 6 in Notepad and 16 equals 12.
So what exactly is meant with charactersize, since it doesnt provide the same result given by notepad, when using equal sizes. This would be my first question.

It is clear to me, that with this technique only multiples of 8 can be drawn correctly , since they only will result in an even scale factor.
Not using this technique will leave most sizes blurry.

The example above is given by the following code :
#include <SFML/Graphics.hpp>
#include <iostream>

//#define CLEAR_FONT // commented, SFML will only draw texts clear with size % 8 == 0
int main()
{
    // Create the main window
    sf::RenderWindow window(sf::VideoMode(320, 180), "SFML window 2.0");

    // Create a graphical text to display
    sf::Font font;
    if (!font.loadFromFile("GB.ttf"))
        return EXIT_FAILURE;
#ifdef CLEAR_FONT
    // 'old' Sfml 1.6 trick
    const sf::Texture* tex = &font.getTexture(8);
    ((sf::Texture*) tex)->setSmooth(false);


    sf::Text MyTexts[9] = { sf::Text("Example", font, 8),  
                            sf::Text("Example", font, 8),
                            sf::Text("Example", font, 8),
                            sf::Text("Example", font, 8),
                            sf::Text("Example", font, 8),
                            sf::Text("Example", font, 8),
                            sf::Text("Example", font, 8),
                            sf::Text("Example", font, 8),
                            sf::Text("Example", font, 8)};

    for (unsigned int i = 1;i < 9;i++)
        MyTexts[i].setScale( (i+8) / 8.0 , (i+8) / 8.0);   // every text will be clear, even when zooming in ( e.g. by resize)
#else

    sf::Text MyTexts[9] = { sf::Text("Example", font, 8),  // will be clear, but blurry when zooming in ( e.g. by resize)
                            sf::Text("Example", font, 9),
                            sf::Text("Example", font, 10),
                            sf::Text("Example", font, 11),
                            sf::Text("Example", font, 12),
                            sf::Text("Example", font, 13),
                            sf::Text("Example", font, 14),
                            sf::Text("Example", font, 15),
                            sf::Text("Example", font, 16)}; // will be clear, but blurry when zooming in ( e.g. by resize)

#endif

    float OffSet_Y = 1;
    for (unsigned int i = 0;i < 9;i++)
    {
        MyTexts[i].setPosition(1.0,OffSet_Y);

        OffSet_Y += MyTexts[i].getGlobalBounds().height + 2;
    }

    // Start the game loop
    while (window.isOpen())
    {
        // Process events
        sf::Event event;
        while (window.pollEvent(event))
        {
            // Close window : exit
            if (event.type == sf::Event::Closed)
                window.close();
        }

        // Clear screen
        window.clear();

        // Draw the string
        for (unsigned int i = 0;i < 9;i++)
            window.draw(MyTexts[i]);

        // Update the window
        window.display();
    }

     return EXIT_SUCCESS;
 }
 

So using this font, I'm forced to only use the character size 8,16,24 and so on.
(If the picture is not available, it's in the attachment)

[attachment deleted by admin]

3
Graphics / sf::string draws in bad quality
« on: June 27, 2011, 08:07:00 am »
Hello.
So I want to display strings with an text and small sizes.
I tried to copy the font in codeblocks.
There you have a Courier font (by default) only 8 pixels big.
Now I go other to sfml, load the font and set the strings size also to 8 pixels, but the quality is completely different than in codeblocks.

I also tried to change the second parameter in the LoadfromFile function from the font object.

Is there any way to reproduce the font-quality from codeblocks or is there just no way to draw that small?

Thank's in advance.

4
General / Child Frames in wxWidgets
« on: May 25, 2011, 09:56:27 pm »
Hi all

So, I want to build an editor for my game with 2 sfml RenderWindows in order to display the map in one frame and the tiles in the other one.
I've done this with a win32 interface but now i want to try it with wxWidgets.
I followed the tutorial and it compiles fine, but it seems when I add the wxSFMLCanvas class to an wxFrame it's position is forced everytime to the origin (0,0) of the wxFrame.
Also the size of the sfml frame is stretched to the size of the whole app.
So I have to catch these events and force it's size and position back to normal.

5
General / [SOLVED]SFML freezes when operating with Win-Api
« on: March 14, 2011, 06:47:41 pm »
Hello

I'm using SFML with the Win32 Api.
I followed the tutorial "Integrating to a Win32 interface" but changed it :
Code: [Select]

    HWND View1 = CreateWindow(szClassName, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 20,  20, 800, 800, hwnd, NULL, hThisInstance, NULL);
    sfview1.SetView(View1);

    HWND View2 = CreateWindow(szClassName, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 1320,  20, 400, 800, hwnd, NULL, hThisInstance, NULL);
    sfview2.SetView(View2);


Instead of "STATIC" I'm using the same string for the main app and for the two sfml views.
This way I can handle events in SFML and main Winproc.

My main loop looks like this :
Code: [Select]

while (messages.message != WM_QUIT)
    {
        if (PeekMessage(&messages, NULL, 0, 0, PM_REMOVE))
        {
            // If a message was waiting in the message queue, process it
            TranslateMessage(&messages);
            DispatchMessage(&messages);
        }
        else
        /*if (!pause) */ // Why sfml is freezing with this ???
        {
            sfview1.act();
            sfview2.act();
        }

        Sleep(1 - (DWORD)Sleeptimer.GetElapsedTime());
        Sleeptimer.Reset();
    }


As you can see I'm using an global bool to stop drawing both subapps.
It can be changed through WinProc of the main app :

Code: [Select]

LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT umsg, WPARAM wParam, LPARAM lParam)
{
     switch (umsg)
    {
         // [...]
         
         case WM_KILLFOCUS :
         {
              pause = true;
              return 0;
          }
          case WM_SETFOCUS :
          {
              pause = false;
              return 0;
          }

        // [...]
    }
    return DefWindowProc(hWnd, umsg, wParam, lParam);
}


So , I click on the menu in order to pop up an dialog and wait 2 secs and the whole thing freezes.
I noticed this also when I build the sfml app without win32-Api.
If you drag the window for a certain time sfml freezes either.

Is there a way while catching the lostfocus event to tell sfml to stop actually ?

I'm using 1.6 : D

Thanks in advance !

EDIT :

Ok I've got it working
The sleeptimer was the problem - I can't use it, when sfview1/2 lost their focus.

Pages: [1]