Anonymous
Ошибки сборки для SDL3 и ImGUI 1.9 (Visual Studio 2022)
Сообщение
Anonymous » 15 янв 2025, 02:54
Я только начал изучать C++ и SDL и пытаюсь добавить пользовательский интерфейс, но столкнулся с проблемой:
Моя программа не запускается/не создается exe-файл.
Я использую SDL3-3.1.6 и ImGui-1.91.7
GameLauncher.cpp
Код: Выделить всё
#include "GameLauncher.h"
int main(int argc, char* argv[]) {
init_Window("Drone Override", 1920, 1080);
return 0;
}
GameLauncher.h
Код: Выделить всё
#pragma once
#include
#include "gWindow.h"
using namespace std;
gWindow.cpp
Код: Выделить всё
#include "gWindow.h"
void init_Window(const char* title, int width, int height) {
SDL_Init(SDL_INIT_VIDEO);
// Create a window with OpenGL context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_Window* window = SDL_CreateWindow("Drone Override", width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY);
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, gl_context);
SDL_GL_SetSwapInterval(1); // Enable vsync
// Initialize Dear ImGui
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
ImGui::StyleColorsDark();
// Setup Platform/Renderer bindings
ImGui_ImplSDL3_InitForOpenGL(window, gl_context);
ImGui_ImplOpenGL3_Init("#version 330");
bool running = true;
SDL_Event event;
while (running) {
// Poll and handle events
while (SDL_PollEvent(&event)) {
if (event.type == SDL_EVENT_QUIT)
running = false;
ImGui_ImplSDL3_ProcessEvent(&event);
}
// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL3_NewFrame();
ImGui::NewFrame();
// Create ImGui UI
ImGui::Begin("Hello, Dear ImGui!");
ImGui::Text("This is a simple example.");
if (ImGui::Button("Exit"))
running = false;
ImGui::End();
// Rendering
ImGui::Render();
SDL_GL_MakeCurrent(window, gl_context);
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
SDL_GL_SwapWindow(window);
}
// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplSDL3_Shutdown();
ImGui::DestroyContext();
SDL_GL_DestroyContext(gl_context);
SDL_DestroyWindow(window);
SDL_Quit();
}
gWindow.h
Код: Выделить всё
#pragma once
#include
using namespace std;
// SDL3
#include "SDL3/SDL.h"
#include "SDL3/SDL_video.h"
#include "SDL3/SDL_opengl.h"
// ImGUI
#include "imgui.h"
#include "imgui_impl_sdl3.h"
#include "imgui_impl_opengl3.h"
void init_Window(const char* title, int width, int height);
C/C++ >>> Общие >>> Дополнительные каталоги включения:
path\imgui-1.91.7 \backends
path\imgui-1.91.7
path\SDL3-3.1.6\include
Компоновщик >>> Общие >>> Дополнительная библиотека Каталоги:
path\SDL3-3.1.6\lib\x64
Linker >>> Ввод >>> Дополнительные зависимости:
SDL3.lib
opengl32.lib
Подробнее здесь:
https://stackoverflow.com/questions/793 ... tudio-2022
1736898879
Anonymous
Я только начал изучать C++ и SDL и пытаюсь добавить пользовательский интерфейс, но столкнулся с проблемой: Моя программа не запускается/не создается exe-файл. Я использую SDL3-3.1.6 и ImGui-1.91.7 GameLauncher.cpp [code]#include "GameLauncher.h" int main(int argc, char* argv[]) { init_Window("Drone Override", 1920, 1080); return 0; } [/code] GameLauncher.h [code]#pragma once #include #include "gWindow.h" using namespace std; [/code] gWindow.cpp [code]#include "gWindow.h" void init_Window(const char* title, int width, int height) { SDL_Init(SDL_INIT_VIDEO); // Create a window with OpenGL context SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_Window* window = SDL_CreateWindow("Drone Override", width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY); SDL_GLContext gl_context = SDL_GL_CreateContext(window); SDL_GL_MakeCurrent(window, gl_context); SDL_GL_SetSwapInterval(1); // Enable vsync // Initialize Dear ImGui IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; ImGui::StyleColorsDark(); // Setup Platform/Renderer bindings ImGui_ImplSDL3_InitForOpenGL(window, gl_context); ImGui_ImplOpenGL3_Init("#version 330"); bool running = true; SDL_Event event; while (running) { // Poll and handle events while (SDL_PollEvent(&event)) { if (event.type == SDL_EVENT_QUIT) running = false; ImGui_ImplSDL3_ProcessEvent(&event); } // Start the Dear ImGui frame ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplSDL3_NewFrame(); ImGui::NewFrame(); // Create ImGui UI ImGui::Begin("Hello, Dear ImGui!"); ImGui::Text("This is a simple example."); if (ImGui::Button("Exit")) running = false; ImGui::End(); // Rendering ImGui::Render(); SDL_GL_MakeCurrent(window, gl_context); glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y); glClearColor(0.1f, 0.1f, 0.1f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); SDL_GL_SwapWindow(window); } // Cleanup ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplSDL3_Shutdown(); ImGui::DestroyContext(); SDL_GL_DestroyContext(gl_context); SDL_DestroyWindow(window); SDL_Quit(); } [/code] gWindow.h [code]#pragma once #include using namespace std; // SDL3 #include "SDL3/SDL.h" #include "SDL3/SDL_video.h" #include "SDL3/SDL_opengl.h" // ImGUI #include "imgui.h" #include "imgui_impl_sdl3.h" #include "imgui_impl_opengl3.h" void init_Window(const char* title, int width, int height); [/code] [b]C/C++ >>> Общие >>> Дополнительные каталоги включения:[/b] path\imgui-1.91.7 \backends path\imgui-1.91.7 path\SDL3-3.1.6\include [b]Компоновщик >>> Общие >>> Дополнительная библиотека Каталоги:[/b] path\SDL3-3.1.6\lib\x64 [b]Linker >>> Ввод >>> Дополнительные зависимости:[/b] SDL3.lib opengl32.lib Подробнее здесь: [url]https://stackoverflow.com/questions/79356702/build-errors-for-sdl3-and-imgui-1-9-visual-studio-2022[/url]