Skip to main content
GameDev.net gamedev.net
🔒 Locked

Drawing in games

Started by -Greywolf- Feb 11, 2009 at 8:17 AM 2 replies 900+ views
Original Post
-Greywolf-
-Greywolf-
Hi everybody. I'm currently developing a 2D game where the player will have the ability to draw shapes within the game, kind of like in Crayon Physics. I'm experimenting with ways of doing this. The current technique that I'm using is not very efficient. What I do is take the current position of the mouse and simply draw a pixel onto a texture by locking, writing and then unlocking the texture. As I said this is not very efficient and the game does lag when doing this. Is their a better way to do this?
LorenzoGatti
LorenzoGatti
Altering texture shouldn't be necessary; you can record every mouse movement and redraw draw suitable geometry every frame, hopefully using efficient vertex buffers instead of immediate mode calls.
For example:
- dots on each different mouse position or lines connecting them;
- point sprites;
- point-like or line-like billboard sprites made of texture-mapped quads or triangles or triangle strips (with slightly offset coordinates around the mouse positions).

If you are doing something similar to Crayon Physics, it should be even easier: since you are already "paying" for a geometric representation of your shapes you can translate low-level mouse motions to shape alteration and render whole shapes in more organized ways such as a decomposition into texture-mapped triangle strips or polygons and/or line strips for borders.
Omae Wa Mou Shindeiru
Matt Aufderheide
Matt Aufderheide
Locking and writing to one texture once per-frame should not lag the game very much if done correctly. There are optimizations you can do. When you lock the texture don't lock the whole surface, only lock a small area around where the write will take place; this shouldn't be hard to calculate.

I assume you are creating the texture in D3DPOOL_DEFAULT with D3DUSAGE_DYNAMIC.

If you are already doing these things and its still a big lag, then I still think something is wrong...
-Greywolf-
-Greywolf-
Thanks for all your replies. I did create the texture in the default pool and I also made it dynamic but I haven't thought of locking only that specific area. Thanks for that idea Matt. Lorenzo, you also gave me a nice technique to use, but it will be better to use the texture technique as the collision detection uses a 2D surface. The way levels are structured and how the player will interact with them will also require the 2D surface.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.