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.
- ctype.h(<cctype>) library in C/C++ with Examples
- <iterator> library in C++ STL
- <algorithms> library in C++ STL
- snprintf() in C library
- <strings> library in C++ STL
- <regex> library in C++ STL
- <numeric> library in C++ STL
- wcstof function in C library
- C Library math.h functions
- wprintf() and wscanf in C Library
- isgraph() C library function
- difftime() C library function
- Any datatype in C++ boost library
- Pattern Searching using C++ library
- Advanced C++ with boost 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 email@example.com. 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.