1616
1717#include " common/arguments.h"
1818
19+ #include < filament/Camera.h>
1920#include < filament/IndexBuffer.h>
2021#include < filament/Material.h>
2122#include < filament/RenderableManager.h>
23+ #include < filament/Renderer.h>
2224#include < filament/Scene.h>
2325#include < filament/VertexBuffer.h>
2426#include < filament/View.h>
@@ -43,6 +45,16 @@ struct App {
4345static constexpr filament::math::float2 POSITIONS[] { {.5 , 0 }, {-.5 , .5 }, {-.5 , -.5 } };
4446static constexpr uint32_t COLORS[] { 0xffff0000u , 0xff00ff00u , 0xff0000ffu };
4547static constexpr uint16_t TRIANGLE_INDICES[] { 0 , 1 , 2 };
48+ static constexpr float ZOOM = 1 .5f ;
49+
50+ static void setCameraProjection (App* app, View* view) {
51+ const uint32_t w = view->getViewport ().width ;
52+ const uint32_t h = view->getViewport ().height ;
53+ const float aspect = (float ) w / h;
54+ app->cam ->setProjection (Camera::Projection::ORTHO,
55+ -aspect * ZOOM, aspect * ZOOM,
56+ -ZOOM, ZOOM, 0 , 1 );
57+ }
4658
4759int main (int argc, char ** argv) {
4860 Config config;
@@ -56,7 +68,6 @@ int main(int argc, char** argv) {
5668
5769 App app;
5870 auto setup = [&app, &vbo](Engine* engine, View* view, Scene* scene) {
59-
6071 // Populate vertex buffer.
6172 app.vb = VertexBuffer::Builder ().vertexCount (3 ).bufferCount (1 )
6273 .attribute (VertexAttribute::POSITION, 0 , VertexBuffer::AttributeType::FLOAT2, 0 , 8 )
@@ -84,6 +95,7 @@ int main(int argc, char** argv) {
8495 // Replace the FilamentApp camera with identity.
8596 app.camera = utils::EntityManager::get ().create ();
8697 view->setCamera (app.cam = engine->createCamera (app.camera ));
98+ setCameraProjection (&app, view);
8799 };
88100
89101 auto cleanup = [&app](Engine* engine, View*, Scene*) {
@@ -95,7 +107,16 @@ int main(int argc, char** argv) {
95107 utils::EntityManager::get ().destroy (app.camera );
96108 };
97109
98- FilamentApp::get ().run (config, setup, cleanup);
110+ FilamentApp::get ().resize ([&app](Engine* engine, View* view) {
111+ setCameraProjection (&app, view);
112+ });
113+
114+ FilamentApp::get ().run (config, setup, cleanup, FilamentApp::ImGuiCallback (),
115+ [](Engine*, View*, Scene*, Renderer* renderer) {
116+ Renderer::ClearOptions options;
117+ options.clear = true ;
118+ renderer->setClearOptions (options);
119+ });
99120
100121 return 0 ;
101122}
0 commit comments