LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   D3D Crosshair? (https://www.linuxquestions.org/questions/programming-9/d3d-crosshair-370028/)

InvisibleSniper 10-05-2005 11:19 AM

D3D Crosshair?
 
Hi again,

Just wondering is someone could give me some info on how to make a D3D crosshair in a 3D video game. This is not for cheating or anything like that... it is just for practice, in single player.

Thanks Again :)

Mega Man X 10-06-2005 05:09 AM

In what game? You mean a game from scratch? That could take a while. Maybe a few thousand lines just to create a window, initialize DX, handle inputs and load graphics...

If you just wanna know how it works, the concept of a crosshair is simple though: Simply set the mouse cursor to invisible, load an image with the cross-hair and let that be your "new" mouse cursor. Usually, it's done with a small image, where everything is black (or any other color, actually) but the cursor itself. You then tell DX to ignore the color at position 0,0 of the image, so only the actual cursor is displayed.

If you really want an example, download DX SDK. It comes with a few examples, but I highly doubt somebody would be kind enough to write thousand of lines to show how a cross-hair works :)

Viper-Inc 10-06-2005 05:40 AM

i think he just wants to replace the game crosshair (the gun crosshair to where you are aiming) with something else.

like a cross +
or a O with a dot in it
or just a dot.

i myself do not know how to do this and will be interested in hearing of how to do it as i have wondered this for quite some time.

geeman2.0 10-06-2005 08:43 AM

If you're trying to mod an existing closed source video game to do this then the solution is likely very complex and highly dependent on which particular game this is.

InvisibleSniper 10-06-2005 09:39 AM

Quote:

Originally posted by Viper-Inc
i think he just wants to replace the game crosshair (the gun crosshair to where you are aiming) with something else.

like a cross +
or a O with a dot in it
or just a dot.

i myself do not know how to do this and will be interested in hearing of how to do it as i have wondered this for quite some time.

Yes, that's what I ment... I am not making a game from scratch I would like this for an already made game in single player mode. I would just like to make a customized crosshair that is different to the in game one just an X or T with a little dot in the middle of it would be good. Anyway the game is battlefield2.

Mega Man X 10-07-2005 12:34 PM

I see. So technically speaking, this has really nothing to do with programming :). And as geeman2.0, this kind of modification really depends of the game. As an example, Doom 3 core files are packed in .pak files. You can rename those files to .zip (or was it .rar), uncompress them, change whatever you want and repack them. That's pretty much the way every gun mod is done for Doom 3.

I've no experience creating mods. Just a little creating maps for Unreal Engine, so I'm not in a position to help or advice you with Battlefield. I would advice you searching google for tutorials modding Battlefield.

Regards!

InvisibleSniper 10-07-2005 11:59 PM

What I really wanted to do was use D3D to add a crosshair, I know this is possible but I do not know how to do it. In other words, have my custom made D3D crosshair follow the in game crosshair moving as I move.

Isn't there some D3D functions that can inject code into the game? I basically want to write over the game's original crosshair with my own(different colour, different shape).

deiussum 10-08-2005 01:29 AM

D3D is a graphics API. It is not an API to "inject code into games." There are only a few ways off the top of my head that I could think of that what you want would be possible.
  • Download the BF2 mod tools and use those to change the graphics that the game itself loads from. I haven't really done much with these tools myself except to look at them briefly, so I'm not sure how you would do what you want offhand.
  • Create a separate D3D app with a window that would somehow sit on top of all other windows to display the crosshair. This seems pretty ugly and not even guaranteed to work with BF2 running fullscreen.
  • Put a piece of scotch tape in the middle of your monitor and draw your crosshair. :)

One other problem is that BF2 uses Punkbuster. So... if you try and use this on a server with Punkbuster enabled (and I believe all ranked servers have to enable Punkbuster) and you have modified your game files using the first method, I'm guessing that you would get kicked.

The_Nerd 10-10-2005 12:25 AM

I don't know about battlefield2, but if it uses the quake3 (or any ID engine), you can:

goto the folder base(q3, q3, something "base") and you'll find a base*.pk* (or *.pak). Rename this to base*.zip. Open it, and look for the crosshair .tga's. They are probably in the Sprites, or Grapics/SFX folder. When you locate them, find the crosshair that is the one you want to change in the game. Make a note of the location of the crosshair (the path + the filename), e.g. sprites/crosshairs/mycross.tga, and then use a program like The GIMP (www.gimp.org) to make your own crosshair. After you're finished with your crosshair, create a new pak file of your own called "mycrosshair.pk* (.pak)) and compress your crosshair.tga file into it with the same path and same name. It will then have replaced the crosshair with your own.

Here, I'll use quake3 as an example:

(1): Goto C:\program files\quake III Arena\baseq3
(2): Rename pak0.pk3 to pak0.zip (you may have to tell windows to show file extensions)
(3): Open pak0.zip with your fav' archiving program (WinZIP, WinRAR, etc...)
(4): In the archiving program, browse to the folder, gfx/2d/
(5): You will now see a few TARGA (.tga) images. The one we will focus on is "crosshaira.tga"
(6): Select and extract "crosshaira.tga", and open it with The GIMP or Photoshop
(7): Edit it to suit your needs
(8): Create a folder called "gfx"
(9): Browse into the newly created folder called "gfx" and create another folder called "2d"
(10): Save your image into this "2d" folder
(11): Create a new archive called "mycross.zip" and compress the "gfx" folder into it
(12): Rename "mycross.zip" to "mycross.pk3" and place it into the "baseq3" folder.
(13): Luanch the game and enjoy your new crosshair!


That is how it is done for Quake3. It will be almost the same thing for any ID engine. If it is some other 3D engine (like Unreal, or Halflife), then you'll have to get their custom archiving tools. But in the end, it is still really just the same thing.

Good luck!

Note: Punkbuster and other cheat detecting programs might see this change as a cheat, and therefor you might be kicked out of servers.

deiussum 10-10-2005 12:35 AM

BF2 doesn't use the Q3 engine. I believe it is an all new engine that Dice developed.


All times are GMT -5. The time now is 08:21 AM.