I'm putting together a small game engine setup. I have the following code and I have some beginner questions about it.
1. For a start, is this a stable setup. Are there objects I would need to instantiate differently or destroy and etc. Question is mostly about the RenderWindow.
2. You will notice, that I used the .create method to create the window. I ran into a problem trying to use the constructor there.
I'm a little inexperienced with this, so my question is - Does it have anything to do with RenderWindow being NonCopyable?
The error messages I got were extreme at the least.
window = sf::RenderWindow(sf::VideoMode(m_iWidth, m_iHeight), m_czTitle, sf::Style::Titlebar | sf::Style::Close);
This is what I tried originally and I'm just making sure I understand how I fixed the problem. Now it works of course.
3. Other than that, any suggestions or improvements are welcome.
#include "engine.h"
int main()
{
CEngine myGame;
myGame.Init();
myGame.Start();
return 0;
}
#ifndef ENGINE_H
#define ENGINE_H
#include <SFML/Graphics.hpp>
class CEngine
{
private:
sf::RenderWindow window;
int m_iWidth; // Screen width
int m_iHeight; // Screen height
const char* m_czTitle;
protected:
void HandleInput();
void DoRender();
public:
CEngine();
~CEngine();
void Init();
void Start();
};
#endif
#include "engine.h"
CEngine::CEngine()
{
m_iWidth = 1280;
m_iHeight = 720;
m_czTitle = "My Game";
}
CEngine::~CEngine()
{
}
void CEngine::Init()
{
window.create(sf::VideoMode(m_iWidth, m_iHeight), m_czTitle, sf::Style::Titlebar | sf::Style::Close);
}
void CEngine::Start()
{
while(window.isOpen())
{
HandleInput();
DoRender();
}
}
void CEngine::HandleInput()
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
{
window.close();
}
}
}
void CEngine::DoRender()
{
window.clear(sf::Color::Blue);
window.display();
}