Okay. In this way, I tried to correct following:
TApp.h#pragma once
#include <SFML\Graphics.hpp>
class TApp
{
public:
TApp();
int DoExecute();
private: /*MAIN FUNCTION*/
void DoInputHandle();
void DoUpdate();
void DoRender();
private:
sf::RenderWindow m_Window;
sf::Texture m_texture;
sf::Sprite m_sprite;
};
DoRender.cpp#include "TApp.h"
#include <assert.h>
void TApp::DoRender()
{
bool m = m_texture.loadFromFile("D:/Project/CPP/Game_Engine/Debug/sprites/first.bmp");
assert(m == false);
m_sprite.setTexture(m_texture);
m_sprite.setPosition(100.0f, 100.0f);
m_Window.clear();
m_Window.draw(m_sprite);
m_Window.display();
}
Not working! I remembered a relation between
sf::Image -
sf::Texture -
sf::Sprite, and I thought that program is right now working, but not.
A few days ago I wrote following code:
main.cpp#include <SFML\Graphics.hpp>
#include <boost\lexical_cast.hpp>
#include <iostream>
#include <string>
class Game
{
public:
Game();
void run();
private:
void processEvent();
void update(sf::Time deltaTime);
void render();
private:
sf::RenderWindow mWindow;
};
int main()
{
Game game;
game.run();
return 0;
}
Game::Game()
: mWindow(sf::VideoMode::getDesktopMode(), "SFML Window", sf::Style::Fullscreen)
{
}
void Game::run()
{
sf::Clock clock;
sf::Time timeSinceLastUpdate = sf::Time::Zero;
const sf::Time TimePerFrame = sf::seconds(1.f / 60.f);
while (mWindow.isOpen())
{
processEvent();
timeSinceLastUpdate += clock.restart();
while (timeSinceLastUpdate > TimePerFrame)
{
timeSinceLastUpdate -= TimePerFrame;
processEvent();
update(TimePerFrame);
}
render();
}
}
void Game::processEvent()
{
sf::Event event;
while (mWindow.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
mWindow.close();
break;
default:
break;
}
}
}
void Game::update(sf::Time deltaTime)
{
}
void Game::render()
{
sf::Texture texture;
texture.loadFromFile("D:/Project/CPP/Game_Engine/Debug/sprites/first.bmp");
sf::Sprite sprite(texture);
sprite.setPosition(100.f, 100.f);
mWindow.clear();
mWindow.draw(sprite);
mWindow.display();
}
It's working. But why?? I confused.
I tried use also following:
#include "TApp.h"
#include <assert.h>
void TApp::DoRender()
{
sf::Texture texture;
bool m = texture.loadFromFile("D:/Project/CPP/Game_Engine/Debug/sprites/first.bmp");
assert(m == false);
sf::Sprite sprite(texture);
sprite.setPosition(100.0f, 100.0f);
m_Window.clear();
m_Window.draw(sprite);
m_Window.display();
}
Same error.