Skip to content

Simple DirectMedia Layer

List of SDL API

심플 다이렉트미디어 레이어(Simple DirectMedia Layer), SDL는 C 프로그래밍 언어로 짜여진 크로스플랫폼 멀티미디어 라이브러리이다. 이 라이브러리는 비디오, 오디오, 사용자 입력 등의 계층을 추상화하여, 리눅스, 마이크로소프트 윈도, 맥 OS X 등 여러 운영 체제에서 실행이 가능하도록 한다. 이 라이브러리는 비디오, 이벤트, 디지털 오디오, CD-ROM, 사운드, 스레드, 공유 객체 불러오기, 네트워킹, 타이머를 관리한다.

SDL 2.0 API by Category

Basics

Video

Input Events

Force Feedback

  • Initialization and Shutdown
    • SDL_Init
    • SDL_InitSubSystem
    • SDL_Quit
    • SDL_QuitSubSystem
  • Configuration Variables
    • SDL_GetHint
    • SDL_SetHint
    • SDL_SetHintWithPriority
  • Error Handling
    • SDL_ClearError
    • SDL_GetError
    • SDL_SetError
  • Log Handling
    • SDL_Log
    • SDL_LogCritical
    • SDL_LogDebug
    • SDL_LogError
    • SDL_LogInfo
    • SDL_LogMessage
    • SDL_LogVerbose
    • SDL_LogWarn
  • Assertions
    • SDL_assert
  • Querying SDL Version
    • SDL_GetVersion
  • Display and Window Management
    • SDL_CreateWindow
    • SDL_DestroyWindow
    • SDL_GetWindowPixelFormat
    • SDL_GetWindowPosition
    • SDL_GetWindowSize
  • 2D Accelerated Rendering
    • SDL_CreateRenderer
    • SDL_CreateSoftwareRenderer
    • SDL_CreateTexture
    • SDL_LockTexture
    • SDL_RenderClear
    • SDL_RenderCopy
    • SDL_RenderCopyEx
    • SDL_RenderDrawLine
    • SDL_RenderDrawLines
    • SDL_RenderDrawPoint
    • SDL_RenderDrawPoints
    • SDL_RenderDrawRect
    • SDL_RenderDrawRects
    • SDL_RenderFillRect
    • SDL_RenderFillRects
    • SDL_SetRenderDrawBlendMode
    • SDL_SetRenderDrawColor
    • SDL_SetRenderTarget
    • SDL_SetTextureAlphaMod
    • SDL_SetTextureBlendMode
    • SDL_SetTextureColorMod
    • SDL_UnlockTexture
    • SDL_UpdateTexture
    • SDL_UpdateYUVTexture
  • Pixel Formats and Conversion Routines
  • Rectangle Functions
  • Surface Creation and Simple Drawing
  • Platform-specific Window Management
  • Clipboard Handling
  • Force Feedback Support

Audio

Threads

Timers

File Abstraction

  • Audio Device Management,
    Playing and Recording
  • Thread Management
  • Thread Synchronization Primitives
  • Atomic Operations
  • Thread Issue
  • Timer Support
  • Filesystem Paths
  • File I/O Abstraction

Shared Object Support

Platform and CPU Information

Power Management

Additional

  • Shared Object Loading
    and Function Lookup
  • Platform Detection
  • CPU Feature Detection
  • Byte Order and Byte Swapping
  • Bit Manipulation
  • Power Management Status
  • Platform-specific functionality
  • Other

SDL_image

SDL_ttf

SDL_mixer

OpenGL

Structure

Libraries

SDL3

Local Download

SDL2 2.0.4
SDL2-2.0.4.tar.gz

Troubleshooting

main() LINKER ERROR

아래와 같은 에러 메시지가 출력될 수 있다.

xxx error LNK2019: _WinMain@16 외부 기호(_WinMainCRTStartup 함수에서 참조)를 확인하지 못했습니다. 
xxx fatal error LNK1120: 1개의 확인할 수 없는 외부 참조입니다. 

SDL에서 mainWinMain으로 Define하여 발생되는 에러이다. SDL.lib, SDLmain.lib 을 링크하면 된다.

MinGW에서 사용할 경우 아래와 같이 사용하면 된다.

$ g++ -std=c++11 main.cpp -lmingw32 -lSDL2main -lSDL2 -lopengl32

implicit entry/start for main executable

clang에서 SDL을 사용할 경우 아래와 같은 에러 메시지가 출력될 수 있다.

Undefined symbols for architecture x86_64:
  "_main", referenced from:
    implicit entry/start for main executable.
    maybe you meant: _SDL_main
ld: symbol(s) not found for architecture x86_64

이 경우, main이 매크로로 등록되어 나타나는 현상이다. 아래와 같이 매크로 등록을 해제한다.

#ifdef main
#undef main
#endif

Renderer already associated with window

SDL_GetError()를 통하여 아래와 같은 에러 메시지를 확인할 수 있다.

Renderer already associated with window

이 경우, 이미 해당 Window에서 Renderer를 생성했다는 의미이다. 이미 생성된 Renderer를 찾아봐야 한다.

MSYS DirectX Symbol error

./configure
make
make install

MSYS에서 위와같이 설치할 경우 DirectX 관련 심볼(__in 등)을 찾을 수 없을 경우가 있다. 이 경우 DirectX를 정상적으로 설치해야 한다.

OpenGL.error.Error: Attempt to retrieve context when no valid context

Ubuntu 20.04 이상에서 Wayland 로 실행된다면 다음과 같은 에러가 출력될 수 있다:

pygame-ce 2.4.1 (SDL 2.28.5, Python 3.11.4)
/home/yourname/Project/ddrm/test.py:13: Warning: PyGame seems to be running through X11 on top of wayland, instead of wayland directly
...
OpenGL.error.Error: Attempt to retrieve context when no valid context

간단히, SDL_VIDEO_X11_FORCE_EGL=1 환경변수 설정하면 된다.

See also

Favorite site

SDL Wiki

Tutorial

Guide

Guide: Initialize

References


  1. Lazyfoo.net.140828.backup.7z 

  2. Inside_linux-happy_hacking-maso200109-use_sdl_library_02.pdf 

  3. CODEpendent-wx-sdl_tutorial_part_1.pdf 

  4. Demonstration_of_SDL2+FFmpeg_player_based_on.pdf