Jump to content
  • Advertisement
Sign in to follow this  
MassacrerAL

How to paint on texture?

This topic is 3919 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

hello all, i`m writing toolset for my engine now, but i have a difficulty that i can`t overcome. i want level designer to have possibility to simply paint on terrain wherever he want. in neverwinter nights 2 toolset it has been done nicely. i know that they can have only six different textures in each tile and therefore i`m quite sure they are using texture splatting(http://www.gamedev.net/reference/articles/article2238.asp). however i have really no idea how to edit texture in such way. i need to create circle around some point in one texture channel. i was thinking about doing it in pixel shader but it would be too complicated. and if i lock texture on cpu i can only rewrite whole texture or rectangle(i think), and it would be slow and complicated. is there some elegant way how to edit texture? for example if i could do something like setTexelColor(x, y, color) on cpu. it would be totally great.

Share this post


Link to post
Share on other sites
Advertisement
If you're doing this in OpenGL, you can keep a copy of the texture in RAM to draw onto it and update the changed portion with glTexSubImage2D... At least this is how I'd do it. (I'm sure D3D has an equivalent function but I'm not familiar with it.)

Btw, even updating the whole texture should not take a noticable amount of time on any halfway modern hardware. I remember doing procedural animated textures this way on a GeForce2.

Share this post


Link to post
Share on other sites
tnx for reply, that sounds good. but how do i store texture in ram? i don`t mean setting something like d3dpool_systemram, becouse it wouldn`t solve anything. maybe something like array?

Share this post


Link to post
Share on other sites
Any image is just an array of pixels in whatever format you're using. For example, 32-bit RGBA textures have one byte for each component per pixel so the array size is width*height*4 bytes and the component bytes are arranged in RGBA order.

If you want to use DX functions, you can probably create a DX surface of some kind in system memory and access its pixel data array directly. It should be the same pixel format that you use for the texture in VRAM.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!