Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Drawing sf::Text in nested loop  (Read 2474 times)

0 Members and 1 Guest are viewing this topic.

not

  • Newbie
  • *
  • Posts: 2
    • View Profile
Drawing sf::Text in nested loop
« on: February 15, 2014, 08:58:36 pm »
Hi, It's my second attemp to post after this forum unlogged me...
I have interesting problem with rendering sf::Text in menu loop located in main loop. Everthing in menu loop display, expect sf::Text. In main loop everything renders with no problems.

VC++


main.cpp
#include <SFML/Graphics.hpp>
//#include <SFML/System.hpp>
#include <iostream>
#include <Windows.h>
#include <vector>

#include "cButton.h"

sf::RenderWindow window(sf::VideoMode(800, 600), "Mun Lander! Alfa 0.1");
sf::Font font;


void fMenu( bool gameOn, sf::Event & eventG )
{
       
        menu::cButton butKontynuuj(font);
        menu::cButton butNowaGra(sf::String("Nowa Gra"),font);

        //desperation act
         
        sf::ConvexShape sAktDesperacji;
        sAktDesperacji.setPosition(300,300);
        sAktDesperacji.setPointCount(4);
        {
                        sAktDesperacji.setPoint(0, sf::Vector2f(-25,-23));
                        sAktDesperacji.setPoint(1, sf::Vector2f(25,-23));
                        sAktDesperacji.setPoint(2, sf::Vector2f(20,0));
                        sAktDesperacji.setPoint(3, sf::Vector2f(-20,0));
        }

        window.setView(window.getDefaultView());
       
        while (window.isOpen())
        {
               
                while (window.pollEvent(eventG))
        {
                        if (eventG.type == sf::Event::Closed)
                        {
                window.close();
                        }
                        if (eventG.type == sf::Event::KeyPressed && eventG.key.code == sf::Keyboard::Escape )
                        {
                                return;
                        }
                }


               
                window.clear(sf::Color(00,20,20));
               
               
                //desperation act, if it appears... You are in menu

                window.draw(sAktDesperacji);
               
                window.draw(butKontynuuj.drawButton());
                window.draw(butNowaGra.drawButton());
               

                window.display();
        }


}

///////////////////////////////////////////////////////////////////////////////////////////////////////




int main()
{
       
       
   
        window.setFramerateLimit(80);
        sf::View defaultCam(window.getDefaultView());
        sf::View landerCam;

        ///Co&#347;
        sf::FloatRect rectCam(100,100,400,300);
        landerCam.reset(rectCam);
        landerCam.setViewport(sf::FloatRect(0.f, 0.f, 1.f, 1.f));
        /// ekran &#322;adowania

        /// inicjalizacja zmiennych i obiektów gry
       

       
// you should change that
        font.loadFromFile("Volter.ttf");

        sf::Event eventG;

       

        srand( time( NULL ) );
       

        //////////////////////////////////////////////////////////////////////////////
        /// test

        menu::cButton aktDesperacji2(sf::String("*GAME HAPPENS HERE*\nexplosions, craters, and space landers"),font);




               
       
       
        /// g&#322;ówna p&#281;tla gry

    while (window.isOpen())
    {
               

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


                        if (eventG.type == sf::Event::MouseWheelMoved && eventG.mouseWheel.delta > 0 )
                        {
                                landerCam.zoom(1.1f);
                                defaultCam.zoom(1.1f);
                        }
                        if (eventG.type == sf::Event::MouseWheelMoved && eventG.mouseWheel.delta < 0 )
                        {
                                landerCam.zoom(0.9f);
                                defaultCam.zoom(0.9f);
                        }
                        if (eventG.type == sf::Event::KeyPressed && eventG.key.code == sf::Keyboard::Escape )
                        {
////////Here menu starts
                                fMenu( true, eventG );
                                zegFiz.restart();
                        }

                       
        }

               
               
               


        window.clear();
               
                window.setView(window.getDefaultView());

        window.display();
    }

    return 0;
}  
 


cButton.h
#pragma once
#include <SFML/Graphics.hpp>
namespace menu
{

class cButton
{
        sf::String  butString;
        sf::Text butText;



public:
        cButton(sf::Font&);
        cButton(sf::String,sf::Font&);
        ~cButton(void);
        sf::Text const & drawButton();
        sf::Vector2f const getPosition();
       
};

} //namespace
 

cButton.cpp
#include "cButton.h"


namespace menu
{

        cButton::cButton(sf::Font& font)
        {
                butString = "Typical text button";
                butText.setString( butString);
                butText.setPosition(200,200);
                butText.setCharacterSize(30);
                butText.setScale(1,1);
                butText.setFont( font );
        }

        cButton::cButton(sf::String str, sf::Font & font)
        {
                butString = str;
                butText.setString( butString);
                butText.setPosition(200,200);
                butText.setCharacterSize(30);
                butText.setScale(1,1);
                butText.setFont( font );
        }


        cButton::~cButton(void)
        {
        }

        sf::Text const & cButton::drawButton()
        {
                return butText;
        }

        sf::Vector2f const cButton::getPosition()
        {
                return butText.getPosition();
        }

} //namespace menu
 

Regards

btw, English grammar hard very is :)

//edited code, some translations
 
« Last Edit: February 15, 2014, 10:45:54 pm by not »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Drawing sf::Text in nested loop
« Reply #1 on: February 15, 2014, 09:11:59 pm »
For what it's worth; I have no problems drawing sf::Text in my own applications, so I'd say that SFML works fine.
As for your code; could you post a complete and minimal example that shows the problem? I (and I guess others) don't want to read through more code than needed to help with a problem.

Hapax

  • Hero Member
  • *****
  • Posts: 3378
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Drawing sf::Text in nested loop
« Reply #2 on: February 15, 2014, 09:19:06 pm »
You should remove code that isn't a part of your problem. It should be complete and minimal. This is certainly not minimal, and - since it doesn't compile - I'd say it doesn't count as complete either.

EDIT: I commented the two external requirements (cLander.h and cSurf.h), and replaced the font filename with one I have and it works fine. It's possible that your font is failing to load. If you didn't use "FreeConsole", you would've seen that :P
« Last Edit: February 15, 2014, 09:28:55 pm by Golden Eagle »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Drawing sf::Text in nested loop
« Reply #3 on: February 15, 2014, 09:29:57 pm »
Please also use [code=cpp] tags, not [code]. Like this, C++ code is syntax-highlighted:
#include <SFML/Graphics.hpp>

int main()
{
}
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

not

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Drawing sf::Text in nested loop
« Reply #4 on: February 15, 2014, 10:09:22 pm »
Sorry :P. My code has been deleted before I sent it. In anger I sent this ugly code.
Tags changed. In polish forum we have [cpp] tags, so I get use write this one.

I hope it will work. I edited that in my smrt phone.

edit: Golden Eagle. I tested that. Debbug says that my font is in sf::Text in each place. Any errors from sfml in console
« Last Edit: February 15, 2014, 10:46:50 pm by not »

 

anything