Reputation: 61
I am having a problem with bgfx graphics framework. This problem causes nothing to be rendered, and the background isn't being set to the correct color.
#include <bgfx/bgfx.h>
#include <bgfx/platform.h>
#include <GLFW/glfw3.h>
#define GLFW_EXPOSE_NATIVE_WIN32
#include <GLFW/glfw3native.h>
const int width = 800;
const int height = 600;
int main()
{
glfwInit();
GLFWwindow* window = glfwCreateWindow(width, height, "Hello, bgfx!", NULL, NULL);
bgfx::PlatformData pd;
pd.nwh = glfwGetWin32Window(window);
bgfx::setPlatformData(pd);
bgfx::Init bgfxInit;
bgfxInit.type = bgfx::RendererType::Count;
bgfxInit.resolution.width = width;
bgfxInit.resolution.height = height;
bgfxInit.resolution.reset = BGFX_RESET_VSYNC;
bgfx::init(bgfxInit);
bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x443355FF, 1.0f, 0);
bgfx::setViewRect(0, 0, 0, width, height);
// Main loop
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();
// Submit empty draw call
bgfx::touch(0);
// Render frame
bgfx::frame();
}
// Cleanup
bgfx::shutdown();
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
Upvotes: 1
Views: 377
Reputation: 61
I found the answer, if you are struggling with this. Instead of defining the platform data object, then doing bgfx::setPlatformData
, set it inside of the init object.
Instead of:
bgfx::PlatformData pd;
pd.nwh = glfwGetWin32Window(window);
bgfx::setPlatformData(pd);
Do:
bgfx::Init bgfxInit;
bgfxInit.platformData.nwh = glfwGetWin32Window(window);
bgfxInit.type = bgfx::RendererType::Direct3D12;
bgfxInit.resolution.width = width;
bgfxInit.resolution.height = height;
bgfxInit.resolution.reset = BGFX_RESET_VSYNC;
bgfx::init(bgfxInit);
Upvotes: 3