directx - Directx10 flip texture horizontal/vertical -
as mentioned in title know how flip id3d10texture2d object horizontal/vertical ?
i used code take screenshot , save file.
id3d10resource *backbufferres; rendertargetview->getresource(&backbufferres); id3d10texture2d *mrenderedtexture; // create our texture d3d10_texture2d_desc texdesc; texdesc.arraysize = 1; texdesc.bindflags = 0; texdesc.cpuaccessflags = 0; texdesc.format = dxgi_format_r8g8b8a8_unorm; texdesc.width = 640; // must same backbuffer texdesc.height = 480; // must same backbuffer texdesc.miplevels = 1; texdesc.miscflags = 0; texdesc.sampledesc.count = 1; texdesc.sampledesc.quality = 0; texdesc.usage = d3d10_usage_default; d3d10device->createtexture2d(&texdesc, 0, &mrenderedtexture); d3d10device->copyresource(mrenderedtexture, backbufferres); d3dx10filtertexture(mrenderedtexture, 0, d3dx10_filter_mirror_u); d3dx10savetexturetofile(mrenderedtexture, d3dx10_iff_png, l"test.png");
d3dx10filtertexture(mrenderedtexture, 0, d3dx10_filter_mirror_u); line doesnt mirror texture. suggestions ?
in shader 1-u flip horizontally or 1-v flip vertically.
edit: if aren't doing rendering there far better ways image manipulation. if want manually have use map , flip data round yourself.
you follows (the code not tested please excuse compile errors):
d3d10resource *backbufferres; rendertargetview->getresource(&backbufferres); id3d10texture2d *mrenderedtexture; // create our texture d3d10_texture2d_desc texdesc; texdesc.arraysize = 1; texdesc.bindflags = 0; texdesc.cpuaccessflags = 0; texdesc.format = dxgi_format_r8g8b8a8_unorm; texdesc.width = 640; // must same backbuffer texdesc.height = 480; // must same backbuffer texdesc.miplevels = 1; texdesc.miscflags = 0; texdesc.sampledesc.count = 1; texdesc.sampledesc.quality = 0; texdesc.usage = d3d10_usage_default; d3d10device->createtexture2d(&texdesc, 0, &mrenderedtexture); d3d10device->copyresource(mrenderedtexture, backbufferres); d3d10_mapped_texture2d d3d10mt = { 0 }; mrenderedtexture->map( 0, d3d10_map_read_write, 0, &d3d10mt ); unsigned int* ppix = (unsigned int)d3d10mt.pdata; int rows = 0; int rowsmax = height; while( rows < rowsmax ) { unsigned int* prowstart = ppix + (rows * width); unsigned int* prowend = prowstart + width; std::reverse( prowstart, prowend ); rows++; } mrenderedtexture->unmap(); d3dx10savetexturetofile(mrenderedtexture, d3dx10_iff_png, l"test.png");
from doc btw:
d3dx10_filter_mirror_u pixels off edge of texture on u-axis should mirrored, not wrapped.
so counts pixels round edge when filtering image.
Comments
Post a Comment