Sign in to follow this  

converting directX to c++

This topic is 4692 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I have done some directx7 programs using VB and want to see if they can be converted to C++ easy enough. I know directX7 has several ways of doing the same thing but I will start with what I know for now. I am not asking for people to translate for me but I want to know is it possible to translate directX7 like this into c++ code directly (of course not using VB keywords in c++ like Set, Picture1.hwnd). 1)create a primary surface 'set up primary display surface Dim ddraw As DirectDraw7 Dim ddScreen As DirectDrawSurface7 Private PSSD As DDSURFACEDESC2 Private rScreen As RECT ddraw.SetCooperativeLevel Picture1.hWnd, DDSCL_NORMAL PSSD.lFlags = DDSD_CAPS PSSD.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE PSSD.lWidth = SCREENWIDTH PSSD.lHeight = SCREENHEIGHT Set ddScreen = ddraw.CreateSurface(PSSD) rScreen.Bottom = SCREENHEIGHT rScreen.Right = SCREENWIDTH rScreen.Top = 0 rScreen.Left = 0 2) 'create the back buffer Dim ddBackBuffer As DirectDrawSurface7 Private BBSD As DDSURFACEDESC2 Dim rBackBuffer As RECT BBSD.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT BBSD.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN BBSD.lWidth = SCREENWIDTH BBSD.lHeight = SCREENHEIGHT Set ddBackBuffer = ddraw.CreateSurface(BBSD) rBackBuffer.Bottom = SCREENHEIGHT rBackBuffer.Right = SCREENWIDTH rBackBuffer.Left = 0 rBackBuffer.Top = 0 3)'load the background image Dim ddBackground As DirectDrawSurface7 Private BGSD As DDSURFACEDESC2 Dim rBackground As RECT BGSD.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT BGSD.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN BGSD.lWidth = SCREENWIDTH BGSD.lHeight = SCREENHEIGHT Set ddBackground = ddraw.CreateSurfaceFromFile( _ "c:\vb_directx\directx\sprite2\blueyellow.bmp", BGSD) rBackground.Bottom = SCREENHEIGHT rBackground.Right = SCREENWIDTH rBackground.Left = 0 rBackground.Top = 0 ddBackBuffer.BltFast 0, 0, ddBackground, rBackground, _ DDBLTFAST_WAIT

Share this post


Link to post
Share on other sites
Can you clearify a bit. It's possible to translate most iterative(I think that's the word) Programming languages as well as Object Orriented language. But the code will be a bit harder to do probably.

C++ would likely take a much larger setup to do so. But it is possible.

I don't know how much experience you have with the system so I'm going to explain a bit of the more basics just to cover it all. Visual C++ while adaptive to most ideas it is more complex then most languages. Visual Basic on the other hand is almost simple compared to C++. I have yet to work with DirectX 7 or DirectX with Visual Basic (working mostly with pure VB, and DirectX 8 and 9 with Visual C++) But it takes a bit more to set up.

If you do have a basic understanding of C++ you shouldn't need too much work, though it appears to be different so it really depends what you're thinking what "Directly" means. but there's quite a bit more functions to use in C++.

Share this post


Link to post
Share on other sites
no your right I dont think it will take too much work. I have a c++ basic understanding althought the directX function calls has tested me...i dont think your meant to know how this works.

the directX c++ directdraw also has evolved over time in the sense you may see code with ddraw.h or other wrapper classes that seem different. that was confusing eg kust trying to load a bitmap from a file has a few ways to do it

Share this post


Link to post
Share on other sites
Quote:
Original post by jagguy
Hi

I have done some directx7 programs using VB and want to see if they can be converted to C++ easy enough. I know directX7 has several ways of doing the same thing but I will start with what I know for now.


I am not asking for people to translate for me but I want to know is it possible to translate directX7 like this into c++ code directly (of course not using VB keywords in c++ like Set, Picture1.hwnd).




1)create a primary surface
'set up primary display surface

Dim ddraw As DirectDraw7
Dim ddScreen As DirectDrawSurface7
Private PSSD As DDSURFACEDESC2
Private rScreen As RECT

ddraw.SetCooperativeLevel Picture1.hWnd, DDSCL_NORMAL
PSSD.lFlags = DDSD_CAPS
PSSD.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
PSSD.lWidth = SCREENWIDTH
PSSD.lHeight = SCREENHEIGHT
Set ddScreen = ddraw.CreateSurface(PSSD)
rScreen.Bottom = SCREENHEIGHT
rScreen.Right = SCREENWIDTH
rScreen.Top = 0
rScreen.Left = 0

2) 'create the back buffer

Dim ddBackBuffer As DirectDrawSurface7
Private BBSD As DDSURFACEDESC2
Dim rBackBuffer As RECT

BBSD.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
BBSD.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
BBSD.lWidth = SCREENWIDTH
BBSD.lHeight = SCREENHEIGHT
Set ddBackBuffer = ddraw.CreateSurface(BBSD)
rBackBuffer.Bottom = SCREENHEIGHT
rBackBuffer.Right = SCREENWIDTH
rBackBuffer.Left = 0
rBackBuffer.Top = 0

3)'load the background image

Dim ddBackground As DirectDrawSurface7
Private BGSD As DDSURFACEDESC2
Dim rBackground As RECT

BGSD.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
BGSD.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
BGSD.lWidth = SCREENWIDTH
BGSD.lHeight = SCREENHEIGHT
Set ddBackground = ddraw.CreateSurfaceFromFile( _
"c:\vb_directx\directx\sprite2\blueyellow.bmp", BGSD)
rBackground.Bottom = SCREENHEIGHT
rBackground.Right = SCREENWIDTH
rBackground.Left = 0
rBackground.Top = 0
ddBackBuffer.BltFast 0, 0, ddBackground, rBackground, _
DDBLTFAST_WAIT







Get the DirectX SDK (240meg download) the sample programs (they even have a general app framework) do all this stuff fo C++.

You may be able to find the samples seperate somewhere on the web.







Share this post


Link to post
Share on other sites
It sounds like if you work a little bit you should be able to get it. The calls will throw you but remember you don't have to memorize it. You can look at all the source code you want.

If you can find tutorials or source code to show you the way that's not too difficult.

Of course to do it with Direct3d isn't that difficult on it's own (as I meantioned I havent' worked with DirectDraw, I'm just begining) If you want Tutorials on Directx9 (or 8 or C#) try this site. http://triplebuffer.devmaster.net/tutorials.php They take a bit to go through but they will explain how to initialize, work with the rendering, and likely late on set a background image. Sorry, the first time through I thought you were talking about converting an existing code base, not just setting up your DirectX to start work and show a background.

Share this post


Link to post
Share on other sites
Quote:
Original post by kinglink
Sorry, the first time through I thought you were talking about converting an existing code base, not just setting up your DirectX to start work and show a background.


thats OK, i am glad i didnt get a whole lot of HUH? replies

this is what i have found with directX on the net. VB is a good starter as there is plently of information with directx7. then there are a lot less DirectX7 for c++....obvious reasons.

the directX7 for c++ can be of many types depending on what classes or wrapper classes you use and it seems you dont find many complete coding for directX7 just bits and pieces which isnt great for a beginner.

with samples SDK 8 comes directdraw samples. Sprite_animate is a good 1.
I will use that for directX setup and just start coding my stuff after setup.(i have been spending too long on setup and not enough on doing)

Share this post


Link to post
Share on other sites
Well let me ask this, is there any particular reason you feel the need to use DirectDraw 7? It is depreciated (meaning let go after 7, though still usable) but if you don't have a specific reason (such as "legacy hardware") Direct3d can do the same stuff, though gives a bit more freedom. Anyways good luck to your project, I hope you the best of luck.

Share this post


Link to post
Share on other sites
i had done some directdraw with VB and to get a better feel for c++ i thought it would be easier to just start this in c++.
not for too long as I will goto directx9, 2D/3D soon.
if i hadnt done all the directx7 and vb api stuff I would have been lost a long time ago

i have found it doesnt matter what you do so long as you can get help when stuck. of course the latest stuff is the best for that.

Share this post


Link to post
Share on other sites

This topic is 4692 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this