level 11
闪光点22的xh
楼主
输出文字怎么都不起效。。。运行4个succeed但就是打印不出来
#include <SDL2/SDL.h>
#include <iostream>
#include <SDL2/SDL_ttf.h>
using namespace std;
SDL_Window*win=SDL_CreateWindow("test",800,80,600,600,SDL_WINDOW_SHOWN);
SDL_Renderer*ren=SDL_CreateRenderer(win,-1,SDL_RENDERER_ACCELERATED|SDL_RENDERER_PRESENTVSYNC);
int main(int argc,char**argv)
{
if(ren==NULL)
cout<<"fail"<<endl;
else
cout<<"succeed"<<endl;
TTF_Init() ;
SDL_Color color = { 255, 255, 255 };
SDL_Rect pos;
pos.x=300,pos.y=300;
TTF_Font *font =TTF_OpenFont("font_a.ttf",36);
if(font==NULL)
cout<<"fail"<<endl;
else
cout<<"succeed"<<endl;
SDL_Surface *surf = TTF_RenderText_Solid(font,"hello world",color);
if(surf==NULL)
cout<<"fail"<<endl;
else
cout<<"succeed"<<endl;
SDL_Texture *texture = SDL_CreateTextureFromSurface(ren, surf);
if(texture==NULL)
cout<<"fail"<<endl;
else
cout<<"succeed"<<endl;
SDL_RenderCopy(ren ,texture,NULL,&pos);
SDL_RenderPresent(ren);
SDL_Delay(2000);
SDL_FreeSurface(surf);
TTF_CloseFont(font);
return 0;
}
@twtfcu3 我已经折腾了一天了。。。仍然是第一次打开花屏,以后运行黑屏
2014年06月28日 14点06分
1
#include <SDL2/SDL.h>
#include <iostream>
#include <SDL2/SDL_ttf.h>
using namespace std;
SDL_Window*win=SDL_CreateWindow("test",800,80,600,600,SDL_WINDOW_SHOWN);
SDL_Renderer*ren=SDL_CreateRenderer(win,-1,SDL_RENDERER_ACCELERATED|SDL_RENDERER_PRESENTVSYNC);
int main(int argc,char**argv)
{
if(ren==NULL)
cout<<"fail"<<endl;
else
cout<<"succeed"<<endl;
TTF_Init() ;
SDL_Color color = { 255, 255, 255 };
SDL_Rect pos;
pos.x=300,pos.y=300;
TTF_Font *font =TTF_OpenFont("font_a.ttf",36);
if(font==NULL)
cout<<"fail"<<endl;
else
cout<<"succeed"<<endl;
SDL_Surface *surf = TTF_RenderText_Solid(font,"hello world",color);
if(surf==NULL)
cout<<"fail"<<endl;
else
cout<<"succeed"<<endl;
SDL_Texture *texture = SDL_CreateTextureFromSurface(ren, surf);
if(texture==NULL)
cout<<"fail"<<endl;
else
cout<<"succeed"<<endl;
SDL_RenderCopy(ren ,texture,NULL,&pos);
SDL_RenderPresent(ren);
SDL_Delay(2000);
SDL_FreeSurface(surf);
TTF_CloseFont(font);
return 0;
}
@twtfcu3 我已经折腾了一天了。。。仍然是第一次打开花屏,以后运行黑屏


