1

I started a very basic XNA 4.0 program where I load a small red image of a dot in through the Content loader. The red dot is 10x10 and is rounded at the edges to make it look rounded. I am drawing it on-screen and updating its X and Y positions to that of the X and Y position of the Mouse. So basically it's a custom red cursor.

Now my question is: How would I go about using this cursor as a brush? When I click the left mouse button I want it to paint onto a blank Texture2D background that is the size of the current screen. It would function just like a paint brush in MSPAINT.

I imagine I would need an array of Vector2 points that holds the points that the mouse has moved over, and for each of these points when the update occurs it paints the dot on the background Texture2D?

It's probably not very efficient but it was all I could think of at the time.

I've also read into changing color data of Texture2Ds but alas have had no luck.

Sebastian Hofmann
  • 1,440
  • 6
  • 15
  • 21
  • why not save a memory image of the who canvas and whenever u add "draw" a new point update the image, so the refresh will require only the draw of the image of part of the image... any way i am clueless in XNA so this is just an idea not sure if its valid here. –  Apr 05 '12 at 13:15
  • Implement it the same way you would it for any other program that has this capability. You using XNA doesn't make it special. If you don't know how to even start, then your out of your league, go hire somebody who knows what they are doing. I mean you do have a computer science degree right, you claim you have experience with DirectX, something tells me your profile is full of lies. – Security Hound Apr 05 '12 at 14:56
  • Ramhound, Im sorry you feel that way but i think thats a little harsh, Have a look at my portfolio if you dont believe me http://www.sourcemodding.com/portfolio/index.html I can understand your scepticism since this is my first post on stackoverflow, that said you have no right to claim my profile "is full of lies" Stackoverflow is a reputable community known for its high degree of helpful citizens. for your information as well Ramhound, Ive spent the last 4-5 hours working on trying to figure it out and i finally figured it out. Try and be a little more understanding next time. thanks – TheFooFighter Apr 05 '12 at 16:39

3 Answers3

3

I've never tried painting with XNA but like the idea ! So i've looked around a little and found out this answered question and who knows it might be just what you need! Good luck with your game. XNA draw / paint onto a Texture2D at runtime

Community
  • 1
  • 1
phadaphunk
  • 12,785
  • 15
  • 73
  • 107
  • Ive managed to figure it out not exactly from the link you provided above but it led me to what eventually solved the problem. If you are interested you can check out my own answer to the question :). Thank you – TheFooFighter Apr 05 '12 at 16:41
  • No problem but you do know you can add a real answer to your question and accept it ? Makes things more clear ;) – phadaphunk Apr 05 '12 at 16:45
  • i think i know what you mean "answer my own question"? ive tried but i need to wait 4 hours since im a new user before i can. I'll do that when the 4 have elapsed :) if you want to look at it though it can be found here https://thefoofighter@github.com/thefoofighter/paint.git – TheFooFighter Apr 05 '12 at 16:49
1

For those of you who are interested in how i managed to "paint" onscreen the whole code repository can be found here https://thefoofighter@github.com/thefoofighter/paint.git

Its certainly best way to approach my problem but it does what i need it to do and since i dont need to worry about optimization with the bigger program im porting this into i havent tried making it better.

There is a readme with the above Git that provides more information on changes and optimizations.

0

At loadContent:

var renderTarget = RenderTarget2D(graphicsDevice, width, height, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);

At draw:
- set this rendertarget
- draw the brush at the currentPosition
- unset the rendertarget
- draw the rendertarget

This way you don't need to set / unset data from the rendertarget onto the texture or keep track of the previous positions.

Tommy Andersen
  • 7,165
  • 1
  • 31
  • 50
mike
  • 26
  • 3