level 4
源代码使用SDL_ttf库里的字体加载等函数
sdl崩溃闪退
怎么解决?
2017年01月08日 13点01分
1
level 4
#include <SDL.h>
#include <SDL_ttf.h>
int main(){
SDL_Init(SDL_INIT_EVERYTHING);
TTF_Init();
SDL_Surface *a_1=NULL,*a_2=NULL;
TTF_Font *ttf_1=NULL;
SDL_Color ttf_1c={0,0,0};
a_1=SDL_SetVideoMode(1080,1920,32,SDL_SWSURFACE);
ttf_1=TTF_OpenFont("/zy/en.ttf",26);
a_2=TTF_RenderText_Solid(ttf_1,"Happy birthday to you.",ttf_1c);
SDL_BlitSurface(a_2,NULL,a_1,NULL);
SDL_Flip(a_1);
SDL_Delay(3000);
}
2017年01月08日 13点01分
2
level 14
在安卓上根本不会有你写的这个路径,把字体路径改对了再说,改到你的ttf_1不为NULL为止。
2017年01月08日 19点01分
3
这个不是相对路径吗
2017年01月09日 12点01分
大神看下楼下我发的图片,c4编译成功,cide出警告,怎么关警报啊
2017年01月09日 16点01分
level 4
#include <SDL.h>
#include <SDL_mixer.h>
#include <SDL_image.h>
#include <SDL_events.h>
#include <SDL_thread.h>
#include "SDL_auxiliary.h"
SDL_Thread *t_1;//建立线程指针
bool quit_main;
#define LENGTH 1080
#define HIGH 1920
int play(void* data) {
Mix_Music *m=(Mix_Music*)data;
while (quit_main != 1) {/*判断主函数是否结束*/
Mix_PlayMusic(m, -1);
}
return 1;
}
int main() {
SDL_Init(SDL_INIT_EVERYTHING);//启动sdl
Mix_Music *m_1;
m_1=Mix_LoadMUS("1.wmv");//加载音乐文件
if (m_1==NULL)
return 0;
Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT, 2, 4096);//启动音频
t_1=SDL_CreateThread(play,(void*)m_1);
int o = 0;
SDL_Event tap = {.type = 0 };
SDL_Rect file_xy[3], screen_a;
file_xy[0].x = 620;
file_xy[0].y = 877;
file_xy[1].x = 841;
file_xy[1].y = 1128;
file_xy[2].x = 1046;
file_xy[2].y = 1526;
char *file_name[3] =
{ "zy/image/1.jpg\0", "zy/image/2.jpg\0", "zy/image/3.jpg\0" };
SDL_Surface *a_1 = NULL, *a_2[3];
a_1 = SDL_SetVideoMode(1080, 1920, 32, SDL_SWSURFACE);
bulk_load_image(file_name, a_2, 3);
for (int i = 0; i % 3 < 3; i++) {
screen_a = middle_xy(1080, 1920, file_xy[i % 3]);
SDL_BlitSurface(a_2[i % 3], NULL, a_1, &screen_a);
SDL_Flip(a_1);
while (o != 1) {
SDL_PollEvent(&tap);
if (tap.type == 5) {
a_1 = SDL_SetVideoMode(LENGTH, HIGH, 32, SDL_SWSURFACE);
SDL_Flip(a_1);
break;
}
}
}
SDL_Quit();
quit_main = 1;
return 0;
}
2017年01月14日 03点01分
7
level 4
头文件的内容:
//图像居中点
SDL_Rect middle_xy(int l,int h,SDL_Rect image_lh){
SDL_Rect re;
re.x=(l-image_lh.x)/2;
re.y=(h-image_lh.y)/2;
return re;
}
//关键色
void key_color(SDL_Surface *file,Uint8 r,Uint8 g,Uint8 b){
Uint32 color=SDL_MapRGB(file->format,r,g,b);
SDL_SetColorKey( file, SDL_SRCCOLORKEY, color );
}
// 图像优化
SDL_Surface *image_opi(SDL_Surface * a) {
SDL_Surface *b = NULL;
b = SDL_DisplayFormat(a);
SDL_FreeSurface(a);
return a;
}
// 图像批量加载
int bulk_load_image(char* file_name[], SDL_Surface *file[], int i) {
SDL_Surface *ls = NULL;
for (int j = 0; j < i; j++) {
ls = IMG_Load(file_name[j]);
file[j] = ls;
}
}
2017年01月14日 03点01分
8
level 14
关于播放的我也不懂,这个代码我测试是ok的,给你吧
#include <android/log.h>
#include <SDL.h>
#include <SDL_mixer.h>
#define LOGI(...) \
((void)__android_log_print(ANDROID_LOG_INFO, "mix", __VA_ARGS__))
#define LOGW(...) \
((void)__android_log_print(ANDROID_LOG_WARN, "mix", __VA_ARGS__))
int main() {
char out[512];
SDL_Init(SDL_INIT_EVERYTHING);
Mix_Init(MIX_INIT_MP3);
Mix_Music *m_1 = NULL;
if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096)<0)
sprintf(out,"open (%s)",Mix_GetError());
else
sprintf(out,"open (%s)","ok");
LOGW(out);
m_1 = Mix_LoadMUS("/sdcard/Music/Two Steps From Hell-Skyworld-Breathe-128.mp3");
if (m_1) {
sprintf(out,"play (%s)","ok");
LOGW(out);
Mix_PlayMusic(m_1, 1);
SDL_Delay(225 * 1000);
}else{
sprintf(out,"load (%s)",Mix_GetError());
LOGW(out);
}
}
2017年01月14日 16点01分
9