#include <SDL.h>
#include <windows.h>
#include <iostream>
#include <d3d11.h>
#include <dxgi1_2.h>
#include <wrl/client.h>
#include <stdbool.h>
#include <stdlib.h>
#include <SDL_test.h>
#include <string.h>
#include "Overlay.h"
#include <imgui.h>
using namespace Microsoft::WRL;
//#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
HRESULT STDMETHODCALLTYPE ReleaseFrame();
// Assume that the necessary structures and types are declared appropriately.
HRESULT STDMETHODCALLTYPE AcquireNextFrame(
/* [annotation][in] */
_In_ UINT TimeoutInMilliseconds,
/* [annotation][out] */
_Out_ DXGI_OUTDUPL_FRAME_INFO* pFrameInfo,
/* [annotation][out] */
_COM_Outptr_ IDXGIResource** ppDesktopResource);
void 渲染主窗口()
{
ImGui::Begin("主窗口");
// 主窗口的内容在这里...
// 嵌套另一个窗口
if (ImGui::Begin("嵌套窗口"))
{
// 嵌套窗口的内容在这里...
ImGui::Text("来自嵌套窗口的问候!");
ImGui::End();
}
ImGui::End();
}
int main() {
// 初始化SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
std::cerr << "SDL initialization failed: " << SDL_GetError() << std::endl;
return 1;
}
// 创建窗口
SDL_Window* window = SDL_CreateWindow(
"SDL Window",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
800, 600,
SDL_WINDOW_SHOWN
);
if (!window) {
std::cerr << "Failed to create SDL window: " << SDL_GetError() << std::endl;
SDL_Quit();
return 1;
}
// 创建渲染器
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (!renderer) {
std::cerr << "Failed to create SDL renderer: " << SDL_GetError() << std::endl;
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
// 初始化Dear ImGui
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
(void)io;
// 配置Dear ImGui的SDL实现
ImGui_ImplSDL2_InitForD3D(window);
ImGui_ImplSDL2_InitForOpenGL(window, nullptr);
SDL_Rect rect_ = { 0,0,0,0 };
// 配置Dear ImGui的SDL实现
ImGui_ImplSDL2_InitForD3D(window);
ImGui_ImplSDL2_InitForOpenGL(window, nullptr);
int x, y;
SDL_GetWindowPosition(window, &x, &y);
rect_.x = x;
rect_.y = y;
std::cout << "Window position: (" << x << ", " << y << ")" << std::endl;
// 获取窗口大小
int width, height;
SDL_GetWindowSize(window, &width, &height);
rect_.w = width;
rect_.h = height;
std::cout << "Window size: " << width << " x " << height << std::endl;
// 获取键盘输入
SDL_Event event;
bool quit = false;
while (!quit) {
while (SDL_PollEvent(&event) != 0) {
if (event.type == SDL_QUIT) {
quit = true;
}
else if (event.type == SDL_KEYDOWN) {
std::cout << "Key pressed: " << SDL_GetKeyName(event.key.keysym.sym) << std::endl;
}
else if (event.type == SDL_MOUSEBUTTONDOWN) {
std::cout << "Mouse button pressed at (" << event.button.x << ", " << event.button.y << ")" << std::endl;
}
ImGui_ImplSDL2_ProcessEvent(&event);
}
渲染主窗口();
ImGui::Render();
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// 渲染窗口
SDL_RenderClear(renderer);
// 在这里添加你的渲染代码
SDL_RenderPresent(renderer);
}
// 获取音频设备信息
int audioDeviceCount = SDL_GetNumAudioDevices(SDL_FALSE);
std::cout << "Number of audio devices: " << audioDeviceCount << std::endl;
for (int i = 0; i < audioDeviceCount; ++i) {
const char* audioDeviceName = SDL_GetAudioDeviceName(i, SDL_FALSE);
std::cout << "Audio device " << i << ": " << audioDeviceName << std::endl;
}
// 清理SDL资源
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
以上代码编译出来的窗口闪退,求大佬指点