linux图形编程之SDL

这篇博客介绍了如何在Ubuntu 15.04上安装和使用SDL库进行图形编程,包括SDL的基础用法、SDL_ttf的安装及应用,以及SDL_draw库的简单示例,展示了从创建红色屏幕到加载图片再到绘制正弦曲线的过程。
摘要由CSDN通过智能技术生成

SDL start

SDL是编写跨平台游戏和多媒体应用的支持库,包含了对图形、声音、游戏杆、线程等支持,内容丰富、应用广泛。
ubuntu15.04上安装SDL:
Source Code在 http://www.libsdl.org/download-1.2.php上,下载SDL-1.2.15.tar.gz。解压tar -zxvf SDL-1.2.15.tar.gz,在加压后的文件夹SDL-1.2.15中使用root账户进行安装三部曲./configure; make; make install
安装完成后根据安装过程中出现log我们可以知道Libraries在/usr/local/lib,而编码所需要的文件SDL.h在/usr/local/include/SDL中,这依靠find命令可以查找到。在INSTALL文件中可以发现更多的东西:

Look at the example programs in ./test, and check out the HTML
        documentation in ./docs to see how to use the SDL library.

我们可以将/usr/local/lib中的库文件放到/usr/lib中,将/usr/local/include/SDL中的头文件放到/usr/include中,然后gcc就能找到了。
对于写好的程序,如果直接编译gcc -o sdl1 sdl1.c,那会出现错误:

/tmp/ccEE9bhU.o: In function `main':
sdl1.c:(.text+0x17): undefined reference to `SDL_Init'
sdl1.c:(.text+0x23): undefined reference to `SDL_GetError'
sdl1.c:(.text+0x59): undefined reference to `SDL_SetVideoMode'
sdl1.c:(.text+0x6a): undefined reference to `SDL_GetError'
sdl1.c:(.text+0x95): undefined reference to `SDL_Quit'
sdl1.c:(.text+0xc3): undefined reference to `SDL_MapRGB'
sdl1.c:(.text+0xd9): undefined reference to `SDL_FillRect'
sdl1.c:(.text+0xef): undefined reference to `SDL_UpdateRect'
sdl1.c:(.text+0x10c): undefined reference to `SDL_Delay'
collect2: error: ld returned 1 exit status

在命令的最后加上连接选项-lSDL,如:gcc -o sdl1 sdl1.c -lSDL
例子:创建一个红色屏幕,并停留5秒。

#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>

int main(){
    SDL_Surface *screen;
    unsigned int
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值