|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| Integrating Direct3D 8.1 With MFC Using Visual Studio 6.0 |
|
![]() FranzWong Member since: 3/3/2002 From: Hong Kong |
||||
|
|
||||
| This tutorial will be perfect if source code is included. I don't want to spend time on the create() function of the Graphics class before I see the result. |
||||
|
||||
![]() SteveConlan3000 Member since: 3/3/2002 |
||||
|
|
||||
| First of all, the return types of the graphics class should all be of type HRESULT. It would be beneficial to both check the return types of the DirectX calls and the member function calls with the same mechanism. Pointers should be nulled in the graphics class and freed / released on destruction. The _teapot should be destroyed on CView destruction. The create function would look like this: HRESULT Graphics::create(HWND hWnd, int width, int height, bool windowed) { // Create the D3D object. if(NULL == (_d3d8 = Direct3DCreate8(D3D_SDK_VERSION))) { return E_FAIL; } // Get the current desktop display mode, so we can set up a back // buffer of the same format D3DDISPLAYMODE d3ddm; if(FAILED( _d3d8->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm))) { return E_FAIL; } // Set up the structure used to create the D3DDevice D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = d3ddm.Format; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D24X8;// D3DFMT_D16 - D3DFMT_D24S8 // Create the D3DDevice if(FAILED(_d3d8->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &_device))) { return E_FAIL; } // Turn off culling _device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); // Turn off D3D lighting, since we are providing our own vertex colors _device->SetRenderState(D3DRS_LIGHTING, FALSE); return S_OK; } Also, the _device should be pricate and only accesed through an accessor function. If you want to see my modified version of the souce, let me know. steveconlan3000@hotmail.com |
||||
|
||||
![]() Laurent Member since: 2/1/2002 From: Seattle, United States |
||||
|
|
||||
| Great Article indeed! However, what the MFC people are looking for is a view that fits nicely in the framework, scrollable, connected to the document, etc. Dialog based apps or SDI-Single View are most of time largely not enough. MFC programmers are looking for something that could work in MDI, SDI, MTI with *multiple* views. I know this is a lot of hard work with these damn swap chains... Handling focus and efficient partial rendering is another difficult challenge. I tried and I gave up, it's a full time job. Microsoft guys should do it if they wish to open DX to mainstream apps. Laurent Laurent - http://www.lafaqmfc.com/ My little game: http://www.lafaqmfc.com/home/play_starshooter.htm |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
| I feel the last two posts (although knowledgeable/valid responses) are missing the point a bit. This article addresses the problems faced by those of us who are trying to work this out for the FIRST TIME. Sure, once this part is working you can take it further.... but every journey's gotta start somewhere ? Personally I found this article to be top notch... keep up the good work - we are not all experts.... yet ! |
||||
|
||||
![]() SteveConlan3000 Member since: 3/3/2002 |
||||
|
|
||||
| If an article to teach beginners is posted. The auther must at least have it proof read to ensure that it has covered all the bases concerning the code and its target audience. Teaching bad practices to beginners is bad practice The lack of the create function would have been the stumbling block of many a beginner. Perhaps they would not be encouraged to continue to learn. However, i think the article is well written. There are just a few omissions that should have been adressed. Thanks Steve |
||||
|
||||
![]() CarlK Member since: 3/4/2002 From: USA |
||||
|
|
||||
| I get a link error with the 3d libs such as d3dxof.lib. Ddraw.lib, dsound.lib and dinput.lib all compile. All libs are in the same directory, mssdk. The error # is LNK1104. Anyone have a solution? Thanks. |
||||
|
||||
![]() SteveConlan3000 Member since: 3/3/2002 |
||||
|
|
||||
| > CarlK Make sure that the compiler environment variables are set correctly. Go to Tools,Options,Directories Make sure you add the lib and include directories for mssdk to the correct fields in the directories tab. That should fix your problems. |
||||
|
||||
![]() Chrominium Member since: 5/11/2001 From: United Kingdom |
||||
|
|
||||
| Just wondering, have any of you found it slower to use MFC than the normal Windows classes (if you know what I mean). When I started using Directx with MFC I had some slight problem with it being updating the frames slower than withour MFC. Also some wierd mouse flickering with MFC too. Does anyone else have that problem? |
||||
|
||||
![]() arbrsoft Member since: 3/24/2002 From: Korea |
||||
|
|
||||
| The attempt of this article is not bad, but it's not good enough I can understand and make a executive one. then some one who can make a executive one after reading this article, he don't need this article really because he knows well enough that the writter didn't tell. I want executive source flie and all source code and all include file list. and the way explain of the fuction is not bad but I want more easy way to go. I have errors in Graphics class using Direct3D functions and structures then I guess I missed some include files. include<.....h> like this. I set position of d3d8.lib etc at project setting. Some one knows what I missed. reply please. And I want more fully expained and detailed article for beginners. [edited by - arbrsoft on March 24, 2002 9:29:09 AM] |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
| Good article indeed.. however, I think what some of these last posts are trying to say, is to refer to the Microsoft tutorials on Direct3D, and check out the initD3D() Function... I believe thats where SteveConlan3000 got his replacement code for the create() Function. I do agree with him however! That is the exact code I used for my create() function too... Check out DirectX on MSND if you wanna get a better idea on how to init Direct3D. Or, just look in your \DXSDK\samples\Multimedia\Direct3D\Tutorials directory and check out any of the tutorials. regard, Derek |
||||
|
||||
![]() meta4m Member since: 5/26/2002 |
||||
|
|
||||
| Hello all, I'm having trouble with this tutorial! It's a real drag. I keep getting the following error, which is really weird: C:\Documents and Settings\rver\Desktop\D3DSELF\D3DMFC\D3DMFCView.cpp(68) : error C2664: 'SetTransform' : cannot convert parameter 2 from 'struct D3DXMATRIX *' to 'const struct _D3DMATRIX *' Basically it's telling me it can't take the address of a D3DXMATRIX as arg 2 to SetTransform( ). Why on earth would it think that? I KNOW this works, as I've done it before in other projects, and it's shown that way in the MSDN docs. example: _device->SetTransform(D3DTS_VIEW, &m); It doesn't like the apmersand. It will take m if I pass by copy, but then it doesn't like the createteapot func a few lines down. WHY, HIVE IMPERIOUS, WHY? (obscure reference) Any help is appreciated. Thanks! Rich |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
| For those of you who wish to have the includes for the project, paste the following at the top of the Graphics class header: #include <d3d8.h> // Include file for DirectX 8.1 #include <D3dx8math.h> // Include file for DirectX 8.1 Math #include <mmsystem.h> // for timer functions then you can pretty much paste the create function previously mentioned or the one from the SDK (initD3D) for create(). It's really not too difficult. If you get the program to run, but have problems seeing the pot, change the 0xffffff from the clear function to: D3DCOLOR_XRGB(0,0,255) This will give you a blue background (my teapot was white, so the white background didn't give much visual pleasure). If you have problems creating your device, your machine may not support the HAL device. Change the D3DDEVTYPE_HAL to D3DDEVTYPE_REF. If you're having problems with the linker: 1. Make sure you're including the .lib files. It's not enough to just list them in the project properties, you must include the SDK\lib and SDK\include directories in the includes list. If you're using VB6 or earlier, you can just click around in the properties dialog box until you see other \lib or \include directories. Simply add the directX SDK directories and voila. 2. If you're using .NET, then do the following: a. Open the project properties. b. Under Linker->Input->Additional Dependencies, add d3d8.lib d3dx8.lib winmm.lib c. Under C/C++ ->Additional Include Directories, add SDK\include (use your path, obviously) d. Under MIDL->Additional Include Directories, add SDK\lib (again, use your path) Your project should then compile and give you no linker errors. However, if you find problems with this technique or have a better solution, please feel free to post the solution for everyone to see. These are the only hurdles I had to jump. I think the article was great. Now, let's see some of the other experts out there post some MDI and partial painting versions of this program out there. -Glenn |
||||
|
||||
![]() a2k Member since: 3/15/2000 From: San Mateo, USA |
||||
|
|
||||
| the compiler trips up when it sees the multiple inheritance line: class CDirect3DMFCView : public CView, public Graphics its complaint is: 'CDirect3DMFCView' : cannot instantiate abstract class due to following members: the line is: IMPLEMENT_DYNCREATE(CDirect3DMFCView, CView) any ideas? a2k |
||||
|
||||
![]() a2k Member since: 3/15/2000 From: San Mateo, USA |
||||
|
|
||||
| nevermind, got it. turns out that i was blindly following the instructions like most everyone else. things that i had to do to get it working: -remember to add a LPD3DXMESH _teapot in the graphics class somewhere. -remember to add the function declarations for the update, init, render and other functions in the --View class header, because they need to define the virtual functions in your graphics class. -another weird one that took a long time, but was the final step was, the teapot was being drawn white on white. not sure if i forgot a line. i just changed the bg color to something non white, and it showed up. good luck to everyone else that tries this demo for themselves. if anyone wants help, feel free to email. a2k |
||||
|
||||
![]() voip_888 Member since: 10/4/2002 From: Australia |
||||
|
|
||||
| Does anyone know how to integrate DirectX into MFC Dialog base??? I tried that article by Frank "Integrating Direct3D 8.1 with MFC using VC6". however, it give me error: C:\DirectX_MFC\DirectX_MFCDlg.cpp(65) : error C2512: 'CEngine' : no appropriate default constructor available Btw, CEngine is the one like the Graphics class. Thanks in advance. Tony |
||||
|
||||
![]() Subotron Member since: 1/13/2002 From: Nijmegen, Netherlands |
||||
|
|
||||
| Source code would b gr8 indeed, but aside from that it's a great article I think. Thanx a lot for writing it! |
||||
|
||||
![]() ZoomBoy Member since: 8/22/1999 From: Vancouver BC, Canada, Vancouver, Canada |
||||
|
|
||||
| Good Good Good Stuff |
||||
|
||||
![]() phantandy Member since: 11/26/2002 From: China |
||||
|
|
||||
| Well,my program might be working now,but i can just see a white board flickering all the time without any teapot.What's wrong with it? |
||||
|
||||
![]() CrazyLion Member since: 4/28/2004 From: Taiwan |
||||
|
|
||||
quote: oh i met the same problem.But i had solve it! you can try clear the backgroud to black(0x000000) and then the teapot will come out. The mesh is white. ..Sorry i don't know how to change the color, maybe i should read the article carefully... |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|