How To Reading Text To Screen

This How-To explains reading keyboard inputs and describes how to display the input in the game window.

Level

Intermediate

Read these first

How To Draw Simple Text

Details

SwinGame allows you to read text input from the keyboard and display the typed input directly in the game window. To achieve this you need to:

  1. Open a game windows
  2. Call ProcessEvents to register input
  3. Call ClearScreen
  4. If reading text procedure is false then call StartReadingText with the desired parameter to draw text to screen
  5. Refresh the screen
  6. Released all resources
  7. Run the program

On the right is a short video clip showing the program created from the code below.

Source Code Widget

  • program HowToReadingTextToScreen;
    uses SwinGame;
    
    procedure Main();
    
    begin
        OpenGraphicsWindow('Read Text To Screen' ,240 ,160 );
        LoadDefaultColors();
        repeat
            ProcessEvents();
            ClearScreen(ColorWhite );
            if  NOT ReadingText()    then
                StartReadingText(ColorRed ,40 ,LoadFont('Arial' ,12 )  ,10 ,10 );
            RefreshScreen(60 );
        
        until WindowCloseRequested();
        ReleaseAllResources();
    end;
    begin
        Main();
    end.
    Download Now"
  • #include 
    #include "SwinGame.h"
    int main() 
    {
    
        open_graphics_window("Read Text To Screen" ,240 ,160 );
        load_default_colors();
        do 
        {
            process_events();
            clear_screen(color_white );
            if ( ! reading_text()  )
                start_reading_text(color_red ,40 ,load_font("Arial" ,12 ) ,10 ,10 );
            refresh_screen(60 );
        }
        while ( ! (window_close_requested() ) );
        release_all_resources();
        return 0;
    }
    
    Download Now"
  • Source Code Coming Soon

  • Source Code Coming Soon

  • Source Code Coming Soon

If there is a useful hint you will find it in a box like this

Possibilities

  • Create a simple program that accepts an input from the user.
  • Create a game that allows each user to have a name.
  • Create a simple chat client.