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ś
sf::FloatRect rectCam(100,100,400,300);
landerCam.reset(rectCam);
landerCam.setViewport(sf::FloatRect(0.f, 0.f, 1.f, 1.f));
/// ekran ł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łówna pę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