From 065ab468229f0f04da65d617057a6ea567b44b4c Mon Sep 17 00:00:00 2001 From: bkaradzic Date: Sat, 18 May 2013 09:43:57 -0700 Subject: [PATCH] Cleanup. --- README.md | 3 +++ examples/12-lod/fs_tree.sc | 4 ++-- examples/12-lod/lod.cpp | 35 ++++++++++++++++++++++++----------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 03468603..e39eedef 100644 --- a/README.md +++ b/README.md @@ -339,6 +339,9 @@ http://fontfabric.com/signika-font/ Visitor Font http://www.dafont.com/visitor.font +Tree Pack 1 +http://www.turbosquid.com/3d-models/free-obj-mode-tree-pack/506851 + Contributors ------------ diff --git a/examples/12-lod/fs_tree.sc b/examples/12-lod/fs_tree.sc index 12acc302..b431da9a 100644 --- a/examples/12-lod/fs_tree.sc +++ b/examples/12-lod/fs_tree.sc @@ -22,7 +22,7 @@ vec2 blinn(vec3 _lightDir, vec3 _normal, vec3 _viewDir) void main() { vec2 viewport = (u_viewRect.zw - u_viewRect.xy) * vec2(1.0/8.0, 1.0/4.0); - vec2 stippleUV = viewport*(v_pos.xy*0.5 + 0.5); + vec2 stippleUV = viewport*(v_pos.xy*0.5 + 0.5); if ((u_stipple.x - texture2D(u_texStipple,stippleUV).r)*u_stipple.y > u_stipple.z) discard; @@ -31,7 +31,7 @@ void main() vec3 view = normalize(v_view); vec2 bln = blinn(lightDir, normal, view); float l = max(0.0, saturate(bln.y) ); - + vec4 color = toLinear(abs(texture2D(u_texColor, v_texcoord0))*l); gl_FragColor = toGamma(color); } diff --git a/examples/12-lod/lod.cpp b/examples/12-lod/lod.cpp index 2ab187b6..76dc3ecf 100644 --- a/examples/12-lod/lod.cpp +++ b/examples/12-lod/lod.cpp @@ -365,12 +365,13 @@ int _main_(int /*_argc*/, char** /*_argv*/) const bgfx::Memory* stipple = bgfx::alloc(8*4); memset(stipple->data, 0, stipple->size); - for (int i=0; i<32; i++) - stipple->data[knightTour[i].m_y * 8 + knightTour[i].m_x] = i*4; + for (uint32_t ii = 0; ii < 32; ++ii) + { + stipple->data[knightTour[ii].m_y * 8 + knightTour[ii].m_x] = ii*4; + } textureStipple = bgfx::createTexture2D(8, 4, 1, bgfx::TextureFormat::L8, BGFX_TEXTURE_MAG_POINT|BGFX_TEXTURE_MIN_POINT, stipple); - // tree assets from: http://www.turbosquid.com/3d-models/free-obj-mode-tree-pack/506851 Mesh mesh_top[3]; mesh_top[0].load("meshes/tree1b_lod0_1.bin"); mesh_top[1].load("meshes/tree1b_lod1_1.bin"); @@ -417,8 +418,10 @@ int _main_(int /*_argc*/, char** /*_argv*/) imguiBeginScrollArea("Toggle transitions", width - width / 5 - 10, 10, width / 5, height / 7, &scrollArea); imguiSeparatorLine(); - if (imguiButton(transitions ? "ON" : "OFF")) + if (imguiButton(transitions ? "ON" : "OFF") ) + { transitions = !transitions; + } static float distance = 2.0f; imguiSlider("Distance", &distance, 2.0f, 6.0f, .01f); @@ -442,7 +445,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) // Use debug font to print information about this example. bgfx::dbgTextClear(); - bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/10-lod"); + bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/12-lod"); bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Mesh LOD transitions."); bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs); bgfx::dbgTextPrintf(0, 4, transitions ? 0x2f : 0x1f, transitions ? "Transitions on" : "Transitions off"); @@ -484,7 +487,8 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::setUniform(u_stipple, stipple, 1); mesh_top[mainLOD].submit(program, mtx, true); - if (transitions && (transitionFrame != 0)) + if (transitions + && (transitionFrame != 0) ) { bgfx::setTexture(0, u_texColor, textureBark); bgfx::setTexture(1, u_texStipple, textureStipple); @@ -498,19 +502,28 @@ int _main_(int /*_argc*/, char** /*_argv*/) } int lod = 0; - if (eye[2]<-2.5f) + if (eye[2] < -2.5f) + { lod = 1; - if (eye[2]<-5.0f) + } + + if (eye[2] < -5.0f) + { lod = 2; + } if (targetLOD!=lod) { if (targetLOD==currLOD) + { targetLOD = lod; + } } if (currLOD!=targetLOD) + { transitionFrame++; + } if (transitionFrame>32) { @@ -523,10 +536,10 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::frame(); } - for (int i=0; i<3; i++) + for (uint32_t ii = 0; ii < 3; ++ii) { - mesh_top[i].unload(); - mesh_trunk[i].unload(); + mesh_top[ii].unload(); + mesh_trunk[ii].unload(); } // Cleanup.