Hello today I was trying to create class that can create and render multiple objects. Unfortunately when I run my program I'm getting only white square.
main.cpp
#include "SFML/Graphics.hpp"
#include "Icons.hpp"
using namespace sf;
int main() {
Icons icons;
Event event;
RenderWindow window(VideoMode(1280,720), "Test", Style::Close);
while (window.isOpen()) {
while (window.pollEvent(event)) {
switch (event.type) {
case Event::Closed: { window.close(); }
}
}
window.clear();
window.draw(icons);
window.display();
}
return EXIT_SUCCESS;
}
Icon.hpp
#pragma once
#include "SFML/Graphics.hpp"
#include <string>
class Icon{
public:
sf::Texture texture;
sf::Sprite sprite;
Icon(std::string path) {
texture.loadFromFile(path);
sprite.setTexture(texture);
}
};
Icons.hpp
#pragma once
#include "SFML/Graphics.hpp"
#include <vector>
#include "Icon.hpp"
class Icons : public sf::Drawable {
std::vector<Icon> icons;
public:
Icons() {
icons.push_back(Icon("test.png"));
}
private:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const {
for (const auto & icon : icons) {
target.draw(icon.sprite);
}
}
};
I'm out of ideas hope someone can help me. Btw I will appreciate any tips cuz I'm still learning how to program :-\