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

Author Topic: Place RenderWindow as Global  (Read 10407 times)

0 Members and 1 Guest are viewing this topic.

armage

  • Newbie
  • *
  • Posts: 10
    • View Profile
Place RenderWindow as Global
« on: February 18, 2008, 09:49:32 pm »
Hi Guys,

How do you do?  :D

I want to place "sf:RenderWindow App" as a Global variable.

I have Global.h and a Global.cpp.

In Global.h
Code: [Select]

#include <SFML/Graphics.hpp>
extern sf::RenderWindow App;

In Global.cpp:
Code: [Select]

#include "Global.h"
sf::RenderWindow App;


In Main.cpp:
Code: [Select]

App = new sf::RenderWindow(sf::VideoMode(640, 480, 32), "SFML Window");


Why cant I do this? If not how do I make RenderWindow global?

C:\_libraries\SFML\include\SFML/Window/Window.hpp(291) : error C2248: 'sf::NonCopyable::operator =' : cannot access private member declared in class 'sf::NonCopyable'
        C:\_libraries\SFML\include\SFML/System/NonCopyable.hpp(65) : see declaration of 'sf::NonCopyable::operator ='
        C:\_libraries\SFML\include\SFML/System/NonCopyable.hpp(42) : see declaration of 'sf::NonCopyable'
        This diagnostic occurred in the compiler generated function 'sf::Window &sf::Window::operator =(const sf::Window &)'[/code]

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Place RenderWindow as Global
« Reply #1 on: February 19, 2008, 02:44:17 am »
1/ Using a global is bad, especially with this kind of class. Try to find a better design ;)

2/ new will return you a pointer, so your App variable should be a sf::RenderWindow* in this case

3/ You don't need to use the constructor (and dynamic allocation), just use the Create function, which takes exactly the same parameters as the constructor
Laurent Gomila - SFML developer

armage

  • Newbie
  • *
  • Posts: 10
    • View Profile
Place RenderWindow as Global
« Reply #2 on: February 19, 2008, 07:32:43 am »
>1/ Using a global is bad, especially with this kind of class. Try to find a better design

I am, just trying to adapt my old work to your framework.
 :lol:

>2/ new will return you a pointer, so your App variable should be a sf::RenderWindow* in this case
Changed to this

Your examples thus far only deal with one main program. I need to reuse the "RenderWindow App" for other game states. How would I go about doing that if not using global variable?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Place RenderWindow as Global
« Reply #3 on: February 19, 2008, 09:50:15 am »
Quote
Changed to this

Did you read 3/ ? ;)

I was suggesting this :
Code: [Select]
// In globals
sf::RenderWindow App;

// In main
App.Create(sf::VideoMode(640, 480, 32), "SFML Window");


Quote
Your examples thus far only deal with one main program. I need to reuse the "RenderWindow App" for other game states. How would I go about doing that if not using global variable?

First create a good skeleton / framework as a base to build your application on. An example (and what I always use) is an Application class, owning the window and all the renderable objects ; then this class can pass the events and the window to these objects when needed.
Laurent Gomila - SFML developer

armage

  • Newbie
  • *
  • Posts: 10
    • View Profile
Place RenderWindow as Global
« Reply #4 on: February 19, 2008, 01:06:53 pm »
I have been struggling with the slowness of your website. Sometimes cant even log in or read the forum.

I just tried your code suggestion of "App.Create" and encountered a possible bug.

Code: [Select]

    bool Running = true;
    while (Running)
    {

if(update()) {
Running = false;
}
if(Running)
{
render();
App.Display();
Helper::System_Log("Running");
}
if(!Running)
{
Helper::System_Log("Not Running");
}

    }
return EXIT_SUCCESS;


Once I exit the while loop, I encountered a Application Error
The instruction at .....referenced momery at ..... The memory could not be read.

Think there could be quick fix to this?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Place RenderWindow as Global
« Reply #5 on: February 19, 2008, 03:56:46 pm »
Quote
I have been struggling with the slowness of your website. Sometimes cant even log in or read the forum.

Not my fault... Say that to the sourceforge.net staff.

Quote
I just tried your code suggestion of "App.Create" and encountered a possible bug.

Before searching a possible bug in SFML, maybe you should show us more of your code.
Laurent Gomila - SFML developer

armage

  • Newbie
  • *
  • Posts: 10
    • View Profile
Place RenderWindow as Global
« Reply #6 on: February 19, 2008, 05:41:55 pm »
Sourceforge getting so slow to work with past week.

If ESC will get that error, if close the window by clicking on the cross seems ok.

Here is the code.

How do I make the window go full screen?

Code: [Select]

#include <fstream>
#include <SFML/Graphics.hpp>

sf::RenderWindow App;

bool render()
{
return false;

}
bool update()
{

        sf::Event Event;
        if (App.GetEvent(Event))
{
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
{
return true;
}
            // Escape key : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
{
return true;
}

            // Resize event : adjust viewport
            if (Event.Type == sf::Event::Resized)
                glViewport(0, 0, Event.Size.Width, Event.Size.Height);
        }


   return false;
 
}


int main()
{
    // Create the main window
App.Create(sf::VideoMode(1280, 768, 32), "SFML Window");
 
    // Create a clock for measuring the time elapsed
    sf::Clock Clock;

    // Set the color and depth clear values
    glClearDepth(1.f);
    glClearColor(0.f, 0.f, 0.f, 0.f);

    // Enable Z-buffer read and write
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);

    // Setup a perspective projection
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.f, 1.f, 1.f, 500.f);


    bool Running = true;
    while (Running)
    {

if(update()) {
Running = false;
}
if(Running)
{
render();
App.Display();

}
    }

return EXIT_SUCCESS;
 
}

zarka

  • Jr. Member
  • **
  • Posts: 81
    • View Profile
Place RenderWindow as Global
« Reply #7 on: February 19, 2008, 10:09:23 pm »
if you are using SFMLs graphics library their really is no need to do OpenGL calls yourself .. unless you want to do 3d but then you should skip the graphics package and build around the window package...

Quote from: "armage"
How do I make the window go full screen?

that is quite easy to find in the tutorials / documentation..
ther are some quite good tutorials here: http://sfml.sourceforge.net/tutorials/

also it depends on which version of SFML your are using .. in 1.2 i believe you send sf::Style::Fullscreen to sf::RenderWindow::Create
//Zzzarka

 

anything