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

Pages: 1 2 [3]
31
I'm back with the absolute minimum, but complete example that reproduces the issue.

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window;
    window.create(sf::VideoMode(400,300,32), "Test", sf::Style::Default);
    sf::Event event;
    sf::RenderTexture rt;
    sf::Sprite sp;
    sf::Font font;
    font.loadFromFile("visitor1.ttf");
    rt.create(window.getSize().x, window.getSize().y/3.f);
    rt.clear(sf::Color(127,127,127,127));
    sp.setTexture(rt.getTexture(), true);
    sf::Text text;
    text.setString(" Initialization Complete");
    text.setFont(font);
    rt.draw(text);
    rt.display();
    sf::View view;
    while (window.isOpen())
    {
        while (window.pollEvent(event))
        {
            switch (event.type)
            {
                case sf::Event::KeyPressed:
                    window.setSize(sf::Vector2u(std::rand()%1166+200, std::rand()%618+150));
                    view.setSize(window.getSize().x, window.getSize().y);
                    view.setCenter(window.getSize().x/2.f, window.getSize().y/2.f);
                    window.setView(view);
                    rt.create(window.getSize().x, window.getSize().y/3.f);
                    rt.clear(sf::Color(127,127,127,127));
                    rt.draw(text);
                    rt.display();
                    sp.setTexture(rt.getTexture(), true);
                    break;
                case sf::Event::Closed:
                    window.close();
                    return 0;
                default: break;
            }
        }
        window.clear();
        window.draw(sp);
        window.display();
    }
    return 0;
}
 

Doesn't matter if you use waitEvent, or set a framerateLimit(), if or while for the event loop. It will always, out of complete randomness, after having resized quickly or slowly (the input per second), regardless of specific window size, regardless of manually resizing with the mouse (you gotta have an event, I deleted the mouse event because it's not necessary) or with an in-game event, the text will sometimes simply not appear in the RenderTexture.

Try adding an sf::CircleShape, and draw it into the RenderTexture at resize, the circle will be present even if the text disappears.

I have updated SFML-2.0 to the latest release candidate: "LaurentGomila-SFML-757a785" 22.08.2012 UCT+1 @ 10PM.

32
I see. But keep in mind that it really will only show new texts when an input happens, thus you if you print out something that isn't directly connected to an event you might get a delay until a new event occurs.

Aaahh, I know what you mean.

   
window.clear();
debugDraw();
window.display();
 

added to debugUpdate(bool); thanks, useful if a message is lodged without any event to trigger it.
However, the problem of disappearing texts still persists.

Ah I now just saw the pictures (didn't show before) in your first post and I see that your scrollbar is located on the right, whereas I see the scrollbar in the beginning on the left (see picture).

Maybe there is something wrong with your debugUpdate(bool) function. I shall re-paste it here:
Edit: I edited the first post to include the pictures. So it's not your fault for not spotting them.

void resources::debugUpdate(bool debugScrolled = false)
{
    if (debugInfo.size() >= 100) //If the size is this large, it'll take a chunk of 20 items and store it, then continue
        debugLog();
    if (!debugScrolled)
        debugScroll = 0;
    debugWindow.clear(sf::Color(127,127,127,127));
    for (int i = debugScroll; i < debugInfo.size(); i++)
    {
        debugInfo[i].setPosition(0.f, (debugWindow.getSize().y - (debugInfo[(i)].getGlobalBounds().height+5)) - debugInfo[i].getGlobalBounds().height*(i-debugScroll));
        debugWindow.draw(debugInfo[(i)]);
    }
    debugBar.setSize(sf::Vector2f(debugBar.getSize().x, debugWindowY * (debugTextsPerWindow/debugInfo.size())));                                          ///sets a level of percentage, fully represents one screen
    debugBar.setPosition(sf::Vector2f(windowSizeX - debugBar.getGlobalBounds().width, (debugWindow.getSize().y - debugBar.getGlobalBounds().height) - (debugScroll/debugTextsPerWindow)*(debugBar.getGlobalBounds().height) )); ///Okay, so I can change position based on amount of texts and current debugScroll position.
    debugWindow.draw(debugBar);
    debugWindow.display();
    window.clear();
    debugDraw();
    window.display();
}
 

If you care to help me finding out why the debugBar doesn't show correctly with you I'd be grateful. (I'd like this to work on different computers).

33
You are not showing the entire window that contains the RenderWindow, so I can not see what you see.

You should allmost never need to use while(true), it's as bad of a design as using goto statements it's also much more likely to create endless loops...

I merely return 0; if something happens (like window is closed, or escape is pressed), do note that this is an example and I will not have this in my final product. It is simply used to test out this class.

Next thing I wonder is why you create two windows in your resource class?

I fail to spot this, I can only see one instance of sf::RenderWindow. Are you referring to sf::RenderTexture?

I'm not sure if you have noticed this or if you understand what it does, you're using window.waitEvent() instead of pollEvent() thus nothing will happen on your window unless you trigger an event (MouseMove over the window, key pressed, window resized, etc). Is this intentional? I mean you then could only display something when an event is triggered on that window.

Yes, the if (waitEvent()) is intentional for my menus, while (waitEvent()) would not work, as waitEvent() never returns false except for minimizing and maximizing. Why is this intentional? Because nothing really happens, music may play, but sfml creates its own thread regarding that, so I don't need to waste clock cycles on something redundant.

34
Graphics / Re: Text scrolling help
« on: August 19, 2012, 01:49:04 pm »
You'll have to use a sf::Clock and create a delay before adding the next character to the sf::Text to get a scrolling effect.

Yea but there is no sf::Text::push_back, so I suggest he needs to create an std::string (yes, it's "an" before an abbrevation due to the pronunciation of "es", the first letter in std) where you push back each character.
After that, you use sf::Text::setString(std::string) and redraw the text.
Of course you use a delay like exploit3r said, or you could make it dependent on screen refresh rate. sf::RenderWindow::setFramerateLimit(unsigned in);

35
Graphics / Re: Help with sf::View
« on: August 19, 2012, 01:44:07 pm »
Well scaling up does expel some sprites from the rendering area, even if you use your method of iterating through an array/vector of sprites whilst setting the scale for each of them. If the previous sentence is not true, then I don't understand what you really mean.  Also, not all of your sprites will be placed outside your window if you zoom (moderately). Note that you can set the center of your view using sf::View::setCenter(sf::Vector2f(x,y)). Then set the view to the RenderTexture/Window using ::setView(sf::View).

Hope that helps.

36
Thanks for your reply, exploit3r, but to me this is the minimal example (Since all of it is needed).
Have you added about 100 debug-lines? At that point it starts logging chunks of 20 lines at a time. Could you provide a picture where you couldn't see the bar? See the pictures I just posted, it is located on the right of the debug RenderTexture (The slightly darker grey bar).

Edit: Slightly LIGHTER grey bar.  :P

37
Graphics / [Problem]: Disappearing Text upon Resize in a Debug Window
« on: August 19, 2012, 12:42:32 pm »
Hello again, I'm having some trouble with a resource class that contains a debug window with a fully functional scrolling system. It also adjusts itself to new screen (RenderWindow) sizes. Here's my problem and how to reproduce it:

[TO REPRODUCE] : Compile/Build/Run in either Debug or Release mode. Resize the window, again, and again... and sometimes, the text will completely disappear from the debug window. The scroll-bar will still be there tho. LaurentGomila-SFML-2b3d9bd (SFML-2.0 rc) used. Code Blocks 10.05 used. Win7 x86 used.

Normal:


Resized, this happens:


Here's the complete code:

//camelCase all the way!

#include <SFML/Graphics.hpp> //Obvious header
#include <string> //std::string
#include <iostream> //std::cin && std::cout
//#include <vector> //std::vector<type>
#include <cstdio> //std::getchar() (Just to pause an element, it's better than using std::cin >> to pause because you don't need to declare a variable)
#include <deque> //std::deque<type> (Stores sf::Text), I guess I should replace it with pointers to sf::Text)
#include <fstream> //std::ofstream
#include <sstream> //std::stringstream << number << string .str().c_str, used for log + number + .txt

/// A CLASS FOR COMPLETE RESOURCE CONTROL PER WINDOW:
/// resources.hpp
class resources
{
    ///Debugger information and methods:
    sf::RectangleShape debugBar; //The little scroll bar on the right side. Size_x = debugWindow.getSize().x/20?, size_y defined by amount of text. Can be modded to be click-drag-able
    std::deque<sf::Text> debugInfo; //push the front, pop the back.
    sf::RenderTexture debugWindow; //The actual window; size_x = window.getSize().x, size_y = window.getSize().y/3
    void debugUpdate(bool scrolled); //Called after ever << input, as well as scrollDebug
    void debugLog(); //Called if the size of debugInfo becomes too large, takes a chunk and puts it in a log file. File is cleaned on startup. File named after the instance-number of this class e.g.: "log2.txt"
    sf::Font debugFont;
    int debugCharacterSize, scroll;
    int debugThisInstance; //Based off the static debugInstance
    float debugTextsPerWindow, debugTextH, debugWindowY;
    static int debugInstance; //Used for the naming of logs
    bool debugVisible;
    ///Debugger information end.
    int windowSizeX, windowSizeY, windowBitsPerPixel;
    std::string windowTitle;
    sf::View view;
public:
    resources(); //Ctor initialized from the same folder the binaries are in. Currently replacement for dirty, quick initialization
    resources(std::string& rootFolder); //Ctor loads settings from a specific folder, that's how I'd like to handle different windows and their respective settings
    ~resources();
    void resize(); //Also modifies the debugging field
    ///To do with debugging:
    void operator << (std::string debugMessage); //Merely adds a message to the deque
    void operator << (const char * debugMessage);
    void debugScroll(bool upOrDown); //The boolean specifies up or down
    inline void debugDraw(); //Function assumes you have already cleared the window, and that you will display it afterwards. Should always be the last draw();
    void debugToggle();
    ///End of debugging specifications
    sf::Event event;
    sf::RenderWindow window;
};

/// resources.cpp
int resources::debugInstance = 0;

//Private member functions:
void resources::debugUpdate(bool scrolled = false)
{
    if (debugInfo.size() >= 100) //If the size is this large, it'll take a chunk of 20 items and store it, then continue
        debugLog();
    if (!scrolled)
        scroll = 0;
    debugWindow.clear(sf::Color(127,127,127,127));
    for (int i = scroll; i < debugInfo.size(); i++)
    {
        debugInfo[i].setPosition(0.f, (debugWindow.getSize().y - (debugInfo[(i)].getGlobalBounds().height+5)) - debugInfo[i].getGlobalBounds().height*(i-scroll));
        debugWindow.draw(debugInfo[(i)]);
    }
    debugBar.setSize(sf::Vector2f(debugBar.getSize().x, debugWindowY * (debugTextsPerWindow/debugInfo.size())));                                          ///sets a level of percentage, fully represents one screen
    debugBar.setPosition(sf::Vector2f(windowSizeX - debugBar.getGlobalBounds().width, (debugWindow.getSize().y - debugBar.getGlobalBounds().height) - (scroll/debugTextsPerWindow)*(debugBar.getGlobalBounds().height) )); ///Okay, so I can change position based on amount of texts and current scroll position.
    debugWindow.draw(debugBar);
    debugWindow.display();
}

void resources::debugLog() //Operation takes 4.2~0.x ms on a bad school-computer, 5200RPM HDD, 320GB
{
    std::stringstream filename;
    filename << "log" << debugThisInstance << ".txt";
    std::ofstream log(filename.str().c_str(), std::ios::app);
    if (log.is_open())
    {
        for (int i = debugInfo.size()-1; i > (debugInfo.size()-80) && i > 0; i--)
        {
            log << (std::string)debugInfo[i].getString() << '\n';
            debugInfo.pop_back();
        }
    }
    else
        std::cout << std::string("Error saving debug info to log file!\n");
        //If we were to do (*this) << "...", and the file could not be made/opened, we'd end up with a massive, recursive spam!
        //Eventually, the call stack would overflow, the program would terminate.
}

//Public member functions:
resources::resources()
{
    debugInstance++;
    debugThisInstance = debugInstance;
    debugCharacterSize = 10;
    scroll = 0;
    windowSizeX = 400;
    windowSizeY = 300;
    windowBitsPerPixel = 32;
    windowTitle = "Debugger Test!";
    ///DEBUGGER INFORMATION:
    debugFont.loadFromFile("visitor1.ttf"); //Quickly load a font file.
    debugWindow.create(windowSizeX, windowSizeY/3);
    debugWindow.clear(sf::Color(127,127,127,127));
    debugWindow.display();
    debugVisible = true;
    debugBar.setSize(sf::Vector2f(windowSizeX/50, 0));
    debugBar.setFillColor(sf::Color(180,180,180,127));
    debugWindowY = (float) debugWindow.getSize().y;
    *this << " Debugger initialization";
    debugTextH = (float) debugInfo[0].getGlobalBounds().height;
    debugTextsPerWindow = debugWindowY / debugTextH;
    debugUpdate();
    ///END DEBUGGER INFORMATION
    window.create(sf::VideoMode(windowSizeX,windowSizeY,windowBitsPerPixel),windowTitle.c_str(), sf::Style::Default);
}

resources::resources(std::string& rootFolder)
{
}

resources::~resources()
{
}

void resources::resize()
{
    windowSizeX = window.getSize().x;
    windowSizeY = window.getSize().y;
    view = sf::View(sf::FloatRect(0,0,windowSizeX, windowSizeY));
    window.setView(view);
    ///We need to re-initialize some parameters of the debug-texture:
    debugWindow.create(windowSizeX,windowSizeY/3);
    debugBar.setSize(sf::Vector2f(windowSizeX/50, 0));
    debugWindowY = (float) debugWindow.getSize().y;
    debugTextH = (float) debugInfo[0].getGlobalBounds().height;
    debugTextsPerWindow = debugWindowY / debugTextH;
    debugUpdate();
    std::stringstream windowSizes; windowSizes << " Window resized: " << windowSizeX << "x" << windowSizeY;
    *this << windowSizes.str();
}

//Operator << for the debug window
void resources::operator << (std::string debugMessage)
{
    debugInfo.push_front(sf::Text(debugMessage, debugFont, debugCharacterSize));
    debugUpdate();
}

void resources::operator << (const char * debugMessage)
{
    *this << std::string(debugMessage);
}

void resources::debugScroll(bool upOrDown = true)
{
    if (upOrDown && scroll < debugInfo.size()-debugTextsPerWindow && debugInfo.size() > debugTextsPerWindow)
        scroll++;
    else if (scroll > 0 && !upOrDown)
        scroll--;
    debugUpdate(true);
}

inline void resources::debugDraw()
{
    if (debugVisible)
        window.draw(sf::Sprite(debugWindow.getTexture()));
}

void resources::debugToggle()
{
    if (debugVisible)
        *this << " Closing debug window";
    else
        *this << " Opening debug window";
    debugVisible = !debugVisible;
}

/// RESOURCE CLASS.

int main()
{
    resources rsc;
    try
    {
        //A simple loop:
        while (true)
        {
            if (rsc.window.waitEvent(rsc.event))
            {
                switch (rsc.event.type)
                {
                    case sf::Event::Resized:
                        rsc.resize();
                        break;
                    case sf::Event::KeyPressed:
                        switch (rsc.event.key.code)
                        {
                            case sf::Keyboard::Escape:
                                return 0;
                            case sf::Keyboard::Insert:
                                rsc.debugToggle();
                                break;
                            case sf::Keyboard::O:
                                rsc.debugScroll();
                                break;
                            case sf::Keyboard::E:
                                rsc.debugScroll(false);
                                break;
                            case sf::Keyboard::Up:
                                rsc << " Up pressed";
                                break;
                            case sf::Keyboard::Down:
                                rsc << " Down pressed";
                                break;
                            case sf::Keyboard::Left:
                                rsc << " Left pressed";
                                break;
                            case sf::Keyboard::Right:
                                rsc << " Right pressed";
                                break;
                            default: rsc << " unknown button pressed"; break;
                        }
                        break;
                    case sf::Event::Closed:
                        return 0;
                    default: break;
                }
            }
            rsc.window.clear(sf::Color::Black);
            rsc.debugDraw();
            rsc.window.display();
        }
    }
    catch (const char * error)
    {
        std::cout << "Error: " << error << std::endl << "Press enter to exit.";
        std::getchar();
    }
    std::getchar();
    return 0;
}
 

http://fontgal.com/font/10468-visitor
is the font used.

Press 'O' to scroll up (Only works if there's more text than the window)
Press 'E' to scroll down.
Press any arrow key to lodge a respective message.
Insert toggles the debug window.
Press any other key to lodge a standard message.

I've spent several hours tracing it, I searched the web, this forum, no hits. So I am forced to ask it here. My apologies if the question is already answered and I didn't find it.

38
Graphics / Re: Problem Moving Shapes on 'Large' Locations
« on: July 11, 2012, 11:15:32 pm »
If the RS is a pointer you shouldn't use "->" instead of "."?

Well, RS is a pointer:
RS = new sf::RectangleShape[50];
 
but only the first element is of interest here.
Only "." seems to work, "->" doesn't, because RS[0] is an actual element, not a pointer, but RS-> would work. But this is an array, so RS-> would point to RS[0].

@Topic: Yes that's because SFML is working with floats and they aren't that precies. What are you trying to achive with such big numbers?

Yea I figured that out. I'm trying to emulate the solar system.

39
Graphics / Problem Moving Shapes on 'Large' Locations
« on: July 11, 2012, 08:14:36 pm »
        MOVX = 1; MOVY = 0;
        RS[0].move(MOVX, MOVY);
 
RS[0].getPosition().x => 1.49598e+008
RS[0].getPosition().y => 0

I found that, at increasing x distances, the value that MOVX requires, to be consistently higher before moving the object at all. I guess it's the same for the y coordinate.

RS is a pointer to sf::RectangleShape, I use sfml 2.0 RC. I check for movement by drawing a background.

Pages: 1 2 [3]