- Home /
What's the best way to draw to a texture?
My game has a small procedurally generated world, and I'm trying to make it generate textures with a map of it for an in-game globe. I'm having trouble grasping how to draw lines onto a texture (the rest of drawing should mostly be that and floodfills, which seem pretty easy.)
Most of the code samples that I've found for drawing lines on a Texture2D only allow for single width lines, and use tons of calls to SetPixel, which I've heard is slow. I've also seen suggestions to use GL immediate mode rendering to a RenderTexture, but I don't know if there's any way to save that and I don't know if it will even do what I want.
Is there some asset I'm missing that would make this easier? If I do have to write a line rasterization algorithm myself, could someone give me an overview of how that would work?
You can save a RenderTexture to a Texture2D: http://answers.unity3d.com/questions/9969/convert-a-rendertexture-to-a-texture2d.html
Do you need to keep updating this map texture in realtime? Or is it just generated once?
If you need to draw to the texture then use SetPixels (not SetPixel) and draw all you need in one go. Do you need to redraw the lines every frme or only at generation? SetPixels is not superfast but definitely fast enough to do once, maybe even fast enough to do per frame in some cases.
If you need to draw several times every frame I would look into using a rendertexture as rendertarget.
Your answer
Follow this Question
Related Questions
Create, export, and then load a huge image. 2 Answers
How do I get file size of texture? 1 Answer
How to save Texture2D to BMP? 1 Answer
Show only the right most part of the loaded image 2 Answers
how we can Enabled Texture Read/Write property run time from script for Android and IOS Devices ?? 0 Answers