Jump to content
  • Advertisement
Sign in to follow this  
NathanRidley

Direct2D/Direct3D (10) - How do I plot a single pixel on a texture2D?

This topic is 2109 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

With reference to the "hello world" code I've written here:

https://gist.github.com/axefrog/6918511#file-hello-world-sharpdx-2-cs

 

I want to set individual pixels on my 2D surface and I'm not sure that drawing a short line, the way I'm doing it in my sample code, is the best way to do it. My goal is to have a simple, fast 2D environment in which to set individual pixels as part of a series of basic exercise I'm working through. I've read somewhere that using a shader might be the way to go, but I don't know anything about shaders yet, and am not sure if that's overkill anyway.

 

What should I change in my code to provide me with a simple interface for setting pixels?

Share this post


Link to post
Share on other sites
Advertisement

You are required to use shaders in Direct3D 10, so you may as well get started studying them.

 

And to draw a single dot you need a vertex buffer with vertex per dot you want to draw.  If you are worried about performance you will batch as many dots into the vertex buffer as you can before actually rendering anything.  The shader simply outputs whatever color is assigned to the dot (the per-dot color would be another attribute of the vertex buffer).  Draw using a point primitive type.

 

Drawing lines is not to be done dot-by-dot.  For that you use another vertex buffer where the vertices represent the endpoints of the line and draw using a line primitive type.

 

 

L. Spiro

Edited by L. Spiro

Share this post


Link to post
Share on other sites
My goal is to have a simple, fast 2D environment in which to set individual pixels as part of a series of basic exercise I'm working through.

 

What's the point of this?

If the exercise in itself is about implementing things by setting individual pixels then it's probably better to skip DirectX and use something that is made for that type of drawing.

Share this post


Link to post
Share on other sites

You are required to use shaders in Direct3D 10, so you may as well get started studying them.

 

And to draw a single dot you need a vertex buffer with vertex per dot you want to draw.  If you are worried about performance you will batch as many dots into the vertex buffer as you can before actually rendering anything.  The shader simply outputs whatever color is assigned to the dot (the per-dot color would be another attribute of the vertex buffer).  Draw using a point primitive type.

 

Drawing lines is not to be done dot-by-dot.  For that you use another vertex buffer where the vertices represent the endpoints of the line and draw using a line primitive type.

 

 

L. Spiro

 

Thanks for the tip. Any particular reading material you recommend? I'll just hunt for articles of course, but I'm open to anything that stands out from the rest.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!