Nebula3 Basic Elements

Source: Internet
Author: User

After reading it for a long time, I can draw things through N3. I feel that its architecture is the ^_^ specially designed for DX. although it is also possible to write the GL middle layer (because the N3 API is in the middle of the inheritance tree, rather than the bottom layer), many habits are dx. it may be easier to get started with APIs.

 

All command line programs are derived from consoleapplication, so the graphics program derives from renderapplication ^_^.

First, let's take a look at the members of the renderapplication:

PTR <core: coreserver> coreserver; The preceding command line program has been used, the most basic core service
PTR <IO: ioserver> ioserver; Input/output service. Do not forget to copy the resources required by the program (such as shader) to the correct directory. The default directory is the directory where the EXE file is located.
PTR <interface: iointerface> iointerface; Interface for asynchronous (multi-thread) Resource loading (N3 Nb is on multiple threads)
PTR <CoreGraphics: renderdevice> renderdevice; The core graphics system can be viewed as an idirect3ddevice9 encapsulation ^ _ ^, with functions similar
PTR <CoreGraphics: displaydevice> displaydevice; Display device, which encapsulates window creation, message processing, and display adapter.
PTR <CoreGraphics: transformdevice> transformdevice; Manage global matrix transformations and their combinations
PTR <CoreGraphics: shaderserver> shaderserver; Shader manager. N3 uses the DX effect framework, and common shader is included in the resource file.
PTR <CoreGraphics: shaperenderer> shaperenderer; The Renderer of the geometric image, which is generally used to assist the drawing in the debugging mode.
PTR <CoreGraphics: vertexlayoutserver> vertexlayoutserver; It can be viewed as a manager of idirect3dvertexdeclaration9 for creating vertex formats.
PTR <resources: sharedresourceserver> sharedresourceserver; Manager for shared resources
PTR <resources: ResourceManager> ResourceManager; It is equivalent to an intermediate layer between the client and resources. The main function is to provide resources for rendering when the minimum memory is used. if the resources are not loaded, a resource placeholder is provided. specific resource management policies are encapsulated in resourcemapper, such as loading priority and level of detail (SLS ).
PTR <models: modelserver> modelserver; Used to load and create shared Model Objects
PTR <graphics: graphicsserver> graphicsserver; Manages an abstract graphic world. one world contains one or more "stages" and one or more "views" connected to the stage )". (xoyojank: Is it Scenario Management ?)
PTR <lighting: lightserver> lightserver; Management scenario light source and real-time illumination processing (sm3.0, but a 98000gt host is installed @_@)
PTR <lighting: shadowserver> shadowserver; Shadow processing: simple Shadow Mapping is used for local light sources, and PSSM is used for global light (sm3.0 again)
PTR <input: inputserver> inputserver; Input device. It seems that directinput is used by the mouse, while Windows message processing is directly used by the keyboard.
PTR <frame: FrameServer> FrameServer; Image space-based processing is mostly used for posteffect.
PTR <scripting: scriptserver> scriptserver; Script System
PTR HTTP debugging information of N3 (this is Nb, but is it practical ?)
PTR <anim: animationserver> animationserver; In the bone animation system, the latest code on SVN seems to have been rewritten, abandoning the N2 encapsulation.

 

I just drew a line ........

// Testwindow. CPP: defines the entry point for the console application. <br/> // </P> <p> # include "stdneb. H "<br/> # include" apprender/viewerapplication. H "<br/> # include" CoreGraphics/memoryvertexbufferloader. H "<br/> # include" Resources/resourceloader. H "<br/> # include" Timing/time. H "</P> <p> using namespace app; <br/> using namespace util; <br/> using namespace math; <br/> using namespace CoreGraphics; <br/> using namespace resources; </P> <p> implementnebulaapplication () </P> <p> class linerenderapp: public renderapplication <br/>{< br/> PTR <vertexbuffer> vertexbuffer; <br/> PTR <shaderinstance> shaderinstance; </P> <p> public: <br/> bool open () <br/> {<br/> If (renderapplication: open ()) <br/>{< br/> // vertex <br/> array <vertexcomponent> vertexcomponents; <br/> vertexcomponents. append (vertexcomponent: Position, 0, vertexcomponent: float3); <br/> float vertex [2] [3] = {-1.0f,-1.0f, 0.0f },{ 1.0f, 1.0f, 0.0f }}; <br/> vertexbuffer = vertexbuffer: Create (); <br/> PTR <memoryvertexbufferloader> vbloader = memoryvertexbufferloader :: create (); <br/> vbloader-> setup (vertexcomponents, 2, vertex, 2*3 * sizeof (float); <br/> vertexbuffer-> setloader (vbloader. upcast <resourceloader> (); <br/> vertexbuffer-> setasyncenabled (false); <br/> vertexbuffer-> load (); <br/> vertexbuffer-> setloader (null ); <br/> // shader <br/> This-> shaderinstance = This-> shaderserver-> createshaderinstance (resourceid ("SHD: Shape ")); <br/> PTR <shadervariable> color = This-> shaderinstance-> getvariablebysemantic (shadervariable: semantic ("matdiffuse ")); <br/> color-> setvector (float4 (1.0f, 1.0f, 1.0f, 1.0f )); <br/> PTR <shadervariable> MVP = This-> shaderinstance-> getvariablebysemantic (shadervariable: semantic ("modelviewprojection"); <br/> MVP-> setmatrix (matrix44:: Identity (); <br/>}< br/> return true; <br/>}</P> <p> void onrenderframe () <br/>{< br/> This-> displaydevice-> processwindowmessages (); <br/> This-> renderdevice-> beginframe (); <br/> This-> renderdevice-> beginpass (this-> renderdevice-> getdefaultrendertarget (), this-> shaderinstance); <br/> primitivegroup primgroup; <br/> primgroup. setbasevertex (0); <br/> primgroup. setnumvertices (2); <br/> primgroup. setprimitivetopology (primitivetopology: linelist); </P> <p> This-> renderdevice-> setvertexbuffer (this-> vertexbuffer ); <br/> This-> renderdevice-> setprimitivegroup (primgroup); <br/> This-> renderdevice-> draw (); <br/> This-> renderdevice-> endpass (); <br/> This-> renderdevice-> EndFrame (); <br/> This-> renderdevice-> present (); <br/>}< br/> }; </P> <p> void <br/> nebulamain (const extends lineargs & ARGs) <br/>{< br/> linerenderapp; <br/> app. setappname ("test Renderer"); <br/> app. setcmdlineargs (ARGs); <br/> If (App. open () <br/>{< br/> app. run (); <br/> app. close (); <br/>}< br/> app. exit (); <br/>}< br/>

 

Of course, you only need to modify primitivetopology to draw other elements.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.