Skip to content

Instantly share code, notes, and snippets.

@Zerophase
Created January 5, 2020 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zerophase/81d6ac5d3801e5ec7820e27c8b32c390 to your computer and use it in GitHub Desktop.
Save Zerophase/81d6ac5d3801e5ec7820e27c8b32c390 to your computer and use it in GitHub Desktop.
SDL2 Unreal start up sample code.
#include <iostream>
#include <SDL.h>
int main()
{
// uint32_t windowStyleSDL = SDL_WINDOW_VULKAN;
SDL_SetHint("SDL_VIDEO_X11_REQUIRE_XRANDR", "1"); // workaround for misbuilt SDL libraries on X11.
// SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_SHOW_CURSOR, "1"); // When relative mouse mode is acive, don't hide cursor.
SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "0"); // Don't warp the cursor to the center in relative mouse mode.
if (SDL_Init((SDL_INIT_EVERYTHING ^ SDL_INIT_AUDIO) | SDL_INIT_NOPARACHUTE) != 0)
std::cout << "SDL could not be inited.\n";
SDL_version CompileTimeSDLVersion;
SDL_version RunTimeSDLVersion;
SDL_VERSION(&CompileTimeSDLVersion);
SDL_GetVersion(&RunTimeSDLVersion);
int SdlRevisionNum = SDL_GetRevisionNumber();
const char *SdlRevision = SDL_GetRevision();
std::cout << "Init SDL version: " << (unsigned int)RunTimeSDLVersion.major << "."
<< (unsigned int)RunTimeSDLVersion.minor << "." << (unsigned int)RunTimeSDLVersion.patch
<< " revision: " << SdlRevisionNum << " (" << SdlRevision << ") (compiled against: " << (unsigned int)CompileTimeSDLVersion.major
<< "." << (unsigned int)CompileTimeSDLVersion.minor << "."
<< (unsigned int)CompileTimeSDLVersion.patch << ")\n";
const char *SdlVideoDriver = SDL_GetCurrentVideoDriver();
if (SdlVideoDriver)
std::cout << "Using SDL video driver: " << SdlVideoDriver << "\n";
SDL_StartTextInput();
const char *title = "Title";
const char *message = "message";
SDL_MessageBoxButtonData *buttons = new SDL_MessageBoxButtonData[2];
buttons[0].flags = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
buttons[0].text = "Yes";
buttons[0].buttonid = 1;
buttons[1].flags = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
buttons[1].text = "No";
buttons[1].buttonid = 0;
SDL_MessageBoxData messageBoxData =
{
SDL_MESSAGEBOX_INFORMATION,
NULL,
title,
message,
2,
buttons,
NULL
};
int buttonPressed = -1;
if (SDL_ShowMessageBox(&messageBoxData, &buttonPressed) == -1)
std::cout << "Messagebox could not be shown\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment