Skip to content

Commit

Permalink
adds textures
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerboa-app committed Oct 25, 2023
1 parent 0563e22 commit 189f6ae
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 5 deletions.
99 changes: 99 additions & 0 deletions examples/Sprite/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include <main.h>

int main(int argv, char ** argc)
{

jGL::Display display(resX, resY, "Sprite");

glewInit();

jGLInstance = std::move(std::make_unique<jGL::GL::OpenGLInstance>(display));

jGL::OrthoCam camera(resX, resY, glm::vec2(0.0,0.0));

camera.setPosition(0.0f, 0.0f);

glm::vec2 res = camera.getResolution();
glm::vec4 minWorld = camera.screenToWorld(0.0f, 0.0f);
glm::vec4 maxWorld = camera.screenToWorld(res.x, res.y);

Log log;

high_resolution_clock::time_point tic, tock;
double rdt = 0.0;

jGLInstance->setTextProjection(glm::ortho(0.0,double(resX),0.0,double(resY)));

std::shared_ptr<jGL::Texture> heart = jGLInstance->createTexture
(
"resource/texture/HEART.png",
jGL::Texture::Type::RGBA
);

std::shared_ptr<jGL::Texture> Pi = jGLInstance->createTexture
(
"resource/texture/Pi.png",
jGL::Texture::Type::RGBA
);

std::shared_ptr<jGL::Texture> random = jGLInstance->createTexture
(
"resource/texture/random.png",
jGL::Texture::Type::RGBA
);

double delta = 0.0;

while (display.isOpen())
{
tic = high_resolution_clock::now();

jGLInstance->clear();

delta = 0.0;
for (int n = 0; n < 60; n++)
{
delta += deltas[n];
}
delta /= 60.0;

std::stringstream debugText;

double mouseX, mouseY;
display.mousePosition(mouseX,mouseY);

debugText << "Delta: " << fixedLengthNumber(delta,6)
<< " ( FPS: " << fixedLengthNumber(1.0/delta,4)
<< ")\n"
<< "Render draw time: \n"
<< " " << fixedLengthNumber(rdt, 6) << "\n"
<< "Mouse (" << fixedLengthNumber(mouseX,4)
<< ","
<< fixedLengthNumber(mouseY,4)
<< ")\n";

jGLInstance->text(
debugText.str(),
glm::vec2(64.0f, resY-64.0f),
0.5f,
glm::vec4(0.0f,0.0f,0.0f,1.0f)
);

if (frameId == 30)
{
if (log.size() > 0)
{
std::cout << log << "\n";
}
}

display.loop();

tock = high_resolution_clock::now();

deltas[frameId] = duration_cast<duration<double>>(tock-tic).count();
frameId = (frameId+1) % 60;
}

return 0;
}
5 changes: 0 additions & 5 deletions examples/Sprite/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <jGL/Display/display.h>
#include <jGL/orthoCam.h>

#include <dynamics.h>
#include <log.h>
#include <Util/util.h>

Expand All @@ -18,10 +17,6 @@ using namespace std::chrono;
const int resX = 800;
const int resY = 1000;

const float SCALE_PX = 16.0f;

const size_t nParticles = 2;

uint8_t frameId = 0;
double deltas[60];

Expand Down

0 comments on commit 189f6ae

Please sign in to comment.