954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

SDL, Unicode, and Trash

Hi everyone, I'm trying to program a game in C++ using SDL and i want to get peoples names. its not working though, and I'm really confused as to why. :?:

i'm using code like the following:
StringInput.h

class StringInput {
private:
std::string str;
SDL_Surface *text;
int x,y,r,g,b;
SDL_Color textColor;
Uint32 uc;
public:
StringInput(int x, int y);
...
handleInput();
...
};


StringInput.cpp

StringInput::StringInput(int x, int y) {
...
SDL_EnableUNICODE(1);
}
...
void StringInput::handleInput() {
...

if(event.key.keysym.sym!=SDLK_BACKSPACE){

str+=(char)(event.key.keysym.unicode);

} else if(str.length()!=0){

str.erase(str.length()-1);

} else { }
...
}
...


At this point I have done a lot of debugging output to a file calledstdout.txt

I have figured out that the value event.key.keysym.unicode is 0 all the time when I type something (normally something like jaksl ... )

What could cause this and how to fix it?

This is in a game of mine that I really want to make. I need help badly. :(

epicbeast9022
Newbie Poster
15 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

are you sure SDL can handle unicode? It seems C++ doesn't have Unicode support. So try third party libraries!

evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 
are you sure SDL can handle unicode? It seems C++ doesn't have Unicode support. So try third party libraries!

I'm using Unicode to test difference between 'a' and 'A'. So yes, it would have unicode. (I'm using GCC for Windows). And what third party libraries could I use?

(are there any other possible solutions?)

epicbeast9022
Newbie Poster
15 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

I'm using Unicode to test difference between 'a' and 'A'. So yes, it would have unicode. (I'm using GCC for Windows). And what third party libraries could I use?

(are there any other possible solutions?)


Check with POCO Unicode , if you have question ask in their forums

evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 

I updated t using the code from Lazy Foo tutorials. In a standalone program it works fine but in this one it doesn't. Any answers?

epicbeast9022
Newbie Poster
15 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

If you don't mind Try wxWidgets . from version 2.9.x you can use wxBase which have no GUI components Just console. Remember to compile with unicode flag set.

wx is known to work with Unicode "naturally" when compiled with Unicode. also there is wx-SDL tutorial .

evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 

i failed :)
I put the SDL Enable Unicode call in the object initialization not the program initialization so that's why it didnt work. now it does.
(also changed the typecasted character values to integers, that might've helped.)
stupid me

epicbeast9022
Newbie Poster
15 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 
i failed :) I put the SDL Enable Unicode call in the object initialization not the program initialization so that's why it didnt work. now it does. (also changed the typecasted character values to integers, that might've helped.) stupid me


Glad you resolved it :)

evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: