Results 1 to 9 of 9

Thread: text with directx

  1. #1

    Thread Starter
    Member Usako's Avatar
    Join Date
    May 2001
    Posts
    60

    text with directx

    ^_^ I'm busy learning c++ and directdraw now and it's working quite well (already got some sort of isometric map thingy working ^_^). Anyway, I was wondering how to print some text in a full screen directx program because I can't find anything about this and when I try to use something like:

    lpddsBack->DrawText(0,0,"Hello",false);

    it gives some 'DrawTextA is not a member of 'IDirectDrawSurface7' etc.'

    Any hints?

    And how do you randomize the timer? (got some random world generator that generates the same random world over and over again )

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    For the random one, call srand(time(NULL)) at the start of your program (and only then).

    No idea about the DX one. Perhaps MSDN can help?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Member Usako's Avatar
    Join Date
    May 2001
    Posts
    60
    thanks alot for that random thingy ^_^.

    I got the help file that came with the SDK but it only shows how to do it in VB (atleast I think )

  4. #4

    Thread Starter
    Member Usako's Avatar
    Join Date
    May 2001
    Posts
    60
    heh, I first got an error but then I added time.h and it worked.

    Thanks

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Yep, there's definitely a C++ one - found it!
    D3DXCreateFont
    Creates a font object for a device and font.

    HRESULT D3DXCreateFont(
    LPDIRECT3DDEVICE8 pDevice,
    HFONT hFont,
    LPD3DXFONT* ppFont
    );

    Parameters
    pDevice
    [in] Pointer to an IDirect3DDevice8 interface, the device to be associated with the font object.
    hFont
    [in] Handle to the font object.
    ppFont
    [out] Returns a pointer to an ID3DXFont interface, representing the created font object.
    Return Values
    If the function succeeds, the return value is D3D_OK.

    If the function fails, the return value can be one of the following values
    ID3DXFont
    The ID3DXFont interface is used to encapsulate the textures and resources needed to render a specific font on a specific device.

    The ID3DXFont interface is obtained by calling the D3DXCreateFont or D3DXCreateFontIndirect functions.

    The methods of the ID3DXFont interface can be organized into the following groups.

    Drawing Begin
    DrawTextA
    DrawTextW
    End
    Information GetDevice
    GetLogFont
    ID3DXFont:rawTextA
    Draws formatted ANSI text on a Microsoft® Direct3D® device.

    INT DrawTextA(
    LPCSTR pString,
    INT Count,
    LPRECT pRect,
    DWORD Format,
    D3DCOLOR Color
    );

    Parameters
    pString
    [in] Pointer to the ANSI string to draw. If the Count parameter is –1, the string must be null-terminated.
    If Format includes DT_MODIFYSTRING, the function could add up to four additional characters to this string. The buffer containing the string should be large enough to accommodate these extra characters.

    Count
    [in] Specifies the number of characters in the string. If Count is –1, then the pString parameter is assumed to be a pointer to a null-terminated string and DrawTextA computes the character count automatically.
    pRect
    [in] Pointer to a RECT structure that contains the rectangle, in logical coordinates, in which the text is to be formatted.
    Format
    [in] Specifies the method of formatting the text. It can be any combination of the following values.
    DT_BOTTOM
    Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.
    DT_CALCRECT
    Determines the width and height of the rectangle. If there are multiple lines of text, DrawTextA uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawTextA modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawTextA returns the height of the formatted text but does not draw the text.
    DT_CENTER
    Centers text horizontally in the rectangle.
    DT_EDITCONTROL
    Duplicates the text-displaying characteristics of a multiline edit control. Specifically, the average character width is calculated in the same manner as for an edit control, and the function does not display a partially visible last line.
    DT_END_ELLIPSIS or DT_PATH_ELLIPSIS
    Truncates the string without adding ellipses so that the result fits in the specified rectangle. The string is not modified unless the DT_MODIFYSTRING flag is specified.
    Specify DT_END_ELLIPSIS to truncate characters at the end of the string, or DT_PATH_ELLIPSIS to truncate characters in the middle of the string. If the string contains backslash (\) characters, DT_PATH_ELLIPSIS preserves as much of the text as possible after the last backslash.

    DT_EXPANDTABS
    Expands tab characters. The default number of characters per tab is eight. The DT_WORD_ELLIPSIS, DT_PATH_ELLIPSIS, and DT_END_ELLIPSIS values cannot be used with the DT_EXPANDTABS value.
    DT_EXTERNALLEADING
    Includes the font external leading in line height. Normally, external leading is not included in the height of a line of text.
    DT_HIDEPREFIX
    Windows 2000: Ignores the ampersand (&) prefix character in the text. The letter that follows is not underlined, but other mnemonic-prefix characters are still processed.
    Example:

    input string: "A&bc&&d"

    normal: "Abc&d"

    HIDEPREFIX: "Abc&d"

    Compare with DT_NOPREFIX and DT_PREFIXONLY.

    DT_INTERNAL
    Uses the system font to calculate text metrics.
    DT_LEFT
    Aligns text to the left.
    DT_MODIFYSTRING
    Modifies the string to match the displayed text. This flag has no effect unless the DT_END_ELLIPSIS or DT_PATH_ELLIPSIS flag is specified.
    DT_NOCLIP
    Draws without clipping. DrawTextA is somewhat faster when DT_NOCLIP is used.
    DT_NOFULLWIDTHCHARBREAK
    Windows 98, Windows 2000: Prevents a line break at a DBCS (double-wide character string), so that the line breaking rule is equivalent to SBCS strings. For example, this can be used in Korean windows for more readability of icon labels. This is effective only if DT_WORDBREAK is specified.
    DT_NOPREFIX
    Turns off processing of prefix characters. Normally, DrawTextA interprets the mnemonic-prefix character & as a directive to underscore the character that follows, and the mnemonic-prefix characters && as a directive to print a single &. By specifying DT_NOPREFIX, this processing is turned off. Compare with DT_HIDEPREFIX and DT_PREFIXONLY.
    DT_PREFIXONLY
    Windows 2000: Draws only an underline at the position of the character following the ampersand (&) prefix character. Does not draw any character in the string.
    Example:

    input string: "A&bc&&d"

    normal: "Abc&d"

    PREFIXONLY: " "

    Compare with DT_NOPREFIX and DT_HIDEPREFIX.

    DT_RIGHT
    Aligns text to the right.
    DT_RTLREADING
    Displays text in right-to-left reading order for bi-directional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.
    DT_SINGLELINE
    Displays text on a single line only. Carriage returns and line feeds do not break the line.
    DT_TABSTOP
    Sets tab stops. Bits 15–8 (high-order byte of the low-order word) of the Format parameter specify the number of characters for each tab. The default number of characters per tab is eight. The DT_CALCRECT, DT_EXTERNALLEADING, DT_INTERNAL, DT_NOCLIP, and DT_NOPREFIX values cannot be used with the DT_TABSTOP value.
    DT_TOP
    Top-justifies text (single line only).
    DT_VCENTER
    Centers text vertically (single line only).
    DT_WORDBREAK
    Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.
    DT_WORD_ELLIPSIS
    Truncates text that does not fit in the rectangle and adds ellipses.
    Color
    [in] D3DCOLOR type, specifying the color of the text.
    Return Values
    If the method succeeds, the return value is D3D_OK.

    If the method fails, the return value can be one of the following values.

    D3DERR_INVALIDCALL
    D3DERR_NOTAVAILABLE
    D3DERR_OUTOFVIDEOMEMORY
    D3DXERR_INVALIDDATA


    Remarks
    DrawText maps to either DrawTextA or ID3DXFont:rawTextW, depending on the inclusion or exclusion of the #define UNICODE switch. Include or exclude the #define UNICODE switch to specify whether your application expects Unicode or ANSI strings. The following code fragment shows how DrawText is defined.

    #ifndef DrawText
    #ifdef UNICODE
    #define DrawText DrawTextW
    #else
    #define DrawText DrawTextA
    #endif
    #endif

    The DrawTextA method uses the device context's selected font, text color, and background color to draw the text. Unless the DT_NOCLIP format is used, DrawTextA clips the text so that it does not appear outside the specified rectangle. All formatting is assumed to have multiple lines unless the DT_SINGLELINE format is specified.

    If the selected font is too large for the rectangle, the DrawTextA method does not attempt to substitute a smaller font.

    The DrawTextA method supports only fonts whose escapement and orientation are both zero.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6

    Thread Starter
    Member Usako's Avatar
    Join Date
    May 2001
    Posts
    60
    isn't that Direct3d? Gonna try it out tomorrow anyway so thanks .

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    It's DirectX Graphics (from DirectX 8.0). I think it's basically ONLY Direct3D now, with a few helper libraries for 2D graphics.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8

    Thread Starter
    Member Usako's Avatar
    Join Date
    May 2001
    Posts
    60
    I'm using Directx7 now (I was used to it in vb so I thought I would be best of learning that first in c++) ^_^.

    Maybe I'll try to 'learn' Directx8 later but now I first want to get some sort of feeling for c++ so I don't have to think what everything does again ^_^ (still stuck in my vb mind )

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I don't think there is a text drawing function for DirectDraw, you use the Win API TextOut instead. Use IDirectDrawSurface4->GetDC to retrieve the necessary device context, set text color and such things, draw the text, and don't forget to release the context.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width