Skip to main content
gamedev.net
🔒 Locked

Text input

Started by Sc4Freak Dec 28, 2006 at 1:06 AM 6 replies 800+ views
Original Post
Sc4Freak
Sc4Freak
I've been told, over and over again, not to use DirectInput for text and to use WM_CHAR instead. That's all fine, but I have a small problem. Since WM_CHAR is a Windows message, it is only updated once every frame. What I want to know is, at a low framerate will this be a problem? Since I can use buffered input with DirectInput, keystrokes in between frames is not a problem, and no matter the framerate every keystroke will always be captured. Does Windows do the same thing with WM_CHAR messages?
hervens
hervens
So if you wanna output text on the screen, supposing your using direct3d, make 2 new files. A source file named text.cpp and a header file named text.h

// text.h
[source lang ="cpp"]#ifndef text_h#define text_h#include "stdafx.h"	class cText{private:	LPD3DXFONT				g_font;	public:							cText();							~cText();	int						testing;	HRESULT					initFont(LPDIRECT3DDEVICE9 device);	HRESULT					printText(LPCSTR text,LPDIRECT3DDEVICE9 device,int top, int left,int right, int bottom);};#endif



// text.cpp
[source lang ="cpp"]#include "text.h"extern D3DXFONT_DESC LogFont = {14,0,400,0,false,DEFAULT_CHARSET,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_PITCH,"Arial"};extern RECT FontPosition = {0,0,800,600,};cText::cText(){	g_font = NULL;	}///////////////////////////////////////////////////////////////////////desc: release the font pointer/////////////////////////////////////////////////////////////////////cText::~cText(){	if (g_font != NULL)		g_font->Release();		g_font = NULL;		}/////////////////////////////////////////////////////////////////////desc: create and initialize the font//////////////////////////////////////////////////////////////////HRESULT cText::initFont(LPDIRECT3DDEVICE9 device){		FontPosition.top = 0;	FontPosition.left = 0;	FontPosition.right = 300;	FontPosition.bottom = 200;		D3DXCreateFontIndirect(device,&LogFont,&g_font);	return S_OK;}///////////////////////////////////////////////////////////////////////desc: creates a font, and prints the text to the screen/////////////////////////////////////////////////////////////////////HRESULT cText::printText(LPCSTR text,LPDIRECT3DDEVICE9 device,int top,int left,int right, int bottom){			FontPosition.top = top;	FontPosition.left = left;	FontPosition.bottom = bottom;	FontPosition.right = right;	g_font->DrawText(NULL,text,-1,&FontPosition,DT_CENTER,0xffffffff);	return S_OK;};


Now to print text with that, you just have to use the function printText

heres an example

#include "text.h"cText text;text = new cText;text->printText("testing my new text class :",device,340,0,100,900);


This should output "testing my new text class :" on the bottom left corner of your screen.

Also keep in mind that printText must be called between BeginScene() and EndScene() functions of direct3d.

hope that helps.
PurpleBoxMobile.com My mobile app publishing startup
Aardvajk
Aardvajk
Quote:
Original post by Sc4Freak
I've been told, over and over again, not to use DirectInput for text and to use WM_CHAR instead. That's all fine, but I have a small problem. Since WM_CHAR is a Windows message, it is only updated once every frame. What I want to know is, at a low framerate will this be a problem?

Since I can use buffered input with DirectInput, keystrokes in between frames is not a problem, and no matter the framerate every keystroke will always be captured. Does Windows do the same thing with WM_CHAR messages?


As far as I am aware, Windows will queue WM_CHAR messages.

However, when you say a very low frame-rate, how low do you mean? Most games would be unplayable at anything less than 20 frames per second and not many of us type at 20+ characters a second.

I really wouldn't worry about it. To my knowlegde, DirectInput just sat an interface on top of the standard message system for keyboard input anyway (do correct me if that's wrong) so you would have had the same problem with that.
delta user
delta user
There will be no problem. Every windows message gets queued. You just need to loop through every message at each frame. (GetMessage() or PeekMessage() functions to read the next message in the queue.)

Someone who uses a, euhm..., delta!?
Mastaba
Mastaba
The solution is simple, toss DirectInput for keyboard and mouse input entirely and just process WM_INPUT messages. (If you don't mind limiting the OS to WinXP or later).
delta user
delta user
thats true. the best combination is WM_CHAR and WM_KEYDOWN/UP. But in some occasions you would also need WM_SYSKEYDOWN/UP ( if you want to check if alt or some other system key is pressed).
Someone who uses a, euhm..., delta!?
Sc4Freak
Sc4Freak
Quote:
Original post by delta user
There will be no problem. Every windows message gets queued. You just need to loop through every message at each frame. (GetMessage() or PeekMessage() functions to read the next message in the queue.)


Ah, ok. That's good.

Thanks, everybody!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.