-
VB: Drawing in a game
Hi, Im trying to display a text message inside a game, it works but it flickers real bad. Programs like FRAPS or XFIRE also draw inside a game but then without the flickering. Whats the best way to make this kind function without the text flickering all the time? The one that Im using now (which flickers) is this one:
Code:
Public Function DrawText(hwnd As Long, strText As String, x As Long, y As Long)
Dim hDC As Long
hDC = GetDC(hwnd)
If hDC = 0 Then Exit Function
SetBkMode hDC, vbTransparent 'Transparent background
SetTextColor hDC, 0 'Textcolor to black
TextOut hDC, x + 1, y + 1, strText, Len(strText) 'Make shadow
TextOut hDC, x + 2, y + 2, strText, Len(strText) 'Make shadow
SetTextColor hDC, RGB(0, 255, 0) 'Set text color to green
TextOut hDC, x, y, strText, Len(strText) 'Write the text
UpdateWindow hwnd
ReleaseDC hwnd, hDC
End Function
Thanks.
-
Re: Drawing in a game
Basically, you need a backbuffer. You do the drawing to this buffer and when all is ready for the next displaying, you copy the backbuffer contents to the screen. Then reset the backbuffer and draw stuff on it again and so on :)
-
Re: Drawing in a game
That would involve using DirectX right? Just to make clear, the game that I want to write my text to is not my own game. It's an other program window I want to write to.
-
Re: VB: Drawing in a game
You don't need to use DirectX to use a backbuffer, if your game was based on BitBlt then using an OffscreenDC as the back buffer would be fine, that way the screen gets updated with one BitBlt rather than several.
Seen as though this isn't your own game will make things more difficult, do yuo know how the other game is working? Like does it use DirectX?
-
Re: VB: Drawing in a game
Yes the game uses DirectX.
-
Re: VB: Drawing in a game
I remember this issue been discussed before. I just can't remember how long time ago it was (many many months atleast) nor I can't remember any keywords so I could find it easily. Anyways, I remember that doing it properly would mean understanding the game very well, interrupting the game's code before it refreshes the screen, adding your own stuff and then letting the game update. Very hard stuff to do.
-
Re: VB: Drawing in a game
no I dont think so, I know what you mean Merri but Xfire and FRAPS have a general routine for it so it will work with any DirectX game so it's possible to do it without gamehacking. That's just the whole problem :bigyello:, I don't know how.
-
Re: VB: Drawing in a game
is it possible to make some kind of overlay window without actually drawing in the fullscreen DirectX game but so you can still see the overlay window?? Or am I talking crazy now :afrog:
-
Re: VB: Drawing in a game
I have this same problem. It works fine on certain video cards, but doesn't work well on others since it flickers. Why does the text flicker when you use certain video cards? At first I thought it was the OS you were using. It worked fine on Windows ME, but on XP and XP Pro, the text flickered. That was until I tried my program out in a computer lab in school. They have XP and the text didn't flicker. So now I know it depends on the card you are using.
-
Re: VB: Drawing in a game
It doesnt depend on that completely because other programs which use a certain technique like that dont have text that flickers, even with my videocard. Its just a matter of finding the right technique but Im stuck on that area :(.
-
Re: VB: Drawing in a game
How about puting all the text onto one polygon surface. That way there, when you use DrawPrimitive (or DrawPrimitiveUP if it's a TLVertex), it should work. If you are using DirectDraw though, same concept, only puting it on a surface and using Blt or BltFast.
-
Re: VB: Drawing in a game
Maybe you didnt read the part about the application I want to write the text to is not mine, because what youre saying isnt possible I think unless the game is your own and youre writing the code directly into it. If not, I dont understand :bigyello: .
-
Re: VB: Drawing in a game
You didn't know you can draw anything onto a polygon surface! Even text! Obviously you didn't understand at all what I was saying. But by doing that and drawing the polygon in the rendering loop, theoretically the problem should be solved. I don't have VB in front of me right now to test it. I'm in college.
Also, you messed up in your code. You are doing Windows GDI in a DirectX application. Big no no there. It's like using BitBlt in a DirectX app.
Here's the solution to your problem on drawing text in a DirectX8 app
if you are using DirectX8:
http://216.5.163.53/DirectX4VB/Tutor...R_Lesson06.asp
If it's not and is DirectX7 instead:
http://216.5.163.53/DirectX4VB/Tutor...D_DrawText.asp
-
Re: VB: Drawing in a game
Im sorry, Im not really into this, I can do a lot in VB but working with graphics is all new to me :(
-
Re: VB: Drawing in a game
I edited my post and gave you a couple solutions ;)
-
Re: VB: Drawing in a game
Here's the reason why yours is flickering. Let's say this is your rendering loop:
Clear the screen
Draw Text
Update Window (You now see text)
DirectX drawing
Backbuffer surface blits to primary surface. (You now see DirectX Graphics and Text has disappeared)
Repeat this over and over and you will now see that Windows GDI cannot blend with DirectX because it flickers.
-
Re: VB: Drawing in a game
Hes trying to inject text into the DC of a games Surface that he didn't write. A game which is compiled and running in the background I assume.
What you are trying to write is a technical hack...Sorta speak.
I must first say it is IMPOSSIBLE for a program to inject text into ANY DirectX program without exception. Cannot be done.
You must know the memory address of the backbuffer surface, from that you will be able to derive the DC which you could blt to and inturn effect the game.
You can't just inject text into a games thread and expect to see it on screen.
I aint exactly sure wut u r attempting but if you got as far as having it flickerin on the game screen while focused on the game then you are doing great.
Truly I believe you are lost and are attempting something you aint ready for.
-
Re: VB: Drawing in a game
Yeah I was about to tell him that he can't do that unless he knows the memory location of the backbuffer, but he just said that working with graphics on VB is very new to him. So this is all Greek to him.
-
Re: VB: Drawing in a game
My advice to Tr_ is to not jump into the DirectX bandwagon until you have some knowledge and experience on working with graphics and know how it works. Start off small and work your way up. That's what I did.
-
Re: VB: Drawing in a game
k guys, download this free program http://www.fraps.com/download.htm, run it and then start your favourite (fullscreen) game, youll see some text appear in a corner which measures your FPS. I dont think that FRAPS reads the base of every DirectX surface from a game and then makes some kind of hack to display something on that screen. I Also know the FPS rate you see when FRAPS is running isnt really text but images used as numbers drawn on the screen. Maybe you are right that its difficult, but not impossible to make such a thing.
-
Re: VB: Drawing in a game
Whoever made FRAPS knows the memory location of the backbuffer and was able to put their text in there. Theoretically speaking of course.
-
Re: VB: Drawing in a game
Well I think Ive discovered something new. The text from the program FRAPS is not being written to the hDC I think but to some kind of new window layer on top of the actual game window. So that means the text is being written to an other window. Weird theory or is this possible?
-
Re: VB: Drawing in a game
I never said the hDC. I said the backbuffer in memory. They were able to get the memory location of the backbuffer and blit stuff onto that.
-
Re: VB: Drawing in a game
well u get what Im trying to say right? anyway I dont understand how you could get the memory location for a backbuffer for every single game. Since gamehacking is complicated I think thats a bit impossible to make it work for every single game :s. Anyway no-one seems to know a solution, too bad :(.
-
Re: VB: Drawing in a game
You don't need to know the backbuffer of every single game. There should be only one backbuffer in memory. Not more than one...I don't think. I could be wrong. The backbuffer in memory I believe is on the video card in some chip. I'm not a hardware kinda guy but I heard it's on that.
-
Re: VB: Drawing in a game
yes but the address of the backbuffer would be different in every game.
-
Re: VB: Drawing in a game
I don't know about that. There should be only one address to the backbuffer. Back in the mid or early 90's before DX, they accessed mode 13 mode(&H13) for video card stuff as well as fullscreen apps. I'm not sure if DX does the same thing. I'll do a Google search on it...
-
Re: VB: Drawing in a game
Yeah, I was close. Mode 13 for VGA cards only had resolutions of 320×200×8 and 320×240×8. But there's also Mode X, which I'm not too familiar with. Here's where I saw it:
http://msdn.microsoft.com/archive/de...dover_82bb.asp
And they said this on Mode X:
Mode X modes are available only if an application uses the DDSCL_ALLOWMODEX, DDSCL_FULLSCREEN, and DDSCL_EXCLUSIVE flags when calling the IDirectDraw7::SetCooperativeLevel method. If DDSCL_ALLOWMODEX is not specified, the IDirectDraw7::EnumDisplayModes method will not enumerate Mode X modes, and the IDirectDraw7::SetDisplayMode method will fail if a Mode X mode is requested.
The question is though, what is the memory location for Mode X?
-
Re: VB: Drawing in a game
To solve:
To draw text onto anything you need the hDc unless it has function written to do it for you like Dx.
The memory address of the backbuffer will be different everytime, even if you store it on the video card.
That program, chances are you are right. It is overlapping a window overtop of the game...Transparent window. It then has its own individual timer which it simply measures with howfast your comp can do the game before the thread pointer hits your app and process's the timer....So it can't be 100% accurate.
I doubt it is possible for it to hijack ANY games backbuffer and Timer.
-
Re: VB: Drawing in a game
Well, I dont necessarily need to know how its done in FRAPS but how I can do it. If the way of making a transparent window on top of the game is possible, does anyone have some code snippets, because Im really stuck here :(
-
Re: VB: Drawing in a game
Google search for transparent windows.
Google search for it all.
Aint no one goona give away code to do what FRAPS does.
Nor will anyone in these forums give away hacks.
-
Re: VB: Drawing in a game
Sirs, you may want to check out http://www.proxy.mikoweb.de
Although it is not VB (but VC), it might give you an impression of how the task in question could probably be done...
yours
miko