|
-
Dec 9th, 2004, 08:19 AM
#1
Thread Starter
Member
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.
Last edited by Tr_; Dec 9th, 2004 at 08:31 AM.
-
Dec 9th, 2004, 08:23 AM
#2
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
-
Dec 9th, 2004, 08:25 AM
#3
Thread Starter
Member
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.
-
Dec 9th, 2004, 10:28 AM
#4
Ex-Super Mod'rater
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?
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Dec 9th, 2004, 10:39 AM
#5
Thread Starter
Member
Re: VB: Drawing in a game
Yes the game uses DirectX.
-
Dec 9th, 2004, 11:27 AM
#6
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.
-
Dec 9th, 2004, 11:32 AM
#7
Thread Starter
Member
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 , I don't know how.
-
Dec 10th, 2004, 12:55 PM
#8
Thread Starter
Member
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
-
Dec 10th, 2004, 12:59 PM
#9
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.
-
Dec 10th, 2004, 01:56 PM
#10
Thread Starter
Member
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 .
-
Dec 10th, 2004, 02:06 PM
#11
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.
-
Dec 10th, 2004, 02:23 PM
#12
Thread Starter
Member
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 .
-
Dec 10th, 2004, 02:27 PM
#13
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
Last edited by Jacob Roman; Dec 10th, 2004 at 02:31 PM.
-
Dec 10th, 2004, 02:30 PM
#14
Thread Starter
Member
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
-
Dec 10th, 2004, 02:32 PM
#15
Re: VB: Drawing in a game
I edited my post and gave you a couple solutions
-
Dec 10th, 2004, 02:44 PM
#16
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.
-
Dec 10th, 2004, 02:59 PM
#17
PowerPoster
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.
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Dec 10th, 2004, 03:02 PM
#18
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.
-
Dec 10th, 2004, 03:09 PM
#19
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.
Last edited by Jacob Roman; Dec 10th, 2004 at 03:13 PM.
-
Dec 10th, 2004, 03:15 PM
#20
Thread Starter
Member
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.
-
Dec 10th, 2004, 03:19 PM
#21
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.
-
Dec 10th, 2004, 05:18 PM
#22
Thread Starter
Member
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?
-
Dec 10th, 2004, 05:29 PM
#23
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.
-
Dec 10th, 2004, 05:37 PM
#24
Thread Starter
Member
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 .
-
Dec 10th, 2004, 05:39 PM
#25
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.
-
Dec 10th, 2004, 05:40 PM
#26
Thread Starter
Member
Re: VB: Drawing in a game
yes but the address of the backbuffer would be different in every game.
-
Dec 10th, 2004, 05:44 PM
#27
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...
-
Dec 10th, 2004, 05:48 PM
#28
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?
Last edited by Jacob Roman; Dec 10th, 2004 at 05:53 PM.
-
Dec 10th, 2004, 07:20 PM
#29
PowerPoster
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.
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Dec 11th, 2004, 10:13 AM
#30
Thread Starter
Member
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
-
Dec 11th, 2004, 05:01 PM
#31
PowerPoster
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.
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Jan 7th, 2005, 12:53 PM
#32
New Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|