SDL is Simple DirectMedia Layer.It is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D.It can be used to make animations and video games.
- It basically provides a set of APIs to interact with various devices like graphics hardware, audio, keyboard, mouse, etc.
- It is written in C programming language and works with C++ and various other languages like c# and python.
Installation on Linux:
- Run command sudo apt-get update on your terminal.
- Run command sudo apt-get install clang on your terminal.
- Run command sudo apt-get install libsdl2-2.0-0 libsdl2-dbg libsdl2-dev libsdl2-image-2.0-0 libsdl2-image-dbg libsdl2-image-dev on your terminal.
we need to make a Makefile.So open a text editor of your choice and start writing the code below.
# A simple Makefile for compiling small SDL projects # set the compiler CC := clang # set the compiler flags CFLAGS := `sdl2-config --libs --cflags` -ggdb3 -O0 --std=c99 -Wall -lSDL2_image -lm # add header files here HDRS := # add source files here SRCS := #file-name.c # generate names of object files OBJS := $(SRCS:.c=.o) # name of executable EXEC := #name your executable file # default recipe all: $(EXEC) showfont: showfont.c Makefile $(CC) -o $@ $@.c $(CFLAGS) $(LIBS) glfont: glfont.c Makefile $(CC) -o $@ $@.c $(CFLAGS) $(LIBS) # recipe for building the final executable $(EXEC): $(OBJS) $(HDRS) Makefile $(CC) -o $@ $(OBJS) $(CFLAGS) # recipe for building object files #$(OBJS): $(@:.o=.c) $(HDRS) Makefile # $(CC) -o $@ $(@:.o=.c) -c $(CFLAGS) # recipe to clean the workspace clean: rm -f $(EXEC) $(OBJS) .PHONY: all clean
That will create a empty window on your screen.
We will write a simple program to explain rendering and I/O handling:
That will render a image on the window which can be controlled via your keyboard up, down, left, right.
- <regex> library in C++ STL
- <algorithms> library in C++ STL
- <iterator> library in C++ STL
- <numeric> library in C++ STL
- <strings> library in C++ STL
- snprintf() in C library
- Map in C++ Standard Template Library (STL)
- C Library math.h functions
- wcstof function in C library
- Any datatype in C++ boost library
- Pattern Searching using C++ library
- difftime() C library function
- isgraph() C library function
- Advanced C++ with boost library
- boost::split in C++ library
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.