   Question about drawing text to screen with Draw_Text_GDI
  Hi, I've got somewhat of a specific question about the basics of drawing text to the screen using the function Draw_Text_GDI. Here's the type of scenario that I have:   sprintf(buffer,"PRESS <ENTER> TO CONTINUE");Draw_Text_GDI(buffer,200, 380,RGB(0,0,255),lpddsback);sprintf(buffer,"PRESS <ESC> TO QUIT");Draw_Text_GDI(buffer,235, 400,RGB(0,0,255),lpddsback);if (keyboard_state[DIK_RETURN]){Hide_BOB(&intro);   sprintf(buffer, "test...");   Draw_Text_GDI(buffer, 50, 0, RGB(0,0,255), lpddsback);   if(keyboard_state[DIK_G]){   game_state = INITIAL_1;   Init_Level1();}}Here basically what I'm doing is after a user presses the enter key to get out of the intro screen, a blank screen comes up, on which I'd like to write some text that has to do with story development (for now I just left ias "test..."). So here, what SHOULD happen, is that when the user hits enter, it should display "test...", and when the user hits the G key, the first level should initiate.That, however, is not what actually happens. What happens is that when the user hits enter, and HOLDS enter, "test..." is displayed. When the user lets go of enter, then the screen goes back to just displaying "Press <Enter> to continue", etc.If the user holds enter and presses the G key, the first level initiates...any clue why that would be?And believe it or not, that's not the main reason I posted. My real question has more to do with this: Let's say my "test..." becomes a whole screen full of text. Is there a way within DirectX to clear the screen of all written text, and then just write some more?I thank everyone for their help, and in taking the time to read my long post.   
  It looks like this code is taken from one of Andre LaMothe's books.  I'm guessing it uses DX5 or DX6?  Definitely using DirectDraw instead of DirectGraphics.Once you press the enter key, the keyboard_state array sets that particular element to "Pressed" and you enter that block of code.  Then it tests the keyboard_state array element for the "G" key - and if it is pressed, it sets the game state to 1 - entering the game.You need some pauses of some kind, or some smaller loops.  I think you probably have a large loop that renders as fast as it can, gathering keyboard input and then moving on.  It doesn't look like you change the game state except in the case of both Return and G.  Instead of just printing "Test..." you should enter a new loop where you draw test every frame and assume that you are in that game state (maybe state 2).I highly recommend you skip this book.  It was fine about 4 years ago, but is now simply outdated.   ;  I'm starting to see that you are in fact right about the book being outdated. It actually uses DirectX 8. And it's the text for a class I'm in, so it wasn't exactly my choice to pick the book up. However, thanks for the advice, and the help!   ;  Incidentally, let me ask another question then. Are there any better ways that you can reccomend to do what I want to do in DirectX? I'm sure updated versions of it must have some sort of way to write text to the screen?   ;  The problem really isn't in the way you are drawing to the screen.  DirectDraw works - at the moment (though it is deprecated).  The solution is to separate your game states a bit.Eg: enum Game_State { gsIntro, gsMenu, gsIngame, gsExit };So your loop is something akin to:Do the following foreverswitch (myGameState) {case gsIntro: drawIntro(); break;case gsMenu: drawMenu(); break;case gsIngame: gameLogic(); break;case gsExit: exit(0); // Or something similar.}Draw back buffer to front buffer.-- For your drawMenu() function, use something like:while (no key is pressed) drawMainMenu(); // Including flip().switch (pressedKey) {case gameStartKey: myGameState = gsIngame; break;case gameExitKey: myGameState = gsExit; break;case gameSubmenuKey: while (no key is pressed) {   drawSubmenu(); // Including flip().   check for new key;} break;}Good luck!   ;  Hey, thanks, that puts things in prespective for me! Any thoughts on what a good way to clear the screen of all drawn text would be?   ;  just because the book is outdated doesn't mean you can't learn from it.  Take the concepts and make a few games using his oldschool engine, it makes learning D3D easier. Everyone has to start somewhere.  I've taken Lamothe's books and made two games already and am starting to work on a 3rd. When I'm done with the 3rd I'll have a strong grasp on programming techniques, directx structures, and games in general and I don't think the switch to D3D will be that hard.To answer your questions:Your loop is checking to see if the enter key is down, if it is down, it displays text.  while the enter key is down, if the g key is down, it does the other set of instructions.An easy fix is to set a gamestate variable.int GameState=0;if(keyboard_state[DIK_RETURN]){GameState=1;}if(GameState==1){Draw_Text_GDI(blahblahblah);if(keyboard_state[DIK_G]){//dostuff}}I've never done a text game before so I'm not sure about the clear text thing.  You have a few choices.  An easy solution is to draw a big black rectangle over the whole screen.I have a game programming journal at http://adamgames.blogspot.comyou can download my game (bounce tennis) and check the source for how i used lamothe's engine to make the game.  I also have a forum if you have any more questions related to the engine, book, demos, etc.There are a lot of people who know 3d gaming engines and will try and dissuade you from reading a book about DirectDraw, just learn the basics and build up. Better to have a crappy text game using an outdated engine then no game at all.   ;Quote:   sprintf(buffer,"PRESS <ENTER> TO CONTINUE");Draw_Text_GDI(buffer,200, 380,RGB(0,0,255),lpddsback);sprintf(buffer,"PRESS <ESC> TO QUIT");Draw_Text_GDI(buffer,235, 400,RGB(0,0,255),lpddsback);if (keyboard_state[DIK_RETURN]){Hide_BOB(&intro);   sprintf(buffer, "test...");   Draw_Text_GDI(buffer, 50, 0, RGB(0,0,255), lpddsback);   if(keyboard_state[DIK_G]){   game_state = INITIAL_1;   Init_Level1();}}The assumption you are making is that keyboard_state[DIK_G] will make the program wait. It will instead check the key and move on. You don't actually have to have return and g held together, but the code is executing at a speed that it seems like it. IIRC from the book (is it the 2d book or the 3d book?), Draw_Text_GDI will not display any output to the screen until you flip the back buffer, so you wouldn't see any text until the end of your main loop either.If you are interested in doing 2d, I've heard good things about SDL.   ;Quote:Original post by StiltzkinHey, thanks, that puts things in prespective for me! Any thoughts on what a good way to clear the screen of all drawn text would be?Color Fill I'm not suggesting you can't learn anything from outdated material, but it will be - by very definition - outdated.  I've read most of LaMothe's books, but it was a long time ago.  There have been a lot of important changes to graphics since DirectDraw.  I have extensive experience with both - I've written games in DirectDraw - and DirectGraphics is a much more powerful, and even easier to use API.   ;  I hate to continue keeping this same old thread alive. But as per a lot of your suggestions, I tried just throwing a game state variable in there to catch this, this is what I have://test game statesif (game_state == INTRO){intro.x = 115;intro.y = 80; Draw_BOB16(&intro,lpddsback);sprintf(buffer,"PRESS <ENTER> TO CONTINUE");Draw_Text_GDI(buffer,200, 380,RGB(0,0,255),lpddsback);sprintf(buffer,"PRESS <ESC> TO QUIT");Draw_Text_GDI(buffer,235, 400,RGB(0,0,255),lpddsback);if (keyboard_state[DIK_RETURN]){game_state = INTRO_STORY;}}if(game_state == INTRO_STORY){   sprintf(buffer, "test...");   Draw_Text_GDI(buffer, 50, 0, RGB(0,0,255), lpddsback);   sprintf(buffer,"PRESS <ENTER> TO START GAME");   Draw_Text_GDI(buffer,200, 380,RGB(0,0,255),lpddsback);   sprintf(buffer,"PRESS <ESC> TO QUIT");   Draw_Text_GDI(buffer,235, 400,RGB(0,0,255),lpddsback);   if(keyboard_state[DIK_RETURN])   {  game_state = INITIAL_1;   }}if(game_state == INITIAL_1){Init_Level1();   //in this function, game_state variable is set to "LEVEL_1", background //is displayed, etc.}//I have other similar if statements here to initialize all the different levelsMy problem now is that the game literally freezes on the title screen. My MIDI music that I have set to play starts and plays fine...but neither escape nor enter actually do anything as they are supposed to. And if I'm right, right after the return key is pressed, we should be going into the INTRO_STORY state. And then the if statement directly after should be picking it up. The funny part is that this statement works just fine if I do NOT switch to INTRO_STORY and start writing text to the screen, but go directly to the INITIAL_1 state when the enter key is pressed. Any thoughts?   