- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在学习 DirectX,我想将调色板绑定(bind)到 PrimarySurface,但过程总是失败。我在下面给出我的代码:
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 32
#define MAX_COLORS_PALETTE 256
#define DDRAW_INIT_STRUCT(ddstruct) { memset(&ddstruct, 0, sizeof(ddstruct)); ddstruct.dwSize = sizeof(ddstruct); }
LPDIRECTDRAW7 lpdd = NULL;
LPDIRECTDRAWSURFACE7 lpddPrimarySurface = NULL;
LPDIRECTDRAWPALETTE lpddPalette = NULL;
PALETTEENTRY palette[256];
// Omit the unneccessary content
int GameInit()
{
if (FAILED(DirectDrawCreateEx(NULL, (void**)&lpdd, IID_IDirectDraw7, NULL)))
return 0;
if (FAILED(lpdd->SetCooperativeLevel(g_GameHwnd, DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
return 0;
if (FAILED(lpdd->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, 0, 0)))
return 0;
DDRAW_INIT_STRUCT(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.dwBackBufferCount = 1;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
if (FAILED(lpdd->CreateSurface(&ddsd, &lpddPrimarySurface, NULL)))
return 0;
ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
if (FAILED(lpddPrimarySurface->GetAttachedSurface(&ddsd.ddsCaps, &lpddBackSurface)))
return 0;
memset(palette, 0, MAX_COLORS_PALETTE * sizeof(PALETTEENTRY));
for (int index = 0; index < MAX_COLORS_PALETTE; index++)
{
if (index < 64)
palette[index].peRed = index * 4;
else if (index >= 64 && index < 128)
palette[index].peGreen = (index - 64) * 4;
else if (index >= 128 && index < 192)
palette[index].peBlue = (index - 128) * 4;
else if (index >= 192 && index < 256)
palette[index].peRed = palette[index].peGreen = palette[index].peBlue = (index - 192) * 4;
palette[index].peFlags = PC_NOCOLLAPSE;
}
if (FAILED(lpdd->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 | DDPCAPS_INITIALIZE, palette, &lpddPalette, NULL)))
return 0;
**// I always failed to set palette to primary surface here....**
if (FAILED(lpddPrimarySurface->SetPalette(lpddPalette)))
{
MessageBox(NULL, "Failed", NULL, MB_OK);
return 0;
}
DDRAW_INIT_STRUCT(ddsd);
if (FAILED(lpddBackSurface->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL)))
return 0;
UINT *videoBuffer = (UINT*)ddsd.lpSurface;
for (int y = 0; y < SCREEN_HEIGHT; y++)
{
memset((void*)videoBuffer, y % 256, SCREEN_WIDTH * sizeof(UINT));
videoBuffer += ddsd.lPitch >> 2;
}
if (FAILED(lpddBackSurface->Unlock(NULL)))
return 0;
return 1;
}
不知道为什么总是SetPalette到primary surface失败。我设置DisplayMode为640*480*32,我的调色板只有256色,是这个原因吗?但是我查阅了MSDN,CreatePalette只能创建2Bit、4Bit、8Bit的调色板。 32 位显示模式可以与 8 位调色板兼容吗?问题出在哪里?
如果有人能给我一些建议,我将不胜感激。谢谢。
最佳答案
任何大于 8 位模式(16、24、32)的都是直接颜色模式,帧缓冲区中的数据是实际颜色,因此没有像 8 位索引颜色模式那样的调色板.
要使您的示例按原样工作,请将 SCREEN_BPP
更改为 8。问题是在现代版本的 Windows 中,您可能会发现您的调色板不固定,它会被设置回系统调色板。此处列出了一些您可以尝试的解决方法:"Exclusive" DirectDraw palette isn't actually exclusive
如果您想使用 32 位模式,则没有调色板,您必须直接设置颜色,而不是使用调色板中的索引。在您的示例中,您可以执行类似的操作以将调色板颜色复制到帧缓冲区中:
if (FAILED(lpddBackSurface->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL)))
return 0;
UINT *videoBuffer = (UINT*)ddsd.lpSurface;
for (int y = 0; y < SCREEN_HEIGHT; y++)
{
const PALETTEENTRY& p = palette[y%256];
UINT color = (p.peRed << 16) | (p.peGreen << 8) | p.peBlue;
for(int x = 0; x < SCREEN_WIDTH; ++x)
{
videoBuffer[x] = color;
}
videoBuffer += ddsd.lPitch / sizeof(UINT);
}
if (FAILED(lpddBackSurface->Unlock(NULL)))
return 0;
关于c++ - DirectX7 SetPalette 总是失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18619107/
我想用groupshared DirectX 计算着色器中的内存以减少全局内存带宽并有望提高性能。我的输入数据是 Texture2D我可以像这样使用二维索引来访问它: Input[threadID.x
我一直在查看 MSDN 和 Microsoft.com,但只能找到存档论坛。现在还有 Microsoft Run DirectX 论坛吗? 最佳答案 在这里: http://forums.xna.co
我正在尝试将网格切成两半,或者至少能够实时删除其中的面。我想知道如何去做这件事? 锁定顶点缓冲区,将选定的面或顶点 memset 为 0,对我不起作用。有没有人对此有解决方案或教程,我真的希望在我的程
我想这是一个相当深入的主题,因此任何带有洞察信息的网址也很乐意接受。我一直在使用原生 DirectX,但从未管理过。另一方面,大多数情况下,在开发不需要高级 GPU 渲染的其他类型的应用程序时,我通常
微软的开源DirectX Shader Compiler描述了一种用于 HLSL 着色器的新中间语言 (IL) 的格式,称为 DXIL。 文档引用了从以前的 HLSL IL(称为 DXBC)到新 DX
我需要同时在更大的显示器上全屏显示在我的应用程序中播放的视频。在某些显卡上,这称为影院模式,使用显卡制造商提供的工具进行配置。 我只想用软件来做到这一点。我可以用 DirectX 做到这一点吗? 我的
我问 how to take the screen shot in DirectX并回答了“使用 GetFrontBufferData()”。然而,“这个函数在设计上非常慢,并且不应该在任何性能关键路
这让我感到困惑。 DirectX 绕过所有内容并直接与设备驱动程序对话,因此 GDI 和其他常用方法将不起作用 - 除非 Aero 被禁用(或不可用),否则出现的只是屏幕左上角的黑色矩形。我已经尝试了
我们正在开发一个通过 Direct3D 可视化显示信息的应用程序。迟到的客户端请求是能够通过某些远程桌面解决方案查看此应用程序。 有人做过类似的事情吗?哪些选项可用/不可用?我正在考虑 RDC、VNC
由于D3DPOOL_SCRATCH处理速度较慢,所以我编写了桌面捕获程序以引用网上的报告。然而,结果却是一片漆黑的画面。这是控制台程序的结果还是有其他原因? #include #include #
背景 我正在玩东方系列游戏之一的不朽之夜。射击按钮是“z”,移动较慢是“shift”,方向键移动。对我来说不幸的是,使用 shift-z 重影我的右箭头键,所以我在射击时无法向右移动。这种重影发生在所
我已经阅读了关于 DirectX 光栅化规则的在线文档,但我仍然不明白为什么这段代码没有在屏幕上产生任何可见的东西? target->SetAntialiasMode(D2D1_ANTIALIAS_M
如您所知,当我们想要在 DirectX 中绘制三维对象时,我们应该定义相机。现在我们有一个设备对象,它的名称是“device1”。这是我的问题: device1.View = Matrix.Look.
我正在使用桌面复制 API 从一个 GPU 捕获桌面,并且需要将纹理(位于 GPU 内存中)复制到另一个 GPU。为此,我有一个捕获线程,用于获取桌面图像,然后使用 ID3D11DeviceConte
假设 DX12 被挂接到叠加渲染的场景,看起来挂接的最佳函数是 IDXGISwapChain::Present,与 DX11 的方式相同。将此函数 Hook 后,交换链就可用,并且可以从中检索设备以创
当帧开始时,我会进行逻辑更新并在此之后进行渲染。 在我的渲染代码中,我做通常的事情。我设置了一些状态、缓冲区、纹理,并通过调用 Draw 来结束。 m_deviceContext->Draw(
我使用 DirectX 9.0 制作了一个小型 3D 查看器应用程序。现在我想添加一些编辑功能。假设我想编辑一个大多边形。当用户编辑形状时,顶点将被添加、删除和移动。现在每个多边形都存储为顶点缓冲区。
我编写了一个应用程序,它可以在 OpenGL、DirectX 9 和 DirectX 11 之间切换以进行渲染,而无需重新启动或重新创建窗口。在 OpenGL 和 DirectX 9 以及 Direc
如何在 DirectX 中执行此操作? glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); 不知何故,我似乎无
msdn documentation解释了在 directx 11 中,有多种方法可以通过编程方式填充 directx 11 纹理: (1) 使用默认使用纹理创建纹理并使用内存中的数据对其进行初始化
我是一名优秀的程序员,十分优秀!