/*---------------------------------------------------------------------------* Project: Horizon File: gx_Draw2d.cpp Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 47228 $ *---------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #include #include "demo.h" namespace { demo::RenderSystemDrawing s_RenderSystem; nn::fnd::ExpHeap s_AppHeap; uptr s_HeapForGx; const u32 s_GxHeapSize = 0x800000; } void Initialize(void); void Finalize(void); bool DrawFrame(void); void DrawDisplay0(void); void DrawDisplay1(void); void Initialize(void) { s_AppHeap.Initialize(nn::os::GetDeviceMemoryAddress(), nn::os::GetDeviceMemorySize() ); s_HeapForGx = reinterpret_cast(s_AppHeap.Allocate(s_GxHeapSize)); s_RenderSystem.Initialize(s_HeapForGx, s_GxHeapSize); } void Finalize(void) { s_RenderSystem.Finalize(); s_AppHeap.Free(reinterpret_cast(s_HeapForGx)); s_AppHeap.Finalize(); } bool DrawFrame(void) { DrawDisplay0(); DrawDisplay1(); s_RenderSystem.WaitVsync(NN_GX_DISPLAY_BOTH); return true; } void DrawDisplay0(void) { s_RenderSystem.SetClearColor(NN_GX_DISPLAY0, 0.1f, 1.0f, 0.1f, 1.0f); s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY0); s_RenderSystem.Clear(); s_RenderSystem.SetColor(0.1f, 0.1f, 1.0f); s_RenderSystem.SetFontSize(8.0f); s_RenderSystem.DrawText(0.0f, 0.0f, "LeftTop 0123456789 %d", 123); s_RenderSystem.SetColor(1.0f, 0.1f, 0.1f); s_RenderSystem.SetFontSize(8.0f); s_RenderSystem.DrawText(400.0f - 8.0f * 11, 240.0f - 8.0f, "RightBottom"); s_RenderSystem.SetColor(1.0f, 0.1f, 1.0f, 1.0f); s_RenderSystem.FillTriangle(220.0f, 20.0f, 200.0f, 50.0f, 250.0f, 50.0f); s_RenderSystem.SetColor(0.7f, 0.1f, 0.1f, 1.0f); s_RenderSystem.FillRectangle(50.0f, 50.0f, 100.0f, 100.0f); s_RenderSystem.SetColor(0.0f, 1.0f, 1.0f, 1.0f); s_RenderSystem.FillSquare(300.0f, 80.0f, 300.0f - 60.0f, 80.0f + 20.0f, 300.0f, 80.0f + 40.0f, 300.0f + 60.0f, 80.0f + 20.0f); s_RenderSystem.SetColor(0.1f, 0.1f, 0.7f); s_RenderSystem.SetLineWidth(3.0f); s_RenderSystem.DrawLine(250.0f, 150.0f, 350.0f, 200.0f); s_RenderSystem.SetColor(1.0f, 1.0f, 0.0f); for (u32 i = 0; i < 5; i++) { f32 value = static_cast(i); s_RenderSystem.SetPointSize( 2.0f * ( value + 1.0f ) ); s_RenderSystem.DrawPoint(200.0f + 10.0f * value, 150.0f + 10.0f * value); } s_RenderSystem.SwapBuffers(); } void DrawDisplay1(void) { s_RenderSystem.SetClearColor(NN_GX_DISPLAY1, 0.1f, 0.1f, 1.0f, 1.0f); s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY1); s_RenderSystem.Clear(); s_RenderSystem.SetColor(1.0f, 0.1f, 0.1f); s_RenderSystem.SetFontSize(8.0f); s_RenderSystem.DrawText(0.0f, 0.0f, "LeftTop 0123456789 %f", 123.0f); s_RenderSystem.SetColor(1.0f, 1.0f, 1.0f); s_RenderSystem.SetFontSize(8.0f); s_RenderSystem.DrawText(320.0f - 8.0f * 11, 240.0f - 8.0f, "RightBottom"); s_RenderSystem.SwapBuffers(); } void nnMain( void ) { // Call only nn::applet::Enable to also allow execution from the HOME Menu // HOME Menu transitions, POWER Button presses, and sleep are all unsupported nn::applet::Enable(); Initialize(); bool flag = true; while ( flag ) { flag = DrawFrame(); } Finalize(); }