SFML community forums
General => General discussions => Topic started by: armage 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
#include <SFML/Graphics.hpp>
extern sf::RenderWindow App;
In Global.cpp:
#include "Global.h"
sf::RenderWindow App;
In Main.cpp:
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]
-
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
-
>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?
-
Changed to this
Did you read 3/ ? ;)
I was suggesting this :
// In globals
sf::RenderWindow App;
// In main
App.Create(sf::VideoMode(640, 480, 32), "SFML Window");
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.
-
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.
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?
-
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.
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.
-
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?
#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;
}
-
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...
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