spring中如何配置事务在XCODE C++中配置SDL

XCODE9上如何配置SDL2? - 知乎有问题,上知乎。知乎作为中文互联网最大的知识分享平台,以「知识连接一切」为愿景,致力于构建一个人人都可以便捷接入的知识分享网络,让人们便捷地与世界分享知识、经验和见解,发现更大的世界。1被浏览2分享邀请回答暂时还没有回答,开始写第一个回答c++ SDL简单例子 - 为程序员服务
为程序员服务
SDL简单例子
/* gcc -g -Wall `sdl-config --cflags` my_test.c `sdl-config --libs` */
#include &SDL.h&
#include &stdlib.h&
typedef struct sound_s {
/* raw PCM sample data */
/* size of sound data in bytes */
} sound_t;
/* Structure for a currently playing sound. */
typedef struct playing_s {
/* 1 if this sound should be played */
/* sound data to play */
/* current position in the sound buffer */
} playing_t;
playing_t play_
void play_callback(void *user_data, Uint8 *stream, int length)
user_data = NULL;
pos = play_music.
memset(stream, 0, length);
if (pos & play_music.sound.length)
if (pos + length & play_music.sound.length)
len = play_music.sound.length -
fprintf(stderr, &%d----&%d\\n&, play_music.sound.length, pos);
SDL_MixAudio(stream, play_music.sound.samples + pos, len, SDL_MIX_MAXVOLUME);
if (pos + length & play_music.sound.length)
play_music.position +=
play_music.position = play_music.sound.
int LoadAndConvertSound(char *filename, SDL_AudioSpec *spec,
sound_t sound)
SDL_AudioCVT
/* audio format conversion structure */
SDL_AudioS
/* format of the loaded data */
Uint8 *new_
/* Load the WAV file in its original sample format. */
if (SDL_LoadWAV(filename,
&loaded, &sound.samples, &sound.length) == NULL) {
printf(&Unable to load sound: %s\\n&, SDL_GetError());
/* Build a conversion structure for converting the samples.
This structure contains the data SDL needs to quickly
convert between sample formats. */
if (SDL_BuildAudioCVT(&cvt, loaded.format,
loaded.channels,
loaded.freq,
spec-&format, spec-&channels, spec-&freq) & 0) {
printf(&Unable to convert sound: %s\\n&, SDL_GetError());
/* Since converting PCM samples can result in more data
(for instance, converting 8-bit mono to 16-bit stereo),
we need to allocate a new buffer for the converted data.
Fortunately SDL_BuildAudioCVT supplied the necessary
information. */
cvt.len = sound.
new_buf = (Uint8 *) malloc(cvt.len * cvt.len_mult);
if (new_buf == NULL) {
printf(&Memory allocation failed.\\n&);
SDL_FreeWAV(sound.samples);
/* Copy the sound samples into the new buffer. */
memcpy(new_buf, sound.samples, sound.length);
/* Perform the conversion on the new buffer. */
cvt.buf = new_
if (SDL_ConvertAudio(&cvt) & 0) {
printf(&Audio conversion error: %s\\n&, SDL_GetError());
free(new_buf);
SDL_FreeWAV(sound.samples);
/* Swap the converted data for the original. */
SDL_FreeWAV(sound.samples);
sound.samples = new_
sound.length = sound.length * cvt.len_
play_music.sound =
/* XXXXXXXXXXXXXXXXXXXXXXXXX */
/* Success! */
printf(&'%s' was loaded and converted successfully.\\n&, filename);
int main(int argc, char *argv[])
/* Audio format specifications. */
SDL_AudioSpec desired,
/* Our loaded sounds and their formats. */
/* Initialize SDL's video and audio subsystems.
Video is necessary to receive events. */
if (SDL_Init(SDL_INIT_AUDIO) != 0) {
printf(&Unable to initialize SDL: %s\\n&, SDL_GetError());
/* Make sure SDL_Quit gets called when the program exits. */
atexit(SDL_Quit);
/* We also need to call this before we exit. SDL_Quit does
not properly close the audio device for us. */
atexit(SDL_CloseAudio);
/* Open the audio device. The sound driver will try to give us
the requested format, but it might not succeed. The 'obtained'
structure will be filled in with the actual format data. */
desired.freq = 44100;
/* desired output sample rate */
desired.format = AUDIO_S16; /* request signed 16-bit samples */
desired.samples = 4096; /* this is more or less discretionary */
desired.channels = 2;
/* ask for stereo */
desired.callback = play_
desired.userdata = NULL;
/* we don't need this */
if (SDL_OpenAudio(&desired, &obtained) & 0) {
printf(&Unable to open audio device: %s\\n&, SDL_GetError());
/* Load our sound files and convert them to the sound card's format. */
if (LoadAndConvertSound(argv[1], &obtained, cannon) != 0) {
printf(&Unable to load sound.\\n&);
/* SDL's audio is initially paused. Start it. */
SDL_PauseAudio(0);
while (play_music.position &= play_music.sound.length)
/* Pause and lock the sound system so we can safely delete our sound data. */
SDL_PauseAudio(1);
/* At this point the output is paused and we know for certain that the
callback is not active, so we can safely unlock the audio system. */
SDL_UnlockAudio();
//该片段来自于http://outofmemory.cn
您可能的代码
相关聚客文章
相关专栏文章&1&/*&2&&*&main.cpp&3&&*&4&&*&&Created&on:&日&5&&*&&&&&&Author:&wgzll&6&&*/&7&#include&&iostream&&8&#include&&sdl2/sdl.h&&9&using&namespace&10&11&SDL_Window*&g_pWindow&=&0;12&SDL_Renderer*&g_pRenderer&=&0;13&14&int&main(int&argc,char&*args[])15&{16&&&&&if(SDL_Init(SDL_INIT_EVERYTHING)&=0)17&&&&&{18&&&&&&&&&g_pWindow&=&SDL_CreateWindow("Chapter&1:&Setting&up&SDL",19&&&&&&&&&&&&&&&&&SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,20&&&&&&&&&&&&&&&&&640,480,21&&&&&&&&&&&&&&&&&SDL_WINDOW_SHOWN);22&&&&&&&&&if(g_pWindow&!=0)23&&&&&&&&&{24&&&&&&&&&&&&&cout&&"初始化成功"&&25&&&&&&&&&&&&&g_pRenderer&=&SDL_CreateRenderer(g_pWindow,-1,0);26&&&&&&&&&}27&&&&&}28&&&&&else29&&&&&{30&&&&&&&&&cout&&"初始化失败"&&31&&&&&&&&&return&1;32&&&&&}33&34&&&&&SDL_SetRenderDrawColor(g_pRenderer,0,0,0,255);35&36&&&&&SDL_RenderClear(g_pRenderer);37&38&&&&&SDL_RenderPresent(g_pRenderer);39&40&&&&&SDL_Delay(500);41&42&&&&&SDL_Quit();43&44&&&&&return&0;45&}#define&SDL_INIT_EVERYTHING&(&\&&&&&&&&&&&&&&&&SDL_INIT_TIMER&|&SDL_INIT_AUDIO&|&SDL_INIT_VIDEO&|&SDL_INIT_EVENTS&|&\&&&&&&&&&&&&&&&&SDL_INIT_JOYSTICK&|&SDL_INIT_HAPTIC&|&SDL_INIT_GAMECONTROLLER&\&&&&&&&&&&&&)&Uint32&subsystem_subsystem_init&=&SDL_WasInit(SDL_INIT_EVERYTHING);&if&(subsystem_init&&&SDL_INIT_VIDEO)&&&&&{&printf("Video&is&initialized.\n");}&else&&&&&{&printf("Video&is&not&initialized.\n");&}if&(SDL_WasInit(SDL_INIT_VIDEO)&!=&0)&&&&&{&printf("Video&is&initialized.\n");}&else&&&&&{&printf("Video&is&not&initialized.\n");}Uint32&subsystem_mask&=&SDL_INIT_VIDEO&|&SDL_INIT_AUDIO;&if&(SDL_WasInit(subsystem_mask)&==&subsystem_mask)&&&&&{&printf("Video&and&Audio&initialized.\n");}&else&&&&&{&printf("Video&and&Audio&not&initialized.\n");}SDL_INIT_TIMERtimer&subsystemSDL_INIT_AUDIOaudio&subsystemSDL_INIT_VIDEOvideo&subsystemSDL_INIT_JOYSTICKjoystick&subsystemSDL_INIT_HAPTIChaptic&(force&feedback)&subsystemSDL_INIT_GAMECONTROLLERcontroller&subsystemSDL_INIT_EVENTSevents&subsystemSDL_INIT_EVERYTHINGall&of&the&above&subsystemsSDL_INIT_NOPARACHUTE&this&flag&is&ignored&&&&&MFC中使用SDL2
[问题点数:40分,无满意结帖,结帖人yztkdqzw]
本版专家分:0
结帖率 100%
CSDN今日推荐
本版专家分:0
结帖率 100%
本版专家分:0
本版专家分:0
本版专家分:0
本版专家分:0
匿名用户不能发表回复!|
CSDN今日推荐一个学生,各种尝试,记录于此……
SDL在dev-c++的配置记录
!!!这个方法有些问题,原因未知,请不要使用
由于一些原因需要用到SDL这个库,把自己学习的过程记录一下。
我的环境,Dev-C++的版本:5.9.2,SDL的版本:2.0.3。
其中的一些操作的原因我也不太清楚为什么,只知道这样可行,如果哪位知道还请留言解惑一下。
一、文件下载
在sdl官网上下载development libraries(MinGW)
http://www.libsdl.org/release/SDL2-devel-2.0.3-mingw.tar.gz
二、将下载的文件解压后目录为
由于我的是64位系统,所以将x86_64-w64-mingw32文件夹下的include和lib文件夹复制到Dev-C++目录下相应的位置,再将SDL根目录下lib\x64里的SDL2.dll文件复制到C:\Windows\System32中(这里为什么不复制到sysWOW64文件夹下?)
三、编译测试
在Dev-C++中新建一个空工程,复制以下代码
#include &stdio.h&
#include "SDL2/SDL.h"
int main( int argc, char* args[] )
if (SDL_Init( SDL_INIT_EVERYTHING ) != 0){
printf("SDL_Init Error: %s", SDL_GetError());
SDL_Quit();
system("pause");
} 然后在 项目-&项目属性-&参数-&链接中添加-lmingw32 -lSDL2main -lSDL2
编译无错即可
没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!

我要回帖

更多关于 如何在cdh中配置kafka 的文章

 

随机推荐