Hi all. I'm new to the SFML and the forum and I had some issues today. First of all, I want to use classes with SFML and I made a framework for this. File Structure is like this:
>main.cpp
>Framework>Window>Window.h and Window.cpp
Framework and main.cpp are at the same level. Window class lies beneath the framework folder.
main.cpp:
#include "Framework\Window\Window.h"
#include <iostream>
#include <SFML/Graphics.hpp>
int main()
{
Window window(640, 360, "Title", false);
while (window.IsOpen()) {
window.Clear();
window.Draw();
}
return 0;
}
Window.h
#ifndef WINDOW_H
#define WINDOW_H
#include <string>
#include <SFML/Graphics.hpp>
class Window {
public:
Window(int width, int height, std::string title, bool fullscreen);
bool IsOpen();
void Clear();
void Draw();
private:
sf::RenderWindow* window;
int windowWidth;
int windowHeight;
std::string windowTitle;
bool windowFullscreen;
};
#endif
Window.cpp
#include "Window.h"
Window::Window(int width, int height, std::string title, bool fullscreen) {
windowWidth = width;
windowHeight = height;
windowTitle = title;
windowFullscreen = fullscreen;
window = &sf::RenderWindow(sf::VideoMode(windowWidth, windowHeight), windowTitle, sf::Style::Close | sf::Style::Titlebar);
window->setFramerateLimit(60);
}
bool Window::IsOpen() {
return window->isOpen();
}
void Window::Clear() {
window->clear();
}
void Window::Draw() {
window->display();
}
What is the problem. Does SFML supports object oriented programming? By the way, clear function gives access violation error in the code.
Thanks.