编译使用SDL2.0
SDL2.0 可以支持非英文的输入。 也有第三方的朋友做了一个SDL插件也支持非英文输入。 这里记录一下在尝试过程中遇到一些编译问题。
参照文档写了一个demo
#include "../include/SDL.h"
//The event structure
SDL_Event event;
char text[1024];
SDL_Surface *screen = NULL;
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;
#include <string>
std::string composition;
int cursor;
int selection_len = 0;
#include "SDL.h"
int main(int argc, char* argv[])
{
SDL_Window* window;
SDL_Renderer* renderer;
// Initialize SDL.
if (SDL_Init(SDL_INIT_VIDEO) < 0)
return 1;
// Create the window where we will draw.
window = SDL_CreateWindow("SDL_RenderClear",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
512, 512,
SDL_WINDOW_SHOWN);
// We must call SDL_CreateRenderer in order for draw calls to affect this window.
renderer = SDL_CreateRenderer(window, -1, 0);
// Select the color for drawing. It is set to red here.
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
// Clear the entire screen to our selected color.
SDL_RenderClear(renderer);
// Up until now everything was drawn behind the scenes.
// This will show the new, red contents of the window.
SDL_RenderPresent(renderer);
SDL_StartTextInput();
while (true)
{
if (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_TEXTINPUT:
/* Add new text onto the end of our text */
strcat(text, event.text.text);
break;
case SDL_TEXTEDITING:
/*
Update the composition text.
Update the cursor position.
Update the selection length (if any).
*/
composition = event.edit.text;
cursor = event.edit.start;
selection_len = event.edit.length;
break;
}
}
}
// Give us time to see the window.
SDL_Delay(1000);
// Always be sure to clean up
SDL_Quit();
return 0;
}
Makefile 这样写的
all:
g++ -g testime.cpp -I/home/zhuzhonghua/work/SDL/include /home/zhuzhonghua/work/SDL/build/.libs/libSDL2.a /home/zhuzhonghua/work/SDL/build/libSDL2main.a -lpthread -lGL -lGLU -lm -L/usr/lib/x86_64-linux-gnu -lrt -ldl
demo写的有问题,需要写一个退出函数,要不然总是关不掉。
本人喜欢静态编译,所以就全部使用的.a文件。
刚开始编译时会遇到dlsym undefined reference 的问题,加上-ldl选项就OK了。
遇到clock_gettime undefined reference,那么加上-lrt的选项,就OK 了。