Skip to content

Commit ee4ae37

Browse files
Added remaining Graphics WhatIs articles
1 parent d439f84 commit ee4ae37

21 files changed

+716
-4
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
---
2+
title: What is 3D Rendering?
3+
description: The basics of the 3D rendering pipeline for MonoGame!
4+
requireMSLicense: true
5+
---
6+
7+
The 3D graphics pipeline uses a `graphics device` (the current display device rendering to the screen) to load resources and render a 3D scene using an [Effect](xref:Microsoft.Xna.Framework.Graphics.Effect).
8+
9+
In general, the 3D pipeline requires the following state information for initialization:
10+
11+
* World, view, and projection matrices to transform 3D vertices into a 2D space.
12+
* A vertex buffer which contains the geometry to render.
13+
* An effect that sets the render state necessary for drawing the geometry.
14+
15+
> [!NOTE]
16+
> For a more detailed explanation of World, View and Projection matrices , check out this [GameFromScratch - beginning 3D](https://gamefromscratch.com/monogame-tutorial-beginning-3d-programming/) article.
17+
18+
As you become comfortable with these ideas, you may want to learn more about the following:
19+
20+
* Manipulating vertices
21+
* Creating your own effects
22+
* Applying textures
23+
* Improving performance by using index buffers.
24+
25+
The MonoGame Framework uses a shader-driven programmable pipeline and requires a graphics card capable of at least Shader Model 2.0. A class called [BasicEffect](xref:Microsoft.Xna.Framework.Graphics.BasicEffect) encapsulates most of these common operations.
26+
27+
> ![IMPORTANT]
28+
> Shader requirements depend on the platform being targeted, the majority of MonoGame titles these days require Shader Model 3.0 as a minimum. You can use [this guide](https://www.lifewire.com/determine-directx-version-and-shader-model-812997) as a reference.
29+
> MonoGame automatically converts all shaders to their appropriate platform based on the "shader level" defined.
30+
31+
## The Graphics Device
32+
33+
When you create a game with MonoGame, the framework initializes a graphics device for you.
34+
35+
The [GraphicsDeviceManager](xref:Microsoft.Xna.Framework.GraphicsDeviceManager) initializes the [GraphicsDevice](xref:Microsoft.Xna.Framework.Graphics.GraphicsDevice).
36+
37+
Before [Initialize](xref:Microsoft.Xna.Framework.Game.Initialize) is called, there are three ways to change the [GraphicsDevice](xref:Microsoft.Xna.Framework.Graphics.GraphicsDevice) settings:
38+
39+
1. Set the appropriate properties such as the [PreferredBackBufferHeight](xref:Microsoft.Xna.Framework.GraphicsDeviceManager.PreferredBackBufferHeight) and [PreferredBackBufferWidth](xref:Microsoft.Xna.Framework.GraphicsDeviceManager.PreferredBackBufferWidth) on the [GraphicsDeviceManager](xref:Microsoft.Xna.Framework.GraphicsDeviceManager) in your game's constructor.
40+
41+
```csharp
42+
_graphics.PreferredBackBufferHeight = 768;
43+
_graphics.PreferredBackBufferWidth = 1024;
44+
_graphics.ApplyChanges();
45+
```
46+
47+
1. Handle the `PreparingDeviceSettings` event on the [GraphicsDeviceManager](xref:Microsoft.Xna.Framework.GraphicsDeviceManager), and change the [PreparingDeviceSettingsEventArgs.GraphicsDeviceInformation.PresentationParameters](xref:Microsoft.Xna.Framework.Graphics.PresentationParameters) member properties.
48+
49+
```csharp
50+
_graphics.PreparingDeviceSettings += OnPreparingDeviceSettings;
51+
private void OnPreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
52+
{
53+
e.GraphicsDeviceInformation.PresentationParameters.BackBufferWidth = 1024;
54+
e.GraphicsDeviceInformation.PresentationParameters.BackBufferHeight = 768;
55+
}
56+
```
57+
58+
> [!WARNING]
59+
> Any changes made to the [PreparingDeviceSettingsEventArgs](xref:Microsoft.Xna.Framework.PreparingDeviceSettingsEventArgs) will override the [GraphicsDeviceManager](xref:Microsoft.Xna.Framework.GraphicsDeviceManager) preferred settings.
60+
61+
1. Handle the `DeviceCreated` event on the [GraphicsDeviceManager](xref:Microsoft.Xna.Framework.GraphicsDeviceManager), and change the [PresentationParameters](xref:Microsoft.Xna.Framework.Graphics.GraphicsDevice.PresentationParameters) of the [GraphicsDevice](xref:Microsoft.Xna.Framework.Graphics.GraphicsDevice) directly.
62+
63+
```csharp
64+
IGraphicsDeviceService graphicsDeviceService = (IGraphicsDeviceService)
65+
Game.Services.GetService(typeof(IGraphicsDeviceService));
66+
67+
if (graphicsDeviceService != null)
68+
{
69+
graphicsDeviceService.DeviceCreated += OnDeviceCreated;
70+
}
71+
72+
private void OnDeviceCreated(object sender, EventArgs e)
73+
{
74+
// Handle updating Graphics Device Presentation Parameters
75+
}
76+
```
77+
78+
When you call [Game.Initialize](xref:Microsoft.Xna.Framework.Game.Initialize) the [GraphicsDeviceManager](xref:Microsoft.Xna.Framework.GraphicsDeviceManager) creates and configures [GraphicsDevice](xref:Microsoft.Xna.Framework.Graphics.GraphicsDevice). You can then safely access [GraphicsDevice](xref:Microsoft.Xna.Framework.Graphics.GraphicsDevice) settings such as the backbuffer, depth/stencil buffer, viewport, and render states in the [Initialize](xref:Microsoft.Xna.Framework.Game.Initialize) method.
79+
80+
> [!IMPORTANT]
81+
> After you call [Game.Initialize](xref:Microsoft.Xna.Framework.Game.Initialize), changes to the [PresentationParameters](xref:Microsoft.Xna.Framework.Graphics.GraphicsDevice.PresentationParameters) of the [GraphicsDevice](xref:Microsoft.Xna.Framework.Graphics.GraphicsDevice) will not take effect until you call [GraphicsDeviceManager.ApplyChanges](xref:Microsoft.Xna.Framework.GraphicsDeviceManager.ApplyChanges). Other changes, such as render states, will take effect immediately.
82+
83+
## Resources
84+
85+
A graphics resource is a collection of data stored in memory that can be accessed by either the CPU or GPU. The types of resources that an application might use include:
86+
87+
* [Render targets](./WhatIs_Render_Target.md)
88+
* [Vertex buffers](xref:Microsoft.Xna.Framework.Graphics.VertexBuffer)
89+
* [Index buffers](xref:Microsoft.Xna.Framework.Graphics.IndexBuffer)
90+
* [Textures](xref:Microsoft.Xna.Framework.Graphics.Texture)
91+
92+
> ![NOTE]
93+
> FOr a more detailed understanding in the use of these terms, check out [Riemers 3D series](https://github.com/simondarksidej/XNAGameStudio/wiki/Riemers3DXNA1Terrainoverview) on the XNAGameStudio Archive.
94+
95+
Based on the resource management mode that was used when a resource is created, it should be reloaded when the device is reset. For more information, see [Loading Resources](../../howto/content_pipeline/HowTo_LoadContentLibrary.md).
96+
97+
### Vertex and Index Buffers
98+
99+
A vertex buffer contains a list of 3D vertices to be streamed to the graphics device. Each vertex in a vertex buffer may contain data about not only the 3D coordinate of the vertex but also other information describing the vertex, such as the vertex normal, color, or texture coordinate. Which you should use will depend on your usage and the needs of the vertex information you are drawing with, [for example](https://stackoverflow.com/questions/4702150/difference-between-using-vertexpositionnormaltexture-and-vertexpositiontexture.)
100+
101+
The MonoGame Framework contains several classes to describe common vertex declaration types, such as:
102+
103+
* [VertexPositionColor](xref:Microsoft.Xna.Framework.Graphics.VertexPositionColor)
104+
105+
Vertex Declaration containing Position and Color of a vertex.
106+
107+
* [VertexPositionColorTexture](xref:Microsoft.Xna.Framework.Graphics.VertexPositionColorTexture)
108+
109+
Vertex Declaration containing Position, Color and Texture of a vertex.
110+
111+
* [VertexPositionNormalTexture](xref:Microsoft.Xna.Framework.Graphics.VertexPositionNormalTexture)
112+
113+
Vertex Declaration containing Position, Normal and Texture of a vertex.
114+
115+
* [VertexPositionTexture](xref:Microsoft.Xna.Framework.Graphics.VertexPositionTexture).
116+
117+
Vertex Declaration containing Position and Texture of a vertex.
118+
119+
> [!NOTE]
120+
> Use the [VertexElement](xref:Microsoft.Xna.Framework.Graphics.VertexElement) class to compose custom vertex types.
121+
122+
Vertex buffers can contain indexed or non-indexed vertex data.
123+
124+
> [!NOTE]
125+
> If a **Vertex Buffer** is not indexed, all of the vertices are placed in the vertex buffer in the order they are to be rendered. Because 3D line lists or triangle lists often reference the same vertices multiple times, this can result in a large amount of redundant data.
126+
>
127+
> **Index buffers** allow you to list each vertex only once in the vertex buffer. An index buffer is a list of indices into the vertex buffer, given in the order that you want the vertices to render.
128+
129+
### Render a non-indexed vertex buffer
130+
131+
To render a non-indexed vertex buffer, call the [GraphicsDevice.DrawPrimitives](/api/Microsoft.Xna.Framework.Graphics.GraphicsDevice.html#Microsoft_Xna_Framework_Graphics_GraphicsDevice_DrawPrimitives_Microsoft_Xna_Framework_Graphics_PrimitiveType_System_Int32_System_Int32_) or [GraphicsDevice.DrawUserPrimitives](/api/Microsoft.Xna.Framework.Graphics.GraphicsDevice.html#Microsoft_Xna_Framework_Graphics_GraphicsDevice_DrawUserPrimitives__1_Microsoft_Xna_Framework_Graphics_PrimitiveType___0___System_Int32_System_Int32_) Methods.
132+
133+
### Render an indexed vertex buffer
134+
135+
To render an indexed buffer, call the [GraphicsDevice.DrawIndexedPrimitives](/api/Microsoft.Xna.Framework.Graphics.GraphicsDevice.html#Microsoft_Xna_Framework_Graphics_GraphicsDevice_DrawIndexedPrimitives_Microsoft_Xna_Framework_Graphics_PrimitiveType_System_Int32_System_Int32_System_Int32_) or [GraphicsDevice.DrawUserIndexedPrimitives](/api/Microsoft.Xna.Framework.Graphics.GraphicsDevice.html#Microsoft_Xna_Framework_Graphics_GraphicsDevice_DrawUserIndexedPrimitives__1_Microsoft_Xna_Framework_Graphics_PrimitiveType___0___System_Int32_System_Int32_System_Int16___System_Int32_System_Int32_) Methods.
136+
137+
### Textures
138+
139+
A texture resource is a structured collection of texture data. The data in a texture resource is made up of one or more sub-resources that are organized into arrays and mipmap chains. Textures are filtered by a texture sampler as they are read. The type of texture influences how the texture is filtered.
140+
141+
You can apply textures by using the [Texture](xref:Microsoft.Xna.Framework.Graphics.BasicEffect.Texture) property of the [BasicEffect](xref:Microsoft.Xna.Framework.Graphics.BasicEffect) class, or choose to write your own effect methods to apply textures.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: What is Antialiasing?
3+
description: The definition of Antialsing for MonoGame!
4+
requireMSLicense: true
5+
---
6+
7+
Antialiasing is a technique for softening or blurring sharp edges so they appear less jagged when rendered.
8+
9+
Antialiasing is accomplished by multi-sampling each pixel at multiple pixel locations and combining the samples to generate a final pixel color. Increasing the number of samples per pixel increases the amount of antialiasing which generates a smoother edge:
10+
11+
* 4x multisampling requires four samples per pixel.
12+
* 2x multisampling requires two sampler per pixel.
13+
* And so on.
14+
15+
Use the [MultiSampleCount](xref:Microsoft.Xna.Framework.Graphics.PresentationParameters.MultiSampleCount) property of the [PresentationParameters](xref:Microsoft.Xna.Framework.Graphics.PresentationParameters) class to set the number of samples for the back buffer.
16+
17+
Set the [PreferMultiSampling](xref:Microsoft.Xna.Framework.GraphicsDeviceManager.PreferMultiSampling) property on the [GraphicsDeviceManager](xref:Microsoft.Xna.Framework.GraphicsDeviceManager) class to **true** to enable multi-sampling for the back buffer.
18+
19+
> [!IMPORTANT]
20+
> This will be ignored if the hardware does not support multi-sampling.
21+
22+
## See Also
23+
24+
[Enabling Anti-aliasing (Multi-sampling)](../../howto/graphics/HowTo_Enable_Anti_Aliasing.md)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: What Is a Back Buffer?
3+
description: The definition of a Back Buffer for MonoGame!
4+
requireMSLicense: true
5+
---
6+
7+
A back buffer is a [render target](./WhatIs_Render_Target.md) whose contents will be sent to the device when [GraphicsDevice.Present](xref:Microsoft.Xna.Framework.Graphics.GraphicsDevice.Present) is called.
8+
9+
The graphics pipeline renders to a render target, the particular render target that the device presents to the display is called the back buffer. Use the [BackBufferWidth](xref:Microsoft.Xna.Framework.Graphics.PresentationParameters.BackBufferWidth) and [BackBufferHeight](xref:Microsoft.Xna.Framework.Graphics.PresentationParameters.BackBufferHeight) properties to get the back buffer dimensions. Render directly to the back buffer or to a render target by configuring the device using [GraphicsDevice.SetRenderTarget](/api/Microsoft.Xna.Framework.Graphics.GraphicsDevice.html#Microsoft_Xna_Framework_Graphics_GraphicsDevice_SetRenderTarget_Microsoft_Xna_Framework_Graphics_RenderTarget2D_) and [GraphicsDevice.SetRenderTargets](/api/Microsoft.Xna.Framework.Graphics.GraphicsDevice.html#Microsoft_Xna_Framework_Graphics_GraphicsDevice_SetRenderTargets_Microsoft_Xna_Framework_Graphics_RenderTargetBinding___).
10+
11+
* For Windows, the back buffer is created to match the dimensions of the [ClientBounds](xref:Microsoft.Xna.Framework.GameWindow.ClientBounds) by default.
12+
* For Consoles, the back buffer is created with the dimensions that have been specified by the user. When going into full-screen mode on Windows.
13+
* On Mobile, it is recommended to set the BackBuffer dimensions to the expected resolution based on the desired orientation of the device (Portrait or Landscape).
14+
15+
It is often desirable to set the back buffer dimensions to match the [DisplayMode](xref:Microsoft.Xna.Framework.Graphics.GraphicsDevice.DisplayMode) dimensions so that the game ("display") resolution does not change when it goes into the full-screen mode.
16+
17+
The back buffer created for consoles is not necessarily the same size as the final resolution on a television connected for display. Consoles automatically scale output to the television resolution selected by the user in the System. If the aspect ratio of the back buffer is different from the aspect ratio of the television display mode, the console will automatically add black bars (also called letter-boxing) if the user's display is not widescreen.
18+
19+
In addition, if you request a back-buffer resolution that is not supported by the output device, the MonoGame framework automatically selects the highest resolution supported by the output device. For example, if you create a back-buffer with a resolution of 1920x1080 (for example, 1080p or 1080i) and display it on a device with 480i resolution, the back-buffer is resized to 480i automatically.
20+
21+
## See Also
22+
23+
[Viewport](xref:Microsoft.Xna.Framework.Graphics.GraphicsDevice.Viewport)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: What Is Blend State?
3+
description: The definition for the Blend State for MonoGame!
4+
requireMSLicense: true
5+
---
6+
7+
The Blend state controls how color and alpha values are blended when combining rendered data with existing render target data.
8+
9+
The blend state class, [BlendState](xref:Microsoft.Xna.Framework.Graphics.BlendState), contains state that controls how colors are blended. Each time you render, the pixel data you generate (call it source data) is stored in a render target. The render target might be empty or it might already contain data (call it destination data). Blending occurs each time you combine source and destination data.
10+
11+
You have a lot of control over how you blend the source and the destination data.
12+
13+
For example:
14+
15+
* You can choose to overwrite the destination with the source data by setting [BlendState.Opaque](xref:Microsoft.Xna.Framework.Graphics.BlendState)
16+
* Combine the data by adding them together using [BlendState.Additive](xref:Microsoft.Xna.Framework.Graphics.BlendState).
17+
18+
You can blend only the color data or the alpha data, or both, by setting up the blending functions [ColorBlendFunction](xref:Microsoft.Xna.Framework.Graphics.BlendState.ColorBlendFunction) and [AlphaBlendFunction](xref:Microsoft.Xna.Framework.Graphics.BlendState.AlphaBlendFunction). You can even limit your blending operation to one or more colors (or channels) using [ColorWriteChannels](xref:Microsoft.Xna.Framework.Graphics.BlendState.ColorWriteChannels).
19+
20+
> [!NOTE]
21+
> For an example that creates and uses a state object, see [Creating a State Object](../../howto/graphics/HowTo_Create_a_StateObject.md).

0 commit comments

Comments
 (0)