diff options
author | Mateja <mail@matejamaric.com> | 2021-02-19 17:28:33 +0100 |
---|---|---|
committer | Mateja <mail@matejamaric.com> | 2021-02-19 17:28:33 +0100 |
commit | 9e7016e23471b7ba67598b5558c7fc7c528f1f2a (patch) | |
tree | 693b9a7fe468e8df1f431b3b5c33971f1a996764 /src/main.cpp | |
parent | 3b89cf20f583a82a3cd5bdbe04c07630838af5c3 (diff) | |
download | erender-9e7016e23471b7ba67598b5558c7fc7c528f1f2a.tar.gz erender-9e7016e23471b7ba67598b5558c7fc7c528f1f2a.zip |
Moved texture loading to `Bitmap` class.
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 31 |
1 files changed, 5 insertions, 26 deletions
diff --git a/src/main.cpp b/src/main.cpp index ca4ff1b..1234964 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,4 @@ #include<SFML/Window.hpp>
-#include<SFML/Graphics.hpp>
#include"Render.h"
@@ -28,30 +27,12 @@ int main() Render render(width, height);
- Bitmap* modelTexture;
-
- bool textureLoaded = false;
-
- std::chrono::high_resolution_clock::time_point time1 = std::chrono::high_resolution_clock::now();
- sf::Image image;
- textureLoaded = image.loadFromFile("model/modelTexture.png");
- if (textureLoaded) {
- modelTexture = new Bitmap(image.getSize().x, image.getSize().y);
- const sf::Uint8* pp = image.getPixelsPtr();
- for (int i = 0; i < image.getSize().x * image.getSize().y * 4; i += 4) {
- modelTexture->pixels[i + 0] = (unsigned char)pp[i + 0];
- modelTexture->pixels[i + 1] = (unsigned char)pp[i + 1];
- modelTexture->pixels[i + 2] = (unsigned char)pp[i + 2];
- modelTexture->pixels[i + 3] = (unsigned char)pp[i + 3];
- }
- }
- std::chrono::high_resolution_clock::time_point time2 = std::chrono::high_resolution_clock::now();
- std::chrono::duration<double> modelTextureLoadingTime = std::chrono::duration_cast<std::chrono::duration<double>>(time2 - time1);
+ Bitmap modelTexture("model/modelTexture.png");
ObjModel model("model/model.obj");
- if (textureLoaded) {
- std::cout << "Texture loading time: " << modelTextureLoadingTime.count() << "\n";
+ if (modelTexture.isLoaded) {
+ std::cout << "Texture loading time: " << modelTexture.loadingTime.count() << "\n";
}
else {
std::cerr << "Couldn't load and/or find texture!\n";
@@ -66,7 +47,7 @@ int main() std::cerr << "Couldn't load and/or find model!\n";
}
- if (textureLoaded && model.isLoaded) {
+ if (modelTexture.isLoaded && model.isLoaded) {
while (window.isOpen())
{
while (window.pollEvent(event))
@@ -90,7 +71,7 @@ int main() render.fill(255, 255, 255);
render.resetZBuf();
- render.renderModel(projectedModel, *modelTexture);
+ render.renderModel(projectedModel, modelTexture);
texture.update((sf::Uint8*)render.pixels);
window.draw(sprite);
@@ -98,7 +79,5 @@ int main() }
}
- delete modelTexture;
-
return 0;
}
|