Random grid

This commit is contained in:
2024-09-19 13:36:49 -04:00
parent 40d51b3d07
commit 08ce40d57c
2 changed files with 106 additions and 10 deletions

View File

@@ -1,8 +1,13 @@
cmake_minimum_required(VERSION 3.18..3.29)
file(COPY "assets" DESTINATION "${PROJECT_BINARY_DIR}/ClientApp")
add_executable(CaveClientApp main.cpp)
target_include_directories(CaveClientApp PUBLIC ${ReWindow_SOURCE_DIR}/include ${J3ML_SOURCE_DIR}/include)
target_include_directories(CaveClientApp PUBLIC
${ReWindow_SOURCE_DIR}/include
${J3ML_SOURCE_DIR}/include
${JGL_SOURCE_DIR}/include)
target_link_libraries(CaveClientApp PUBLIC ReWindowLibrary J3ML)
target_link_libraries(CaveClientApp PUBLIC ReWindowLibrary J3ML JGL)

View File

@@ -1,7 +1,23 @@
#include <iostream>
#include <rewindow/types/window.h>
#include <JGL/JGL.h>
class TestWorld
{
public:
void render()
{
}
protected:
private:
};
int test_tiles[1024][1024];
JGL::Font Jupiteroid;
class CaveGameWindow : public ReWindow::RWindow
{
@@ -9,22 +25,80 @@ public:
CaveGameWindow() : ReWindow::RWindow() {}
CaveGameWindow(const std::string& title, int width, int height) : ReWindow::RWindow(title, width, height) {}
void initGL()
{
gladLoadGL();
JGL::InitTextEngine();
JGL::Update(getSize());
Jupiteroid = JGL::Font("assets/Jupiteroid.ttf");
glClearColor(0.f, 0.f, 0.f, 0.f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glDepthMask(GL_TRUE);
}
void display()
{
JGL::Update(getSize());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
JGL::J2D::Begin();
for (int tx = 0; tx < 1024; tx++)
{
for (int ty = 0; ty < 1024; ty++)
{
Color4 color = {0,0,0,0};
int tile_id = test_tiles[tx][ty];
if (tile_id == 0)
color = Colors::Red;
if (tile_id == 1)
color = Colors::Gray;
if (tile_id == 2)
color = Colors::Browns::Bisque;
JGL::J2D::FillRect(color, {static_cast<float>(tx), static_cast<float>(ty)}, {1, 1});
}
}
JGL::J2D::End();
// Draw Watermark
JGL::J2D::Begin();
JGL::J2D::DrawString(Colors::White, "Re-CaveGame - Redacted Software", 0,0, 1, 12, Jupiteroid);
JGL::J2D::End();
}
void OnRefresh(float elapsed) override
{
display();
int glError = glGetError();
if (glError != GL_NO_ERROR)
std::cout << glError << std::endl;
glSwapBuffers();
}
void OnMouseButtonDown(const ReWindow::WindowEvents::MouseButtonDownEvent &) override
void OnMouseButtonDown(const ReWindow::WindowEvents::MouseButtonDownEvent &ev) override
{
RWindow::OnMouseButtonDown(ev);
}
void OnMouseButtonUp(const ReWindow::WindowEvents::MouseButtonUpEvent &) override
void OnMouseButtonUp(const ReWindow::WindowEvents::MouseButtonUpEvent &ev) override
{
RWindow::OnMouseButtonUp(ev);
}
bool OnResizeRequest(const ReWindow::WindowEvents::WindowResizeRequestEvent &e) override
bool OnResizeRequest(const ReWindow::WindowEvents::WindowResizeRequestEvent &ev) override
{
return true;
}
@@ -32,11 +106,28 @@ public:
int main()
{
srand(0);
for (int tx = 0; tx < 1024; tx++)
{
for (int ty = 0; ty < 1024; ty++)
{
test_tiles[tx][ty] = rand() % 5;
}
}
auto* window = new CaveGameWindow("Re-CaveGame", 1280, 720);
window->setRenderer(RenderingAPI::OPENGL);
window->Open();
window->initGL();
window->setResizable(true);
window->setVsyncEnabled(true);
while (window->isAlive()) {
window->pollEvents();
window->refresh();
}
return 0;
}