Page 1 of 2

Drawing and Rendering with DirectX11

Posted: August 23rd, 2014, 7:09 pm
by eXscreen
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

Re: Drawing and Rendering with DirectX11

Posted: August 25th, 2014, 4:28 am
by albinopapa
Are you wanting to draw on a specific surfaces texture or maybe an overlay (i.e. health bar )?

Re: Drawing and Rendering with DirectX11

Posted: August 25th, 2014, 12:38 pm
by eXscreen
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?

Re: Drawing and Rendering with DirectX11

Posted: August 25th, 2014, 1:44 pm
by chili
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.

Re: Drawing and Rendering with DirectX11

Posted: August 25th, 2014, 2:42 pm
by eXscreen
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?

Re: Drawing and Rendering with DirectX11

Posted: August 26th, 2014, 7:31 am
by albinopapa
Use the textured quads method, will be much faster, as long as you use the vertex and pixel shaders that is.

Re: Drawing and Rendering with DirectX11

Posted: August 26th, 2014, 1:24 pm
by chili
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?

Re: Drawing and Rendering with DirectX11

Posted: August 29th, 2014, 7:57 am
by albinopapa
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.

Re: Drawing and Rendering with DirectX11

Posted: August 29th, 2014, 8:27 pm
by jkhippie
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 >

Re: Drawing and Rendering with DirectX11

Posted: August 29th, 2014, 9:48 pm
by DeitusPrime
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)