我打算开发一个应用程序来从文件中获取图像并用Directx9
. 我已经使用了这段代码,但我在SetBackBuffer
方法上遇到了错误!!
System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
private void d3dImage_IsFrontBufferAvailableChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (d3dImage.IsFrontBufferAvailable)
{
// (Re)initialization:
Bitmap b = new Bitmap(@"C:\Users\newuser\Desktop\3.jpg");
IntPtr Mysurface = b.GetHbitmap();
if (Mysurface != IntPtr.Zero)
{
d3dImage.Lock();
//Error occurred this line
d3dImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, Mysurface);
d3dImage.Unlock();
CompositionTarget.Rendering += CompositionTarget_Rendering;
}
}
else
{
// Cleanup:
CompositionTarget.Rendering -= CompositionTarget_Rendering;
//Sample.Cleanup();
}
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e); …
Run Code Online (Sandbox Code Playgroud) 我有一个 C++ 函数,它将 LPSTR 类型变量拆分为一个字符数组 (char*) 示例:
this->XMeshTexturePath = FindTexturePath(XMeshTexturePath,d3dxMaterials[i].pTextureFilename);
//the value of XMeshTexturePath is: Models\\Textures\\
//the value of d3dxMaterials[i].pTextureFilename is: BlaBlaBla\\BlaBla\\Cyrex.x
//The Result(XMeshTexturePath) should be like this:"Models\\Textures\\Cyrex.x"
Run Code Online (Sandbox Code Playgroud)
这是我正在尝试编写的功能:
int FindTextLength(char* Text){
int length
Run Code Online (Sandbox Code Playgroud)
h=0; for(int i=0;i
char* FindTexturePath( char* TexturePath ,LPSTR FileNameToCombine){
int FileLength=0;
int PathAndFileLength=0;
char *FileName = new char;
char *TexPathAndName = new char;
strcpy(TexPathAndName, FileNameToCombine);
PathAndFileLength = FindTextLength(TexPathAndName);
for(int i=0; i<PathAndFileLength; i++){
if( TexPathAndName[i] != NULL){
if(TexPathAndName[i] != '\\'){
FileName[FileLength] = TexPathAndName[i];
FileLength++;
}
else
FileLength …
Run Code Online (Sandbox Code Playgroud) 我发现很难找到很好的信息来源来解释 DirectX API,尽管我已经查看了一段时间的 DirectX 文档。
我正在尝试为 DX9 的包装类创建一个方法,该方法在运行时更改分辨率。我已经设法用 DirectDraw 处理了这个问题,但我没有找到关于 DX9 的信息,尽管它应该更常见。
我发现的只是对 SetDisplayMode 的引用,但是我的 Direct Object 或 DirectX Device 都没有这个方法。
我正在使用 DirectX 9。
示例方法:
void SetResolution(int width, int height, int depth)
{
// I have access to DirectX device, object and the window HWND in this class
};
Run Code Online (Sandbox Code Playgroud)
...我是更改 HWND 窗口大小,还是在 DirectX 中处理此问题?我知道如何在 Windows 应用程序中更改分辨率,但不知道如何在 DX9 中执行此操作。
在我阅读上面的文章之后,我仍然不确定宏是否只是一个函数或其他任何东西.宏是否等于功能?
例:
// Create a Direct3D 9 device.
hr = direct3D9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dPP, &d3dDevice);
// Cout out the message to indicate the failure.
if(FAILED(hr))
return 0;
Run Code Online (Sandbox Code Playgroud) 我正在使用DirectX9进行一个简单的项目。我对数据类型的转换有些迷惑,并且已经做过一些研究,但是还没有发现任何特别有用的东西。让我们从代码开始:
LPDIRECT3DSURFACE9 LoadSurface(char *fileName, D3DCOLOR transColor)
{
LPDIRECT3DSURFACE9 image = NULL;
D3DXIMAGE_INFO info;
HRESULT result;
result = D3DXGetImageInfoFromFile(fileName, &info);
if (result != D3D_OK) return NULL;
result = d3ddev->CreateOffscreenPlainSurface(
info.Width, //width of the surface
info.Height, //height of the surface
D3DFMT_X8R8G8B8, //surface format
D3DPOOL_DEFAULT, //memory pool use
&image, //reference to image
NULL); //reserved - ALWAYS NULL
//make sure file loaded properly
if (result != D3D_OK) return NULL;
return image;
}
Run Code Online (Sandbox Code Playgroud)
在第6行,我得到了变量fileName的错误:
IntelliSense:“ char *”类型的参数与“ LPCWSTR”类型的参数不兼容
当尝试使用MessageBox时,我在第二个和第三个参数上也得到了完全相同的错误消息:
if (d3ddev == NULL)
{
MessageBox(hWnd, …
Run Code Online (Sandbox Code Playgroud)