3D Render First Files

This commit is contained in:
Asrın Doğan 2020-01-08 14:45:47 +03:00
parent d45db29f4e
commit 84eb390803
6 changed files with 178 additions and 1 deletions

View File

@ -48,6 +48,9 @@
"xstddef": "cpp",
"xtr1common": "cpp",
"xutility": "cpp",
"iostream": "cpp"
"iostream": "cpp",
"list": "cpp",
"unordered_set": "cpp",
"xhash": "cpp"
}
}

12
3DTest/SynGame.hpp Normal file
View File

@ -0,0 +1,12 @@
#ifndef SynClasses
#define SynClasses
#define DegToRad 0.0174533
#include <SFML/Graphics.hpp>
#include <sstream>
#include <vector>
#include <cmath>
#include "Timer.hpp"
#include "Window.hpp"
#endif

47
3DTest/Timer.hpp Normal file
View File

@ -0,0 +1,47 @@
#include "SynGame.hpp"
class Timer
{
private:
sf::Clock clock;
float deltaTime;
float timePassed;
public:
Timer();
void ResetTimer();
void UpdateTime();
float GetDeltaTime();
float GetTimePassed();
};
Timer::Timer()
{
clock.restart();
timePassed = 0.0;
deltaTime = 0.0;
}
void Timer::ResetTimer()
{
clock.restart();
timePassed = 0.0;
deltaTime = 0.0;
}
void Timer::UpdateTime()
{
float newTimePassed = clock.getElapsedTime().asSeconds();
deltaTime = newTimePassed - timePassed;
timePassed = newTimePassed;
}
float Timer::GetDeltaTime()
{
return deltaTime;
}
float Timer::GetTimePassed()
{
return timePassed;
}

102
3DTest/Window.hpp Normal file
View File

@ -0,0 +1,102 @@
#include "SynGame.hpp"
class Window
{
private:
sf::RenderWindow window;
sf::Event event;
sf::Vector2u size;
std::string title;
sf::Uint32 style;
Timer timer;
bool isFocused;
public:
Window(unsigned int = 960, unsigned int = 540, std::string = "Window", sf::Uint32 = 7U);
void CreateWindow();
void CloseWindow();
void Update();
void SetFrameRate(int = 0);
void SetTitle(std::string);
void SetSize(unsigned int, unsigned int);
bool IsOpen();
};
void Window::Update()
{
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
CloseWindow();
else if (event.type == sf::Event::LostFocus)
isFocused = false;
else if (event.type == sf::Event::GainedFocus)
isFocused = true;
}
if(!isFocused)
return;
timer.UpdateTime();
}
Window::Window(unsigned int width, unsigned int height, std::string title, sf::Uint32 style)
{
this -> size.x = width;
this -> size.y = height;
this -> title = title;
this -> style = style;
isFocused = true;
SetFrameRate();
CreateWindow();
}
void Window::CreateWindow()
{
if(window.isOpen())
return;
sf::VideoMode videoMode(size.x, size.y);
window.create(videoMode, title, style);
timer.ResetTimer();
}
void Window::CloseWindow()
{
if(!window.isOpen())
return;
window.close();
}
void Window::SetFrameRate(int rate)
{
if(rate == 0)
{
window.setVerticalSyncEnabled(true);
return;
}
if(rate < 0)
window.setFramerateLimit(10000);
else
window.setFramerateLimit(rate);
window.setVerticalSyncEnabled(false);
}
void Window::SetTitle(std::string title)
{
this -> title = title;
window.setTitle(title);
}
void Window::SetSize(unsigned int width, unsigned int height)
{
size = sf::Vector2u(width, height);
window.setSize(size);
}
bool Window::IsOpen()
{
return window.isOpen();
}

11
3DTest/main.cpp Normal file
View File

@ -0,0 +1,11 @@
#include "SynGame.hpp"
int main()
{
Window window;
while (window.IsOpen())
window.Update();
return 0;
}

2
3DTest/makefile Normal file
View File

@ -0,0 +1,2 @@
main.exe : *.cpp
g++ -o main.exe *.cpp ../SFML/*.a