-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aeb47ac
commit 66616a9
Showing
20 changed files
with
1,204 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule jGL
updated
25 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
cmake_minimum_required(VERSION 3.22) | ||
project(macos-lib-test) | ||
|
||
set(OUTPUT_NAME user) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_BUILD_TYPE Release) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-trapping-math -fno-rounding-math -fno-signaling-nans -fno-signed-zeros") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -O3 -Wall") | ||
|
||
set(SRC | ||
"main.cpp" | ||
) | ||
|
||
include_directories(include) | ||
include_directories(.) | ||
|
||
find_package(ZLIB REQUIRED) | ||
find_package(PNG REQUIRED) | ||
find_package(Vulkan REQUIRED) | ||
find_package(OpenGL REQUIRED) | ||
find_package(X11 REQUIRED) | ||
|
||
add_executable(${OUTPUT_NAME} ${SRC}) | ||
|
||
target_link_libraries( | ||
${OUTPUT_NAME} | ||
${CMAKE_SOURCE_DIR}/libjGL.a | ||
${X11_LIBRARIES} | ||
${OPENGL_LIBRARIES} | ||
${Vulkan_LIBRARIES} | ||
${ZLIB_LIBRARIES} | ||
${PNG_LIBRARIES} | ||
${CMAKE_SOURCE_DIR}/libHop.a | ||
) | ||
target_include_directories( | ||
${OUTPUT_NAME} | ||
PUBLIC | ||
${Vulkan_INCLUDE_DIR} | ||
) | ||
|
||
# https://stackoverflow.com/questions/18391487/compiling-with-glfw3-linker-errors-undefined-reference | ||
target_link_libraries(${OUTPUT_NAME} "-framework Cocoa -framework IOKit -framework CoreVideo") | ||
|
||
target_compile_definitions(${OUTPUT_NAME} PUBLIC GLSL_VERSION="330") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#include "main.h" | ||
|
||
int main(int argv, char ** argc) | ||
{ | ||
|
||
jGL::DesktopDisplay::Config conf; | ||
|
||
conf.VULKAN = false; | ||
conf.COCOA_RETINA = false; | ||
|
||
jGL::DesktopDisplay display(glm::ivec2(resX, resY), "Shape", conf); | ||
|
||
glewInit(); | ||
|
||
jGLInstance = std::move(std::make_unique<jGL::GL::OpenGLInstance>(display.getRes())); | ||
|
||
jGL::OrthoCam camera(resX, resY, glm::vec2(0.0,0.0)); | ||
|
||
camera.setPosition(0.0f, 0.0f); | ||
|
||
jLog::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))); | ||
jGLInstance->setMSAA(1); | ||
|
||
std::shared_ptr<jGL::ShapeRenderer> circles = jGLInstance->createShapeRenderer | ||
( | ||
32 | ||
); | ||
|
||
std::vector<std::shared_ptr<jGL::Shape>> shapes; | ||
|
||
RNG rng; | ||
|
||
for (unsigned i = 0; i < 64; i++) | ||
{ | ||
shapes.push_back | ||
( | ||
std::make_shared<jGL::Shape> | ||
( | ||
jGL::Transform(rng.nextFloat(), rng.nextFloat(), 0.0, 0.1f), | ||
glm::vec4(rng.nextFloat(), rng.nextFloat(), rng.nextFloat(), 1.0) | ||
) | ||
); | ||
|
||
circles->add(shapes[i], std::to_string(i)); | ||
} | ||
|
||
circles->setProjection(camera.getVP()); | ||
|
||
std::shared_ptr<jGL::Shader> shader = std::make_shared<jGL::GL::glShader>(vertexShader, fragmentShader); | ||
|
||
shader->use(); | ||
|
||
double delta = 0.0; | ||
double dt = 1.0/600.0; | ||
|
||
while (display.isOpen()) | ||
{ | ||
tic = high_resolution_clock::now(); | ||
|
||
jGLInstance->beginFrame(); | ||
|
||
jGLInstance->clear(); | ||
|
||
for (unsigned i = 0; i <shapes.size(); i++) | ||
{ | ||
auto tr = circles->getTransform(std::to_string(i)); | ||
circles->getShape(std::to_string(i))->update | ||
( | ||
jGL::Transform(tr.x+dt*(rng.nextFloat()-0.5), tr.y+dt*(rng.nextFloat()-0.5), tr.theta, tr.scale) | ||
); | ||
} | ||
|
||
circles->draw(shader); | ||
|
||
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"; | ||
} | ||
} | ||
|
||
jGLInstance->endFrame(); | ||
|
||
display.loop(); | ||
|
||
tock = high_resolution_clock::now(); | ||
|
||
deltas[frameId] = duration_cast<duration<double>>(tock-tic).count(); | ||
frameId = (frameId+1) % 60; | ||
|
||
} | ||
|
||
jGLInstance->finish(); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.