surface to texture

cccccui 2011-05-19 11:45:27
我想把 屏幕截取出来,然后用directx 渲染一下。

代码大致如下
surface = scrDevice.CreateOffscreenPlainSurface(scrDevice.DisplayMode.Width ,scrDevice.DisplayMode.Height , Format.A8R8G8B8, Pool.SystemMemory );
scrDevice.GetFrontBufferData(0, surface);
GraphicsStream gStream = SurfaceLoader.SaveToStream(ImageFileFormat.Jpg, surface, new Rectangle(0, 0, 1024, 768));
gStream.Seek(0, System.IO.SeekOrigin.End);
texture = TextureLoader.FromStream(device, gStream);
(c#代码, 大概思路就是
通过 CreateOffscreenPlainSurface(),GetFrontBufferData()把桌面放到 surface里,然后把surface转换成stream,再把stream转换成texture) 这样的问题 是 surface,转换[来源:GameRes.com]成stream,在转换成texture,消耗的时间太长。有没有其他什么办法啊?
查了资料,貌似 surface ->GetContainer()可以得到texture,但貌似surface如果是通过GetFrontBufferData()方法生成的,没办法得到他的texture, 有没有其他什么办法,可以把桌面截取出来 然后放到texture里渲染啊?



(大家看看我的结贴率,就该我是不平凡的人,分数多多啊。。)

...全文
218 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhanlonglong 2011-05-20
  • 打赏
  • 举报
回复
结贴率原来可以超过100%!!!
蚂蚁上树 2011-05-20
  • 打赏
  • 举报
回复
cccccui 2011-05-20
  • 打赏
  • 举报
回复
顶上去,结贴率高高啊。
gamemagic 2011-05-20
  • 打赏
  • 举报
回复
只有不和谐的人,结帖率才能够超过100
chifagao 2011-05-20
  • 打赏
  • 举报
回复
DDraw 里面 图片就是 表面 所以 texture也是表面。

锁定 获得指针 图片信息 就可以 随便操作了。

网上应该有代码


cccccui 2011-05-20
  • 打赏
  • 举报
回复
csdn太球了。我原来结贴率一直都是 102.5%的。昨天发这个帖子,今天上午看到还是102.5%的。

下午居然帮我改了。汗死了。
是不是手动改数据库的啊????



另我的问题还是不会啊。哭
hellolongee 2011-05-20
  • 打赏
  • 举报
回复
没用过C#,我说下c++环境下怎么将surface复制到texture中,希望对你有用。
d3d中,texture的内容是由若干的surface来构成的。
那么可通过以下的方法将src surface复制到dst texture中。
IDirect3DSurface* srcSur, *dstSur;
IDirect3DTexture* dstTex;

dstTex->GetSurfaceLevel(0, &dstSur);

现在就得到了源surface和目标surface两个指针了,然后通过LockRect的方法获取
数据,利用memcpy将src surface拷贝到dst surfcae中。

srcSur->LockRect()
dstSur->LockRect()
/*
typedef struct D3DLOCKED_RECT {
INT Pitch;
void *pBits;
} D3DLOCKED_RECT, *LPD3DLOCKED_RECT;
*/
void* srcBits = ...
void* dstBits = ...
for(int y=0;y<height;y++)
{
memcpy(dstBits, srcBits, sz);
dstBits += dstPitchs;
srcBits += srcPitchs;
}


dstSur->UnlockRect()
srcSur->UnlockRect


cccccui 2011-05-20
  • 打赏
  • 举报
回复
这个速度太慢了 。。 i3,310M的配置 都 将近300毫秒的,有没有其他解决方法啊
Sou2012 2011-05-20
  • 打赏
  • 举报
回复
一般都是这样做的。你可以把颜色位数降低点,速度会快一点。
cccccui 2011-05-20
  • 打赏
  • 举报
回复
帮我 回答回答啊。。。

高结贴率啊
Physically Based Rendering from Theory to Implementation 一共3部分~~~~~~~~~, 源码下载to h t t p ://www.p b r t . o r g /downloads.php /////////////////////////////////// CHAPTER 01. INTRODUCTION Literate Programming Indexing and Cross-Referencing Photorealistic Rendering and the Ray-Tracing Algorithm Cameras Ray-Object Intersections Light Distribution Visibility Surface Scattering Recursive Ray Tracing Ray Propagation pbrt: System Overview Phases of Execution Scene Representation Main Rendering Loop Scene Methods An Integrator for Whitted-Style Ray Tracing How to Proceed through This Book The Exercises Using and Understanding the Code Pointer or Reference? Code Optimization The Book Web site Bugs Further Reading Exercise CHAPTER 02. GEOMETRY AND TRANSFORMATIONS Coordinate Systems Coordinate System Handedness Vectors Arithmetic Scaling Dot and Cross Product Normalization Coordinate System from a Vector Points Normals Rays Ray Differentials Three-Dimensional Bounding Boxes Transformations Homogeneous Coordinates Basic Operations Translations Scaling x, y, and z Axis Rotations Rotation around an Arbitrary Axis The Look-At Transformation Applying Transformations Points Vectors Normals Rays Bounding Boxes Composition of Transformations Transformations and Coordinate System Handedness Differential Geometry Further Reading Exercises CHAPTER 03. SHAPES Basic Shape Interface Bounding Refinement Intersection Avoiding Incorrect Self-Intersections Shading Geometry Surface Area Sidedness Spheres Construction Bounding Intersection Partial Spheres Partial Derivatives of Normal Vectors DifferentialGeometry Initialization Surface Area Cylinders Construction Bounding Intersection Partial Cylinders Surface Area Disks Construction Bounding Intersection Surface Area Other Quadrics Cones Paraboloids Hyperboloids Triangles and Meshes Triangle Triangle Intersection Surface Area Shading Geometry Subdivision Surfaces † Mesh Representation Bounds Subdivison Further Reading Exercises CHAPTER 04. PRIMITIVES AND INTERSECTION ACCELERATION Primitive Interface and Geometric Primitives Geometric Primitives Object Instancing Aggregates Ray-Box Intersections Grid Accelerator Creation Traversal Kd-Tree Accelerator Tree Representation Tree Construction Traversal Further Reading Exercises CHAPTER 05. COLOR AND RADIOMETRY Spectral Representation Spectrum Class XYZ Color Basic Radiometry Basic Quantities Incident and Exitant Radiance Functions Working with Radiometric Integrals Integrals over Projected Solid Angle Integrals over Spherical Coordinates Integrals over Area Surface Reflection and the BRDF Further Reading Exercises CHAPTER 06. CAMERA MODELS Camera Model Camera Coordinate Spaces Projective Camera Models Orthographic Camera Perspective Camera Depth of Field Environment Camera Further Reading Exercises CHAPTER 07. SAMPLING AND RECONSTRUCTION Sampling Theory The Frequency Domain and the Fourier Transform Ideal Sampling and Reconstruction Aliasing Antialiasing Techniques Application to Image Synthesis Sources of Aliasing in Rendering Understanding Pixels Image Sampling Interface Sample Representation and Allocation Stratified Sampling Low-Discrepancy Sampling † Definition of Discrepancy Constructing Low-Discrepancy Sequences (0,2)-Sequences The Low-Discrepancy Sampler Best-Candidate Sampling Patterns † Generating the Best-Candidate Pattern Using the Best-Candidate Pattern Image Reconstruction Filter Functions Further Reading Exercises CHAPTER 08. FILM AND THE IMAGING PIPELINE Film Interface Image Film Image Output Image Pipeline Perceptual Issues and Tone Mapping † Luminance and Photometry Bloom Tone Mapping Interface Maximum to White Contrast-Based Scale Factor Varying Adaptation Luminance Spatially Varying Nonlinear Scale Final Imaging Pipeline Stages Further Reading Exercises CHAPTER 09. REFLECTION MODELS Basic Interface Reflectance BRDF>BTDF Adapter Specular Reflection and Transmission Fresnel Reflectance Specular Reflection Specular Transmission Lambertian Reflection Microfacet Models Oren-Nayar Diffuse Reflection Torrance-Sparrow Model Blinn Microfacet Distribution Anisotropic Microfacet Model Lafortune Model Fresnel Incidence Effects Further Reading Exercises CHAPTER 10. MATERIALS BSDFs BSDF Memory Management Material Interface and Implementations Matte Plastic Additional Materials Bump Mapping Further Reading Exercises CHAPTER 11. TEXTURE Sampling and Antialiasing Finding the Texture Sampling Rate Filtering Texture Functions Ray Differentials for Specular Reflection and Transmission † Texture Coordinate Generation 2D (u, v) Mapping Spherical Mapping Cylindrical Mapping Planar Mapping 3DMapping Texture Interface and Basic Textures Constant Texture Scale Texture Mix Textures Bilinear Interpolation Image Texture Texture Caching MIPMaps Isotropic Triangle Filter Elliptically Weighted Average Solid and Procedural Texturing UV Texture Checkerboard Solid Checkerboard Noise Perlin Noise Random Polka Dots Noise Idioms and Spectral Synthesis Bumpy and Wrinkled Textures Windy Waves Marble Further Reading Exercises CHAPTER 12. VOLUME SCATTERING † Volume Scattering Processes Absorption Emission Out-Scattering and Extinction In-scattering Phase Functions Volume Interface and Homogeneous Media Homogeneous Volumes Varying-Density Volumes 3D Grids Exponential Density Volume Aggregates Further Reading Exercises CHAPTER 13. LIGHT SOURCES Light Interface Visibility Testing Point Lights Spotlights Texture Projection Lights Goniophotometric Diagram Lights Distant Lights Area Lights Infinite Area Lights Further Reading Exercises CHAPTER 14. MONTE CARLO INTEGRATION I: BASIC CONCEPTS Background and Probability Review Continuous Random Variables Expected Values and Variance The Monte Carlo Estimator Sampling Random Variables The Inversion Method Example: Power Distribution Example: Exponential Distribution Example: Piecewise-Constant 1D Functions The Rejection Method Example: Rejection Sampling a Unit Circle Transforming between Distributions Transformation in Multiple Dimensions Example: Polar Coordinates Example: Spherical Coordinates 2D Sampling with Multidimensional Transformations Example: Uniformly Sampling a Hemisphere Example: Sampling a Unit Disk Example: Cosine-Weighted Hemisphere Sampling Example: Sampling a Triangle Further Reading Exercises CHAPTER 15. MONTE CARLO INTEGRATION II: IMPROVING EFFICIENCY Russian Roulette and Splitting Splitting Careful Sample Placement Stratified Sampling Quasi Monte Carlo Warping Samples and Distortion Bias Importance Sampling Multiple Importance Sampling Sampling Reflection Functions Sampling the Blinn Microfacet Distribution Sampling the Anisotropic Microfacet Model Sampling FresnelBlend Specular Reflection and Transmission Application: Estimating Reflectance Sampling BSDFs Sampling Light Sources Basic Interface Lights with Singularities Area Lights ShapeSet Sampling Infinite Area Lights Volume Scattering † Sampling Phase Functions Computing Optical Thickness Further Reading Exercises CHAPTER 16. LIGHT TRANSPORT I: SURFACE REFLECTION Direct Lighting Estimating the Direct Lighting Integral The Light Transport Equation Basic Derivation Analytic Solutions to the LTE The Surface Form of the LTE Integral over Paths Delta Distributions in the Integrand Partitioning the Integrand The Measurement Equation and Importance Path Tracing Overview Path Sampling Incremental Path Construction Implementation Bidirectional Path Tracing † Irradiance Caching Particle Tracing and Photon Mapping Theoretical Basis for Particle Tracing † Photon Integrator Building the Photon Maps Using the Photon Map Photon Interpolation and Density Estimation Further Reading Exercises CHAPTER 17. LIGHT TRANSPORT II: VOLUME RENDERING † The Equation of Transfer Volume Integrator Interface Emission-Only Integrator Single Scattering Integrator Further Reading Exercises CHAPTER 18. SUMMARY AND CONCLUSION Design Retrospective Abstraction versus Efficiency Design Alternatives: Triangles Only Design Alternatives: Streaming Computation Major Projects Parallel Rendering Increased Scene Complexity Subsurface Scattering Precomputation for Interactive Rendering Conclusion APPENDIXES Utilities Scene Description Interface Input File Format Index of Fragments Index of Classes and their Members Index of Identifiers REFERENCES INDEX ABOUT THE CD-ROM

8,325

社区成员

发帖
与我相关
我的任务
社区描述
游戏开发相关内容讨论专区
社区管理员
  • 游戏开发
  • 呆呆敲代码的小Y
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧