#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include <SDL.h>
#include "windows.h"
const int SCREEN_WIDTH = 640; //屏幕宽度
const int SCREEN_HEIGHT = 480; //屏幕高度
const int SCREEN_BPP = 32; //屏幕所使用的像素色彩位数
SDL_Surface *screen = NULL; //屏幕接口
boolean quit = false;
/* 导入位图*/
SDL_Surface *load_image( char *filename )
{
//将图象暂时存储在这里
SDL_Surface* loadedImage = NULL;
//存储最佳的图象
SDL_Surface* optimizedImage = NULL;
//导入图象
loadedImage = SDL_LoadBMP( filename );
//如果导入图象不为空
if( loadedImage != NULL )
{
//建立最佳的图象
optimizedImage = SDL_DisplayFormat( loadedImage );
//释放老的图象
SDL_FreeSurface( loadedImage );
}
//返回最佳的图象
return optimizedImage;
}
/*显示函数*/
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination )
{
//建立一个暂时的矩形设置显示的坐标
SDL_Rect offset;
//设置坐标
offset.x = x;
offset.y = y;
//显示图象
SDL_BlitSurface( source, NULL, destination, &offset );
}
int my_thread( void *data )
{
//While the program is not over
while( quit == false )
{
//Do the caption animation
SDL_WM_SetCaption( "Thread is running", NULL );
SDL_Delay( 250 );
SDL_WM_SetCaption( "Thread is running.", NULL );
SDL_Delay( 250 );
SDL_WM_SetCaption( "Thread is running..", NULL );
SDL_Delay( 250 );
SDL_WM_SetCaption( "Thread is running...", NULL );
SDL_Delay( 250 );
}
return 0;
}
int main( int argc, char* args[] ) //主程序
{
char msg[500]; // 得到系统消息
int done;
/* 初始化SDL */
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
sprintf (msg, "不能初始化 SDL: %sn", SDL_GetError ());
MessageBoxA(0, msg, "Error", MB_ICONHAND);
exit (1);
}
atexit(SDL_Quit);
/* 设置 640x480 16-bits 图象模式 */
screen = SDL_SetVideoMode (640, 480, 16, SDL_SWSURFACE | SDL_DOUBLEBUF);
if (screen == NULL)
{
sprintf(msg, "不能设置成 640x480x16 图象模式: %sn", SDL_GetError ());
MessageBoxA (0, msg, "Error", MB_ICONHAND);
exit (2);
}
/*设置SDL窗口标题 */
SDL_WM_SetCaption("hello,the world", NULL);
done = 0;
/*导入图象*/
SDL_Surface* demo = load_image("uhnfu32u.bmp");
done = 0;
/*在屏幕上画图*/
apply_surface(0,0,demo,screen);
//然后进入游戏循环,在循环的过程中,我们需要不停地更新屏幕:
//更新屏幕
if( SDL_Flip( screen ) == -1 )
{
return 1;
}
SDL_Thread* thread = SDL_CreateThread( my_thread, NULL );
//游戏循环 done=1时退出,done=0时继续
while (!done)
{
SDL_Event event;
/* Check for events */
while (SDL_PollEvent (&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
break;
case SDL_QUIT:
done = 1;
quit = true;
break;
default:
break;
}
}
}
//最后,图象显示完毕,我们要释放图象。
/*释放图象*/
SDL_FreeSurface(demo);
SDL_Quit();
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
sdl.rar_SDL sdk_doc_html SDL_sdl
共277个文件
html:204个
h:42个
lib:4个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 141 浏览量
2022-09-20
15:30:20
上传
评论
收藏 1.96MB RAR 举报
温馨提示
sdl的例子 包括sdk和doc 例子内容包括线程 图片显示等
资源推荐
资源详情
资源评论
收起资源包目录
sdl.rar_SDL sdk_doc_html SDL_sdl (277个子文件)
uhnfu32u.bmp 1.71MB
BUGS 507B
COPYING 24KB
main.cpp 3KB
SDL_config.h.default 1KB
mt.dep 67B
SDL.dll 314KB
SDL.dll 314KB
firstsdl.exe 40KB
rainbow.gif 2KB
SDL_opengl.h 328KB
SDL_video.h 36KB
SDL_stdinc.h 15KB
SDL_events.h 12KB
SDL_audio.h 11KB
SDL_keysym.h 7KB
SDL_syswm.h 6KB
SDL_mutex.h 6KB
SDL_cdrom.h 6KB
SDL_endian.h 6KB
SDL_joystick.h 5KB
SDL_rwops.h 5KB
SDL_mouse.h 5KB
SDL_config_win32.h 4KB
SDL_thread.h 4KB
SDL_timer.h 4KB
begin_code.h 4KB
SDL_keyboard.h 4KB
SDL_config_os2.h 4KB
SDL_config_macosx.h 3KB
SDL.h 3KB
SDL_config_symbian.h 3KB
SDL_config_nds.h 3KB
SDL_config_dreamcast.h 3KB
SDL_config_macos.h 3KB
SDL_loadso.h 3KB
SDL_main.h 3KB
SDL_version.h 2KB
SDL_platform.h 2KB
SDL_cpuinfo.h 2KB
SDL_config_amiga.h 2KB
SDL_config_minimal.h 2KB
SDL_quit.h 2KB
SDL_active.h 2KB
SDL_error.h 2KB
SDL_config.h 1KB
close_code.h 1KB
SDL_types.h 910B
SDL_getenv.h 910B
SDL_byteorder.h 910B
SDL_copying.h 869B
SDL_name.h 183B
BuildLog.htm 7KB
sdlkey.html 27KB
index.html 21KB
guideinputkeyboard.html 17KB
guidevideoopengl.html 16KB
guideinput.html 15KB
sdlenvvars.html 14KB
docs.html 14KB
sdlevent.html 13KB
video.html 11KB
sdlopenaudio.html 9KB
guidevideo.html 9KB
sdlpixelformat.html 8KB
sdlsetvideomode.html 8KB
sdlsetalpha.html 8KB
sdlsurface.html 8KB
sdlaudiocvt.html 7KB
sdlaudiospec.html 7KB
eventfunctions.html 7KB
sdlcreatergbsurface.html 7KB
sdlconvertaudio.html 6KB
VisualC.html 6KB
sdlcreatecursor.html 6KB
sdlsetpalette.html 6KB
thread.html 5KB
sdlblitsurface.html 5KB
joystick.html 5KB
sdlsetcolors.html 5KB
sdlvideoinfo.html 5KB
sdljoyhatevent.html 5KB
sdloverlay.html 5KB
sdlglattr.html 5KB
sdlmousemotionevent.html 5KB
guidecdromexamples.html 5KB
sdlkeysym.html 5KB
sdlkeyboardevent.html 5KB
sdlmousebuttonevent.html 5KB
cdrom.html 5KB
sdladdtimer.html 5KB
guideeventexamples.html 5KB
sdlcd.html 4KB
sdlactiveevent.html 4KB
guidebasicsinit.html 4KB
sdljoybuttonevent.html 4KB
sdllocksurface.html 4KB
sdlsemwaittimeout.html 4KB
sdllistmodes.html 4KB
sdljoyballevent.html 4KB
共 277 条
- 1
- 2
- 3
资源评论
小贝德罗
- 粉丝: 65
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功