Jump to content

  • Log In with Google      Sign In   
  • Create Account

How to get user writing input string in openGl?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
16 replies to this topic

#1 moudy   Members   -  Reputation: 102

Like
0Likes
Like

Posted 14 December 2013 - 05:50 PM

I need the way for allow users input text by writing (typing) , while users input text they see what's they input when user press enter jump for next line and when user end press on button to finish ?

note: I need user text input without opening a new window etc.


Edited by moudy, 15 December 2013 - 07:22 AM.


Sponsor:

#2 Servant of the Lord   Crossbones+   -  Reputation: 20974

Like
3Likes
Like

Posted 14 December 2013 - 06:07 PM

OpenGL is a graphics library only, and doesn't have (and shouldn't have) any GUI features built-in.

 

If you're using C++, consider using Qt for GUI-based applications.

Here's a screenshot of me using Qt to build an editor alongside my game: (still a work in progress)

cisd.png

 

Qt is for heavily GUI-driven applications, and takes over a great deal of your application. If text entry is really all you want, then Qt is way overkill, and you'd want something smaller like a OpenGL-based in-game GUI library - I don't have personal experience with any of those, but a half-dozen or so of them exist.


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#3 richardurich   Members   -  Reputation: 1187

Like
3Likes
Like

Posted 14 December 2013 - 06:56 PM

If you're looking for something with a lot smaller footprint than the Qt suggestion, you can use SDL. You can probably learn all the essentials of SDL in less than a day, and there are plenty of tutorials out there. Text input in SDL is just an event of type SDL_TEXTINPUT. If you need the key's state (down or up), you can track event types SDL_KEYDOWN and SDL_KEYUP instead.



#4 Servant of the Lord   Crossbones+   -  Reputation: 20974

Like
3Likes
Like

Posted 14 December 2013 - 07:02 PM

SDL doesn't have any GUI capabilities, just events.


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#5 swiftcoder   Senior Moderators   -  Reputation: 10363

Like
2Likes
Like

Posted 14 December 2013 - 09:05 PM


SDL doesn't have any GUI capabilities, just events.

SDL + SDL_ttf pretty much fits the bill, no?


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#6 Servant of the Lord   Crossbones+   -  Reputation: 20974

Like
1Likes
Like

Posted 14 December 2013 - 09:19 PM

 

SDL doesn't have any GUI capabilities, just events.

SDL + SDL_ttf pretty much fits the bill, no?

 

Perhaps! I was reading the OP's request as a LineEdit or TextEdit-style widget (but just not in a Win32-style pop-up modal dialog box).

 

@moudy: Are you looking for something like this:

q676.png

 

Or similar to this:

qeat.png

 

Or something else entirely?


Edited by Servant of the Lord, 14 December 2013 - 09:20 PM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#7 moudy   Members   -  Reputation: 102

Like
0Likes
Like

Posted 15 December 2013 - 07:39 AM

@Servant of the Lord

I am looking for something like the first example .



#8 Servant of the Lord   Crossbones+   -  Reputation: 20974

Like
0Likes
Like

Posted 15 December 2013 - 09:12 AM

Then you'll probably need to code most of it yourself to fine-tune it to your desires, using OpenGL-based text-renderers.

 

If your game is 2D, I'd suggest SFML 2, but SDL and SDL_ttf (like richardurich mentioned) are excellent as well. You could even use SDL_ttf or SFML to generate OpenGL textures for you that contain text, but the logical interactions and the correct layout will need to be written by your code.

 

Alternatively, you could try a OpenGL-based GUI library (which one, I wouldn't know).


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#9 moudy   Members   -  Reputation: 102

Like
-1Likes
Like

Posted 17 December 2013 - 08:54 AM

@

Servant of the Lord

pls , can u give a source code for the first example or anything useful or tutorial or website .



#10 BitMaster   Crossbones+   -  Reputation: 4427

Like
0Likes
Like

Posted 17 December 2013 - 09:47 AM

SotL already said what he is using for his example screenshot: Qt. If you decide to go down this route (which may not be wise for all types of games) and you aren't familiar with Qt yet then you will have to spend at least a few weeks learning a bit more about Qt. It's a quite massive framework and there is little room for cherry-picking a few pieces out quickly.

 

There are plenty of places to learn about Qt, including the site SotL (and now myself) linked.


Edited by BitMaster, 17 December 2013 - 09:47 AM.


#11 Servant of the Lord   Crossbones+   -  Reputation: 20974

Like
2Likes
Like

Posted 17 December 2013 - 01:45 PM

This example:

q676.png

 

Was made with SFML, but ANY graphics library can do the same thing.

 

I rendered the background (grass and water), then I rendered a stretched image over it, with transparency enabled:

39dz.png

 

Then I captured keyboard events to get keyboard input from the user and so the user can enter text into a std::string.

 

Then I used SFML to render some text from the std::string using a font, and drew that text over the panel.

 

This can be done with any decent graphics library, whether SDL, or SFML, or OpenGL, or whatever - the only difficulty is drawing the text, which OpenGL doesn't have native support for - you can use SFML or SDL to render text for you, and then upload it as a texture for OpenGL to use.

 

Multiple individual steps working together - how they will work together in your game will be different than how they work together in mine, so there's no code for you to copy and paste, you have to figure out how to write it yourself. Just break it into small steps like I just described, and accomplish the goals one by one.

 

Or, use a OpenGL-based GUI library.


Edited by Servant of the Lord, 17 December 2013 - 01:46 PM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#12 Solid_Spy   Members   -  Reputation: 451

Like
0Likes
Like

Posted 17 December 2013 - 05:43 PM

Yeah, I did this before with openGl. I had to create a Sentence Class, A Word Class, and a Letter Class. I Create a sentence at a certain position on the screen, and add text through its constructor, then creates words out of the text by splitting the spaces. It then creates a letter object for each letter in each word, and it renders each individual letter.

#13 moudy   Members   -  Reputation: 102

Like
0Likes
Like

Posted 21 December 2013 - 10:13 AM

@

Servant of the Lord 

I have used sdl_ttf in opengl . but i have this error :

  1. error LNK1104: cannot open file 'SDL_ttf.lib'

i already have tried to remove the "SDL_ttf.lib" , but it didn't useful.
i have trid used : lazyfoo.net for setting up the opengl with sdl
pls tell me what must i do ? .



#14 Servant of the Lord   Crossbones+   -  Reputation: 20974

Like
0Likes
Like

Posted 21 December 2013 - 11:36 AM

Are you on Windows or Linux or Mac OSX?

If on Windows, are you using Visual Studio or MinGW to compile your code?


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#15 Mathimetric   Members   -  Reputation: 133

Like
1Likes
Like

Posted 27 December 2013 - 08:14 PM

quik simple example

inside  ~ MainWindowProc ~

(I have used this to print 3D text from user keyboard input)

 

 

example.JPG

 

 
//                                                                  //
    case WM_CHAR:
    switch(wParam)
    {
    case VK_BACK:
    if(print.BuffPos)
    print.text[--print.BuffPos] = 0;
    if(print.sBuffPos)
    print.gBuff[--print.sBuffPos] = 0;
    break;
    case VK_RETURN:
    print.text[++print.BuffPos] = NULL;
    print.gBuff[++print.sBuffPos] = NULL;
    print.Return0(print.text,"char", 256);
    print.BuffPos = 0;
    print.Return0(print.gBuff, "char", 256);
    print.sBuffPos = 0;
    ++print.rtrn;
    break;
 case VK_NEXT:
 //MoonT.translation[1] -= 2;
 break;
 case VK_PRIOR:
 //MoonT.translation[1] += 2;
 break;
 break;
 break;
 
 case VK_LEFT:
        break;
 
 case VK_RIGHT:
      break;
 case VK_DOWN:     
 break;
 
 case VK_UP:      
 break;
    default:
    print.text[print.BuffPos] = (TCHAR) wParam;
    print.gBuff[print.sBuffPos] = (TCHAR) wParam;
    ++print.BuffPos;    ++print.sBuffPos;
    break;
    }
    break;
//                                                                    //
////////////////////////////////////////////////////////////////////////
 
Notice when a key is entered (printable character)
the switch is defaulted to update a string buffer.
--when enter key is depressed the handle Ends buffer with a NULL terminate char
|- then updates the data "rtrn" member to allow the program to know what line or how many times
the return key has been pressed. - this info is passed to the graphics functions for render()
 
-when the backspace key is pressed the string buffer's current Position is  zero'ed , and decrimented (pos) to re-enter the key that needs to be edited.
 
 
*in this case the buffer is used simulair to an I/O stream buffer in witch the buffer can be used to pass data to parameter's givin to
a function or class member function; such as GetString(int Rtn_order, char * format, ...)
 
Original standard streaming I/O buffers uses access of the Keyboard buffer and passes its data to a TEMP file buffer
{
(I.E.)
 
extern  FILE        _RTLENTRY _EXPDATA _streams[];
extern  unsigned    _RTLENTRY _EXPDATA _nfile;
 
stdin   (&_streams[0])
stdout  (&_streams[1])
stderr  (&_streams[2])
}
and C string Buffer's using BIOS (basic input/output instruction Sets')

Edited by Mathimetric, 11 January 2014 - 10:53 AM.


#16 moudy   Members   -  Reputation: 102

Like
-2Likes
Like

Posted 03 January 2014 - 05:26 PM

@

Mathimetric 

pls can you give me the file for this example . 



#17 Mathimetric   Members   -  Reputation: 133

Like
0Likes
Like

Posted 09 January 2014 - 11:20 AM

@ Moudy I can try to find a source for this example (a HEllo World example)

but it will be un-related to the Hex editor -converter dipicted in the screen shot.

 

if thats ok? ; I will attach it to this messge when I have it together.

 

 

here is an alternate example of  GetString using OpenGL and windows library

-So in function the *strng is updated (represinting a Line) via the stream buffer gBuff [ ]

-when the return key check (rtrn) is  (>) greater then (Order) ; the function returns the string length of *strng -

and stops updating the *strng

 

the reason it looks this way is because it is meant to be inserted into a windows Loop or Application window Loop.

functions that are inside a window are a little different then the normal console apps' sometimes.

 

-class interface design-

class GLText
public:
    int BuffPos, sBuffPos,
    First, Count1, Count2;
    unsigned int base;
    unsigned int m_fontListBase;
    GLYPHMETRICSFLOAT gmf[256];   // holds orientation and placement
                                  // info for display lists

     GLText();
    ~GLText();

    bool Init(char *fontname, int fontsize, float depth);
    unsigned int CreateOutlineFont(char *fontname, int fontsize, float depth);
    void PositionFont(float xPos, float yPos, float zPos);
    void PrintFont(int order, const char *__format, ...);
    void CenterFont();
    void ReleaseFont(unsigned int base);
    int  ScanFont(int order, const char *__format, ...);
    void NewLine(float Mult = 1, float X = 0, float Y = 0, float Z = 0, char *Direction = "down");
    bool Shutdown();
    void Return0(void *var, char *type, int elms); //same as memset (...) for string
    int  GetString(int Order, char *strng);
    int rtrn;
    char *pBuff;
    char *sBuff;
    char *gBuff;
    char text[256];
int GLText::GetString(int Order, char *strng)
{
if(Order<=rtrn)
{
if (Order == rtrn )
{
 glPushAttrib(GL_LIST_BIT);
        glListBase(base);
        glCallLists(strlen(gBuff), GL_UNSIGNED_BYTE, gBuff);
 glPopAttrib();
        strng[BuffPos] = gBuff[BuffPos];
        strcpy(strng, gBuff);
return 0;
}
else
if(Order <= rtrn)
{
        glPushAttrib(GL_LIST_BIT);
        glListBase(base);
        glCallLists(strlen(strng), GL_UNSIGNED_BYTE, strng);
 glPopAttrib();
return strlen(strng);
}
return 0;
}
else
return strlen(strng);
}

I attached the class function def source code in src.cpp.txt

you will need to use your knowledge of C++ to piece them together for compilation/debugging/porting or use in another instance.

 

You can do 1 of 2 things with it

1. you could just include (src.cpp) it to the appended end of the class body Def

2. precompile it and link it with the H and the Main.cpp with the OBJ file

(this also includes letting microsofts visual studio LInk the resources with (h/cpp))

 

Summary:

this class will allow you, if you are using openGL (v1.0 or greater) 3d perspectives or ortho (ithink), a pixel pallete window application (WIN32); To draw 3d text on to the screen. Givin also the interface' to use input/output UI via keyboard or simulair (drivin) hardware.

--another requirement is that the window(x/s) APP must have a procedure for handling the window and its messeges--

 

your skill level needs to be intermediate to advanced to understand how to compile or port this into your own apps.

creating a window App is not an easy task for the beginner. You need to understand your own compiler and interfaces,

and some compiler's dont always have the nessesary DLL's included in its default libraies; so sometimes you need to know how to

find them and import them.

Attached Files


Edited by Mathimetric, 11 January 2014 - 11:57 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS