Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


How many APIs are for drawing text?


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
15 replies to this topic

#1 aj3423   Members   -  Reputation: 108

Like
0Likes
Like

Posted 25 July 2014 - 04:05 AM

Hi, I wanna hook a DX game's text output, it uses d3dx9_35.dll. I'm not good at DirectX,  the game looks like:

 

qnyh_zpsb1845a78.png

 

I hooked D3DXCreateFontA/W, D3DXCreateFontIndirectA/W , they are not called. And the GDI api TextOutA/W DrawTextA/W are not used either. The game is not protected, I can debug it with OllyDbg, I add breakpoints to these functions, never breaks. So how does the game draw text?

 

Thanks.



Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 8758

Like
0Likes
Like

Posted 25 July 2014 - 04:35 AM

All the D3DX stuff is just wrappers around the native D3D calls, so eventually everything boils down to one of the following:

  • DrawPrimitive
  • DrawPrimitiveUP
  • DrawIndexedPrimitive
  • DrawIndexedPrimitiveUP

They're the APIs that will be used, but that means that you're not going to have an easy way (or even any way) of determining whether one of these is used for drawing text or for drawing something else.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 Tom KQT   Members   -  Reputation: 1633

Like
0Likes
Like

Posted 25 July 2014 - 04:45 AM

"Render a text" will most probably mean "reander a vertex buffer (small quads, one of each letter) with a texture". The texture contains all the necessary chars. So you can try to look for that. Is the texture pre-made with all possible chars (can you find it somewhere in the game assets)? Is it made when the application starts and the letters are somehow drawn in it? Or is it changed even when the application runs if the text needs new letters (Btw I think the last variant is what D3DXFont does).



#4 cozzie   Members   -  Reputation: 2071

Like
0Likes
Like

Posted 25 July 2014 - 05:44 AM

you could also contact the developer/ studio and ask

(note; not as a joke/ sarcastic)



#5 aj3423   Members   -  Reputation: 108

Like
0Likes
Like

Posted 25 July 2014 - 09:00 AM

Thanks guys
 
to mhagain:
    I'll try that when I get back.
 
to Tom KQT:
    Do you mean the API like D3DXCreateText / D3DXCreateTexture ?
 
to cozzie:
    :)


#6 DvDmanDT   GDNet+   -  Reputation: 1193

Like
0Likes
Like

Posted 25 July 2014 - 09:47 AM

Is that Japanese? If so, doesn't it have tons of "characters"/symbols? As far as I know, the ID3DXFont etc just creates a spritefont from the parameters and uses it, which I can imagine would be impractical for some languages since the spritesheet would be huge. I could very well be wrong here though, I've never worked with anything that couldn't fit in ISO8859-1.. 

 

Are you sure it's not just prerendered?



#7 Necrolis   Members   -  Reputation: 1384

Like
2Likes
Like

Posted 26 July 2014 - 08:25 AM

In a slightly more generalized answer: If you can attach PIX then that will help track down any specific DX API call used to perform an operation or render (as it gives you a breakdown of DX calls in a frame along with a before and after of the state and rendered frame -- in the frame capture mode). It will also help in debugging any issues you might have (though unfortunately MS saw fix to break PIX with a certain Win7 patch...). The various GPU vendors also provide similar free tools (NSight for nVidia, GPUPerfStudio for AMD and GPA for Intel).

 

The game might possibly call D3DPERF_SetOptions() to disable PIX, but its very easy to NOP/remove.


Edited by Necrolis, 26 July 2014 - 08:29 AM.


#8 Jason Z   Crossbones+   -  Reputation: 5812

Like
0Likes
Like

Posted 26 July 2014 - 11:03 AM

You can also do the same with the Graphics Debugger if PIX is indeed unavailable to you.



#9 aj3423   Members   -  Reputation: 108

Like
0Likes
Like

Posted 29 July 2014 - 09:48 PM

If you can attach PIX then that will help track down any specific DX API call used to perform an operation or render

Thanks, I tried PIXWin, it works. The game calls SetTexture -> SetStreamSource -> DrawIndexedPrimitive to draw the text

 

I can see the Mesh, VertexBuffer and some other visual information from PIXWin, but I don't see any relationship between these stuff and the text being drawn.  So I tried to analyze the Text3D from DirectX examples, because it uses ID3DXFont::DrawText to draw this red string(on the first image), and may be I can find the how the underlying things are done.

 

I captured one frame of Text3D, opened in PIXWin, it draws this line first:

d3d_drawtext_zpsbe53bd92.png

 

and here's the call of DrawText:

 

pixwin1_zps73622b22.png

 

I checked all the functions in the call tree,  0x010016F8 is never used, why?  maybe I missed something?

Thanks.


Edited by aj3423, 29 July 2014 - 09:50 PM.


#10 SimonForsman   Crossbones+   -  Reputation: 6518

Like
0Likes
Like

Posted 30 July 2014 - 12:32 AM

I checked all the functions in the call tree,  0x010016F8 is never used, why?  maybe I missed something?
Thanks.


0x010016F8 is a pointer to a string, no direct3d function operates on strings so the d3dx drawtext function should use the string and font data to calculate the values it passes to the other functions.
I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#11 aj3423   Members   -  Reputation: 108

Like
0Likes
Like

Posted 30 July 2014 - 01:00 AM

 

I checked all the functions in the call tree,  0x010016F8 is never used, why?  maybe I missed something?
Thanks.


0x010016F8 is a pointer to a string, no direct3d function operates on strings so the d3dx drawtext function should use the string and font data to calculate the values it passes to the other functions.

 

Inside the function drawtext, I guess when It calculates each vertex of the string, it should reference to the memory address.  But in which step is the calculation done?



#12 aj3423   Members   -  Reputation: 108

Like
0Likes
Like

Posted 31 July 2014 - 01:30 AM

I checked he Text3d demo, debugging it with IDA Pro, in function DrawText it calls ScriptPlace/ScriptShape and ExtTextOut, I guess it uses these function to calculate each pixel of text string. But the real game never uses these function, what function could the game possibly use to do the calculation?



#13 mhagain   Crossbones+   -  Reputation: 8758

Like
0Likes
Like

Posted 31 July 2014 - 01:57 AM

I checked he Text3d demo, debugging it with IDA Pro, in function DrawText it calls ScriptPlace/ScriptShape and ExtTextOut, I guess it uses these function to calculate each pixel of text string. But the real game never uses these function, what function could the game possibly use to do the calculation?

 

It's unlikely that it uses any D3D function for this.  The work will be done on the CPU, so what it will do is something like use the string to calculate a list of positions and texture coords, then lock the vertex buffer, memcpy the list across, then unlock.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#14 aj3423   Members   -  Reputation: 108

Like
0Likes
Like

Posted 31 July 2014 - 02:11 AM

 

I checked he Text3d demo, debugging it with IDA Pro, in function DrawText it calls ScriptPlace/ScriptShape and ExtTextOut, I guess it uses these function to calculate each pixel of text string. But the real game never uses these function, what function could the game possibly use to do the calculation?

 

It's unlikely that it uses any D3D function for this.  The work will be done on the CPU, so what it will do is something like use the string to calculate a list of positions and texture coords, then lock the vertex buffer, memcpy the list across, then unlock.

Exactly, what API(s) could be used to do the calculation, except the ScriptPlace/ScriptShape/ExtTextOut.


Edited by aj3423, 31 July 2014 - 02:11 AM.


#15 mhagain   Crossbones+   -  Reputation: 8758

Like
0Likes
Like

Posted 31 July 2014 - 05:20 PM

 

 

I checked he Text3d demo, debugging it with IDA Pro, in function DrawText it calls ScriptPlace/ScriptShape and ExtTextOut, I guess it uses these function to calculate each pixel of text string. But the real game never uses these function, what function could the game possibly use to do the calculation?

 

It's unlikely that it uses any D3D function for this.  The work will be done on the CPU, so what it will do is something like use the string to calculate a list of positions and texture coords, then lock the vertex buffer, memcpy the list across, then unlock.

Exactly, what API(s) could be used to do the calculation, except the ScriptPlace/ScriptShape/ExtTextOut.

 

 

It's likely that no APIs are used to do the calculation.  Instead it's just regular arithmetic operators: +, -, *, /, and some array lookups, followed by a memcpy.

 

For example, one way of drawing text might be to store the characters in a texture with 16 rows and 16 columns.  That gives enough for 256 characters, so we're assuming a standard extended ASCII character set, but the principle will be the same for other character sets.  The integer equivalent of each character (space = 32, A = 65, B = 66, etc) is used to look up an array which supplies the texture coords to use for that character (this can also be done with math).  This and the positions are then copied out to an array of structs that looks something like:

 

struct textchar

{

    float position[2];

    float texcoord[2];

};

 

The array is sized large enough for the string being drawn.  When we reach the end of the string the vertex buffer is locked, the array is memcpyed in, the vertex buffer is unlocked, a draw call is issued.

 

In other words, no API is needed for this; it's not an API problem, it's a "do it yourself in C/C++" problem.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#16 aj3423   Members   -  Reputation: 108

Like
0Likes
Like

Posted 01 August 2014 - 05:02 AM

 

 

 

I checked he Text3d demo, debugging it with IDA Pro, in function DrawText it calls ScriptPlace/ScriptShape and ExtTextOut, I guess it uses these function to calculate each pixel of text string. But the real game never uses these function, what function could the game possibly use to do the calculation?

 

It's unlikely that it uses any D3D function for this.  The work will be done on the CPU, so what it will do is something like use the string to calculate a list of positions and texture coords, then lock the vertex buffer, memcpy the list across, then unlock.

Exactly, what API(s) could be used to do the calculation, except the ScriptPlace/ScriptShape/ExtTextOut.

 

 

It's likely that no APIs are used to do the calculation.  Instead it's just regular arithmetic operators: +, -, *, /, and some array lookups, followed by a memcpy.

 

For example, one way of drawing text might be to store the characters in a texture with 16 rows and 16 columns.  That gives enough for 256 characters, so we're assuming a standard extended ASCII character set, but the principle will be the same for other character sets.  The integer equivalent of each character (space = 32, A = 65, B = 66, etc) is used to look up an array which supplies the texture coords to use for that character (this can also be done with math).  This and the positions are then copied out to an array of structs that looks something like:

 

struct textchar

{

    float position[2];

    float texcoord[2];

};

 

The array is sized large enough for the string being drawn.  When we reach the end of the string the vertex buffer is locked, the array is memcpyed in, the vertex buffer is unlocked, a draw call is issued.

 

In other words, no API is needed for this; it's not an API problem, it's a "do it yourself in C/C++" problem.

 

Seems lots of game uses freetype2 + .ttc file, now I know how it works.

Thanks a lot.






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