3d games download

Hello everyone, and welcome back to thistutorial series about how to create a 3D game in C++ from scratch. In this fifthvideo tutorial we’ll see how to render our first triangle so we will see how toplace its vertices and how we can properly set the various stages of thegraphics pipeline, stages that will allow the DirectX to perform the renderingof the 3d scene to a 2d screen. As always we will face three main parts:requirements, design and implementation of all the necessary things to rendera triangle. So let’s start with the requirements. We need a C++ IDE, VisualStudio is recommended. The target platform is Windows, we also need DirectX 11 SDK. Last but not least, a bit ofknowledge of C++ programming language is recommended. Now we can start the designpart. As first thing, let’s see what is a triangle. A triangle is simply a polygoncomposed by three vertices. Vertices are points placed in a space. But, do wereally know what is a vertex? As we said it is a point, and just for this fact, ithas a position in the space. But in most Graphics API, a vertex can be definedby more attributes. As we see from the image, a vertex can be customized addingany kind of attribute, like position color, texture coordinates and so on. Forthis fact, we can add more types of vertex: for example we can have a vertexwith only the position attribute, that we can call VertexPos; a vertexwith position and color attributes, that we can call VertexPosColor and so on.Well, but how can we use those vertices of a certain type to render our triangleon screen? By adding them to the vertex buffer. A vertex buffer is nothing morethan a memory buffer that contains a list of vertices. It can be of any size,but each vertex buffer can contain a list of only one type of vertices. Forexample, we can have a vertex buffer that contains only vertices of type VertexPos, but it can’t contains vertices of other type, like VertexPosColormentioned earlier. For that, we need to create another vertex buffer. Good, butnow we need a way to tell to our Graphics API of what attributes ourvertex type is composed. This can be accomplished by the input layout object.In DirectX, an input layout is an object in which we can add all the necessaryinformation to define the various attributes of our vertex type, so theirnames, the size in bytes, the displacement inside the vertex type structure and soon. At this point, we have all the necessary resources to draw our triangle, but weneed to know in what points of the space to place our vertices! Well, first of all,we need to know that most of the time we deal with vertices placed in a 3d space,but to allow the Graphics API to process them and show the polygons onthe screen, we need to transform them into screen space, through the vertex shader,but this is something that we will see in the next tutorials. For now, we will simply place the vertices of our triangle directly inthe screen space coordinates. Let’s see what is a screen space. The screen spaceis 2D space in which there are two axis, the x axis, along the width ofthe screen, and the y axis, along the

Default 3d games downloadtwo axis, the x axis, along the width ofthe screen, and the y axis, along the height of the screen. For each axis, therange of values goes from minus 1 to plus 1. In the x axis – 1 representsthe left side of screen, instead 1 the right side. In the y axis, -1represents the bottom side of screen, instead 1 the top side. With all thisinformation we can easily find out the positions in which to place the verticesof our triangle! There is nothing to do butcall the draw function to render the triangle. But… What happens after calling the drawfunction? It’s executed a process called graphics pipeline composed by somestages before to call the draw function we need to set some important data thatare useful for the correct execution of each stage the first stage is inputassembler for this stage we have to set vertex buffers include layouts so thatall the vertices can be collected and used for the programmable shaders stagewe have to set some shaders like vertex shader for the manipulation of verticesrasterization stage is the stage where vector information composed of shapes orprimitives are converted into a raster image composed of pixels for this stagewe have to set at least one area or viewport of a specific render targetwhich to render our rasterized image pizza shader stage is the stage in whichthe final pixel color is elaborated the last stage is output merger stage wherewe will indicate in which render target we want to output our final rasterizedimage and we will choose the back buffer of our wordsworth chain let’s start tocreate the class diagram we can start adding the vertex buffer class that willhave three methods the most important ones are load and release in load methodwe will pass an array with the three vertices of our triangle and we willcreate the vertex buffer and input layout then we will add other freemethods in the vise context to necessary for the passage of the data needed forthe graphics pipeline and one that be the draw function and then we willcreate the vertex buffer through our graphics engine adding the create vertexbuffer function very good finally we could start the implementation we can start creating a feature and theclass for the vertex buffer you as a first thing let’s implement theloot and release networks you a load method we have to create thevertex buffer from Direct X device so we have to get it from graphics engine since the device is a private member wehave to set vertex buffer a friend class of graphics engine class you now we can get the device and call thecreate buffer function

1 3d games downloadnow we can get the device and call thecreate buffer function we have to pass some parameters thefirst is a descriptor object in which we have to set some data relative to ourbuffer the first attribute to set is usage thatindicates whether our buffer is accessible by CPU and or GPU let’s setit to the fold that means that it can be both read and written by the GPU the second attribute is bite with thatindicates the size of bytes of our buffer here we need to decide in bytesof our vertex tag and the number of vertices of that type so let’s add someparameters and load method let’s add a pointer to the list of vertices the sizeof the vertex type and the number of vertices in that listlet’s add them even in the heater fire and at the end but whiff will be theproduct between the size of vertex and the number of vertices in the leastthe other attribute is white flag here we tell tutor attacks how to bind thisbuffer to the graphics pipeline and we will buy it as a vertex buffer then wehave two other attributes that are not so important in this moment and so weset them to zero let’s pass the descriptor to the function at this point we need to pass a subresource data object so let’s create it here we have to pass the pointer to thememory in which the list of vertices is located well now let’s add some attributes toour vertex buffer class the size vertex in bytes and size of least you after that we can pass the sub resourcedata to the function and finally get the output buffer you let’s do some error checking you very good we have created our vertexbuffer now we can create the input layout as we said this object has us todefine the attributes of our vertex type as the first thing we have a descriptorobject in which to add all the information about the attributes that wecompose our vertex type you since at the moment we don’t needspecial attributes we use only the position attribute with free floatvalues you then we have to get the number ofattributes and we can do it with array size at the end let’s pass the descriptor tocreate a good layout function the remaining necessary parameters are thebyte code of a shader and exercise in

3d games download remaining necessary parameters are thebyte code of a shader and exercise in

2 3d games downloadremaining necessary parameters are thebyte code of a shader and exercise in bytes this is necessary so that theinput signature of our shader can be validated against the array ofattributes just created anyway we will see this topic more deeply in the nexttutorials you at the end as always let’s get theoutput object you let’s do another error checking you very good now we can implement therelease method there is no so big news indeed we have only to get our toresources and release them since our load method can be usedmultiple times to load a different list of vertices let’s release our tworesources so that we can create new ones for new lists of vertices well it can besaid that our vertex buffer class is readyso let’s go to graphics engine class and let’s add the create vertex buffermethod you in which we will simply create a newinstance of the vertex buffer class and we don’t have to forget to deleteour instance in release method of vertex buffer so good now we have to add thefree methods in the vise context class let’s start with set vertex buffer you at the implementation we need to callthe is at vertex buffers method and indicates that we pass only one bufferand we have to pass the pointer to the buffer since it is a private member even inthis case we have to set the device context a friend class of vertex buffer you at this point we have to pass this tribeor the size of our vertex type then we have to set the offset a size inbytes that allows us to set the beginning of our buffer in otherposition and we set it to zero another important thing with this method is tocall another function to pass the input layout object the so called is at inputlayout very well let’s clean a bit our codethis methods for example booth as type of return value is a useless so we willuse void the next method to add is draw trianglelist this method as the name suggests will allow us to gather a list oftriangle on the screen this list will be passed with the method that we have justimplemented to implement our job effort we have to tell two direct acts that ourvertex buffer that we will pass with such vertex buffer is composed by a listof triangles so we will use the method

3 3d games downloadsuch vertex buffer is composed by a listof triangles so we will use the method set primitive technology and at the endwe will call the true method here we have to pass how many vertices we wantto do and from what vertex we want to start let’s return a moment into clearrender target color method here we have to add a really important functionthey set render targets this function will allow us to set in which rendertarget we want to draw and as we said previously when we use the back bufferof our swap chain very well the last method to implement is such viewportsize you in this method we will simply set inwhat area or view part of their already settled rendered target we want to do you now we have to go to upwind of and useour just implemented methods here we can start by defining the structure of ourvertex type as a first fiend let’s define a factor of three floats valuesthat represent the free coordinates of the space XY set then we will use it torepresent the position inside the vertex type structure at this point we can start to create thelist of vertices of our triangle and so we will use the vertices with thecoordinates that we have find out previously you now we can create the vertex buffer andload it with the array filled with our birth disease you since our input layout requires thecompletion of a shader and since this is not a topic of this video we we usemethods already implemented for which we will get the buy code of a vertex shaderand it’s the size you very good now that we have our resourcessettled up we have to focus on set various data for the graphics pipelinewe can start by set the viewport size in which to render our triangle and we willset it with the size of our window then we set all the shaders necessaryfor the execution of the programmable and pixel shader stages obviously wewill pass the vertex buffer from which to get the vertices together and at theend we will finally call our what to method it needs the number of verticesto draw since our vertex buffer at this information let’s go to vertex bufferclass and let’s add a method so that we can retrieve the number of vertices you as the last thing let’s release thevertex buffer after destroy event we can finally start to build ourprogram you that’s all for now folks after a lot oftroubles we have finally rendered our firsttriangle the next time we will try to draw a quote unfortunately it will bemore easy than now since we have implemented almost all the necessarymethods to do it see you soon thanks for watching

Leave a Reply

Your email address will not be published.