Drawing and Rendering with DirectX11

The Partridge Family were neither partridges nor a family. Discuss.
eXscreen
Posts: 4
Joined: August 23rd, 2014, 5:49 pm

Drawing and Rendering with DirectX11

Post by eXscreen » August 23rd, 2014, 7:09 pm

So recently i started doing some DX11 stuff and i don't know if i have chosen the right path for drawing and rendering bitmaps. I am using the DirectX Toolkit (SpriteBatch and SpriteFont) for drawing sprites and fonts on to the buffer. Its real easy and doesn't require me to draw sprites with quads and vertices.The problem is that i want to have the option to manipulate individual pixels using for example PutPixel() and not just importing bmps and drawing them.
So my question is: How can i achieve this (it doesn't have to be using the toolkit )?

Thanks

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Drawing and Rendering with DirectX11

Post by albinopapa » August 25th, 2014, 4:28 am

Are you wanting to draw on a specific surfaces texture or maybe an overlay (i.e. health bar )?
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

eXscreen
Posts: 4
Joined: August 23rd, 2014, 5:49 pm

Re: Drawing and Rendering with DirectX11

Post by eXscreen » August 25th, 2014, 12:38 pm

Yeah i want to draw with a specific surface texture.I want to have a system buffer array like in chilis videos that i can just then draw using SpriteBatch.
I've been searching for examples of this and have only managed to find this:

Code: Select all

 
Texture2D rect = new Texture2D(graphics.GraphicsDevice, 80, 30);
 Color[] data = new Color[80*30];
 for(int i=0; i < data.Length; ++i) data[i] = Color.Chocolate;
 rect.SetData(data);
 Vector2 coor = new Vector2(10, 20);
 spriteBatch.Draw(rect, coor, Color.White);
In this code he has an array of Color objects that he sets to a texture and then draws that texture using spritebatch.I'm thinking of making an array of color the size of the screen(800x600) then setting it to the texture(also the size of the screen) and then drawing that texture using spritebatch.
Is this good or is there a better solution?

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Drawing and Rendering with DirectX11

Post by chili » August 25th, 2014, 1:44 pm

You have to think about why you need putpixel functionality in the first place. If you're using a system buffer for your drawing, then you won't get any improvement over what is in the tutorials. Just because you write it in DX11 doesn't mean it will be any faster.

To realize the potential of HW acceleration, you need to have the CPU involved as little as possible in the rendering process.
Chili

eXscreen
Posts: 4
Joined: August 23rd, 2014, 5:49 pm

Re: Drawing and Rendering with DirectX11

Post by eXscreen » August 25th, 2014, 2:42 pm

So is it worth rendering a 2d game in DX11? Right now i'm trying to port the platformer to DX11 but if the performance isn't going to improve i don't see the point. I like the performance of the platformer but for future projects should i learn how to do rendering with quads in DX11 or just stick with DX9?

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Drawing and Rendering with DirectX11

Post by albinopapa » August 26th, 2014, 7:31 am

Use the textured quads method, will be much faster, as long as you use the vertex and pixel shaders that is.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Drawing and Rendering with DirectX11

Post by chili » August 26th, 2014, 1:24 pm

Using sprite batch is rendering with textured quads. It's only when you try to access the framebuffer from the CPU each frame that your performance will be killed.

Why do you even want to manipulate individual pixels?
Chili

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Drawing and Rendering with DirectX11

Post by albinopapa » August 29th, 2014, 7:57 am

I think what you would want to do to make a 2D accelerated version of the Platformer is load all the textures for the dude to a layered texture, mipmap I believe, and as for the level graphics (walls and floors ) they could be textured quads or cubes that are proceedurally placed just as the 2D tiles were and d3d would take care of the cam/viewport/clipping you would just keep the code for controlling the dude, collision and updating the camera position to the CPU. At least I think how all that would work.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
jkhippie
Posts: 218
Joined: March 24th, 2014, 5:11 pm

Re: Drawing and Rendering with DirectX11

Post by jkhippie » August 29th, 2014, 8:27 pm

I'd like to be able to use PutPixel and sprite->Draw together, like in the Advanced Framework with the teapot, but it seems spotty. Sometimes I only get a display of the BeginScene/EndScene stuff OR the buffer/memcpy stuff. I've tried using LockedRect to draw PutPixel-style to a surface and then drawing it with sprite->Draw, but no joy. I must be missing something? It'd sure be nice to find a Chili-style explanation of all that. < hint, hint >
To strive, to seek, to find, and not to yield.

DeitusPrime
Posts: 97
Joined: June 9th, 2014, 11:14 pm

Re: Drawing and Rendering with DirectX11

Post by DeitusPrime » August 29th, 2014, 9:48 pm

jkhippie wrote:I'd like to be able to use PutPixel and sprite->Draw together, like in the Advanced Framework with the teapot, but it seems spotty. Sometimes I only get a display of the BeginScene/EndScene stuff OR the buffer/memcpy stuff. I've tried using LockedRect to draw PutPixel-style to a surface and then drawing it with sprite->Draw, but no joy. I must be missing something? It'd sure be nice to find a Chili-style explanation of all that. < hint, hint >
I'm on something simular to this.

Though I've got a different framework I'm working on, in the Engine::Run() function is a loop that uses BeginScene(), EndScene(), Present()... I've tried adding BeginFrame(); EndFrame(); code into that. Works thus far for drawline, putpixel, etc. right? (It does).

HOWEVER, when I run the FONT code I'm using(which is stripped-down version of the DirectX9 SDK example...it does not require a "font image" file to load from, just puts text on the screen) This font code *also* accesses the backbuffer in a manner that Putpixel does...this does not allow me to have BOTH a text-based font, AND the putpixel drawn stuff at the same time (which is lame, because I need both)

Any ideas? (I could post code, but I'd have to give you the whole project file--which I can't do just yet)
Choose not to go to destruction with a taco-sauce that is bland...
Go to construction with a taco-sauce that is flavorful!!
Mwa ha ha!!

Post Reply