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

Author Topic: why this code is not working , i want to add a button into my window !  (Read 1991 times)

0 Members and 1 Guest are viewing this topic.

Rayan jutt

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
Code: [Select]

#include <SFML/window.hpp>
#include <SFML/system.hpp>
#include <SFML/audio.hpp>
#include <SFML/graphics.hpp>
#include <TGUI/TGUI.hpp>
//#include <SFML/Video.hpp>
//#include <conio.h>

//#include <iostream>

int main()
{
    // Create the window
    sf::RenderWindow window(sf::VideoMode(800, 600), "Window");
    tgui::Gui gui(window);
 
    // Load the font (you should check the return value to make sure that it is loaded)
    gui.setGlobalFont("C:/Users/corleone/Documents/Visual Studio 2010/Projects/MySfml/MySfml/TGUI-0.6-alpha2-Visual-C++10-2010-32-bits/TGUI-0.6-alpha2/fonts/DejaVuSans.ttf");
 
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
 
            // Pass the event to all the widgets (if there would be widgets)
            gui.handleEvent(event);
        }
 
        //window.clear();
 
        // Draw all created widgets
        gui.draw();

tgui::Button::Ptr button(gui);
button->load("C:/Users/corleone/Documents/Visual Studio 2010/Projects/MySfml/MySfml/TGUI-0.6-alpha2-Visual-C++10-2010-32-bits/TGUI-0.6-alpha2/widgets/Button/BabyBlue/Normal.conf");

        window.display();
   








}
return EXIT_SUCCESS;
}



 :(



Rayan jutt

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
Re:
« Reply #1 on: September 08, 2013, 07:12:11 pm »
Please also tell me how can i make list Box in this code ???
and secondly why font file is not loading in this code ???? I need help  ! :(

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: why this code is not working , i want to add a button into my window !
« Reply #2 on: September 08, 2013, 08:48:57 pm »
You're going to have to give a much better description of the problem than "not working" if you want anyone to help.  At least run it in a debugger and give us the error messages.  And if loading external resources is a problem, tell us where the files are and what you think the working directory is and what IDE you're using and all the other obvious stuff we'd need to begin guessing.

Gobbles

  • Full Member
  • ***
  • Posts: 132
    • View Profile
    • Email
Re: why this code is not working , i want to add a button into my window !
« Reply #3 on: September 08, 2013, 09:08:54 pm »
Code: [Select]
...
int main()
{
    // Create the window
    sf::RenderWindow window(sf::VideoMode(800, 600), "Window");
    tgui::Gui gui(window);
 
    // Load the font (you should check the return value to make sure that it is loaded)
    gui.setGlobalFont("C:/Users/corleone/Documents/Visual Studio 2010/Projects/MySfml/MySfml/TGUI-0.6-alpha2-Visual-C++10-2010-32-bits/TGUI-0.6-alpha2/fonts/DejaVuSans.ttf");
...
        //window.clear();
 
        // Draw all created widgets
        gui.draw();

tgui::Button::Ptr button(gui);
button->load("C:/Users/corleone/Documents/Visual Studio 2010/Projects/MySfml/MySfml/TGUI-0.6-alpha2-Visual-C++10-2010-32-bits/TGUI-0.6-alpha2/widgets/Button/BabyBlue/Normal.conf");

        window.display();
 ...

2 things I noticed right away. First, you don't even follow your own comments direction (about checking the return value on the font loading). This leads me to believe you just copied and pasted this code without knowing what your doing.

And second, you load a button every single frame after the gui draw call is done. This also leads me to believe you have no idea what your working on. Understand the libraries your working with before you randomly throw code together and ask why it's not working and ask us to fix it for you.

I apologize if I come off as harsh, but honestly it doesn't even look like you tried...