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 called stdout.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. :(

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

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?)

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

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?

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.

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

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.