   Framework Source Suggestions?
Framework Source CodeHello again! lol, back for more help. ^_^Okay, as most of you know (who've checked my posts) I'm learning the DirectX API.  Right now, because of the information available, and simplicity, I'm learning 9.  Also, I'm using a VERY good book by Jonathon Harbour, Beginning Game Programming.  Really takes the whole boring "learning" process out of it, and makes it just an enjoyable activity. Anyway, I'm working on designing a framework for future projects.  Right now, it's just bare-bones.  Loads D3D and runs the game-loop.  Before I add anything else to it, I'd greatly appreciate it if some of you with a bit more experience than myself to download the source and header files (in that zip file) and skim over them, and give me any pointers tips, suggestions, criticism, etc. that you can come up with.A couple notes before hand, just for clarifications:First, everything works and runs correctly so far, including the D3DXLoadSurfaceFromFile() method.  So, no worries on trying to find syntax errors or anything.Second, my main goal in posting this is to get corrections on basically... for lack of a better phrase "acceptable standards" in the source.  For example, basically every variable so far is a static variable, declared globally.  I know it's typically bad practice (or so most reading says...), but it's the only way I know how to be able and share variables between multiple source files.  Another example would be passing by reference; I don't know if that's standard practice for those variables I have or not, but it's the only way I could edit some.  Like the d3dDevice->CreateOffscreenPlainSurface() wasn't able to use the surface class without being passed by reference.Anyway, that's basically what I'm looking for:  Pointers on anything I'm doing so far that's not normally standard practice.Thank you very much for takin the time to read over it! ^_^   
  The standard way of sharing variables around source files is to use header guards on each header, then have an extern declaration of the variable inside there, then the full definition inside one of your source files.So for exampleDirect3DCode.h:#ifndef _DIRECT3DCODE_H#define _DIRECT3DCODE_H// stuffextern LPDIRECT3D9 d3d9;// more stuff#endif // _DIRECT3DCODE_HDirect3DCode.cpp:// include stuff#include "Direct3DCode.h" // don't have to worry about the #ifndef _FRAMEWORK stuff you have currentlyLPDIRECT3D9 d3d9; // actual declaration, don't declare anywhere else or you'll get linker errorsNow on a deeper level, usually you would group all your Direct3D code into the one file (or a couple of related files) or in the one C++ class, and then provide an interface with that to the rest of your application.  So instead of passing around the d3d9 object to different files and classes, everything just uses your common D3D layer.  That way the implementation details are hidden and you could easily swap the code out for a OpenGL version, or a Direct3D 11 version, etc. without affecting your main game code.Hope that makes a bit of sense!EDIT: When you need to share between source files, then yes passing it by a reference is probably preferred.   ;Quote:Original post by mightypigeonNow on a deeper level, usually you would group all your Direct3D code into the one file (or a couple of related files) or in the one C++ class, and then provide an interface with that to the rest of your application.  So instead of passing around the d3d9 object to different files and classes, everything just uses your common D3D layer.  That way the implementation details are hidden and you could easily swap the code out for a OpenGL version, or a Direct3D 11 version, etc. without affecting your main game code.Hope that makes a bit of sense!A good idea if you are making and engine.But for your own projects, the idea may or may not be that brilliant.Given the fact that encapsulating DirectX components behind interface means that you really can't use the D3DX helper library on the "wrong side" of the interface.Or why not, but doing so would totally do in any advantages the interface roulette gives you in the long run. Multiplatforming would go out of the figurative Window(s) in an eyeblink. I seriously can't see any benefit for using OpenGL on windows for any other reason than providing an alternate renderer for those wanting it.So, you will really need to either  roll your own or third party Vector and Matrix implementations with appropriate operations. ( And make sure that the matrix atleast shares a physical semblance with its directX counterpart. In such a delightful scenario, you can just cast the datatype as (D3DXMATRIX) and pass it on to pipeline, instead of doing temporary objects and some memcopying.Then again, building an incompatible matrix for this use is something I have not seen yet...   ;  Great!  Thanks for the help and advice!BTW, I did start to share using the extern type, and am getting a decent understanding of how that goes.Next question I have though...I've got two methods:InitializeGame() which creates an off-screen surface and loads an image to it:void InitializeGame(){LPDIRECT3DSURFACE9 logo = CreateImageSurface(TEXT("logo.jpg"), D3DCOLOR_XRGB(0, 0, 0));}The CreateImageSurface method is:LPDIRECT3DSURFACE9 CreateImageSurface(LPCWSTR imageName, D3DCOLOR transColor){LPDIRECT3DSURFACE9 image;ZeroMemory(&image, sizeof(LPDIRECT3DSURFACE9));D3DXIMAGE_INFO imageInfo;ZeroMemory(&imageInfo, sizeof(D3DXIMAGE_INFO));RECT rect;HRESULT result;//For error Checking//Get image information using D3DX and check for successresult = D3DXGetImageInfoFromFile(imageName, &imageInfo);if (result != D3D_OK){Error("Failure to get image information using D3DXGetImageInfoFromFile() method!");return NULL;}rect.top = 0;rect.left = 0;rect.bottom = imageInfo.Height;rect.right = imageInfo.Width;//Create off-screen buffer and check for successd3dDevice->CreateOffscreenPlainSurface(imageInfo.Width,imageInfo.Height,D3DFMT_X8R8G8B8,D3DPOOL_DEFAULT,&image, NULL);if (result != D3D_OK){Error("Failed to create off-screen buffer using CreateOffscreenPlainSurface() method!");return NULL;}//Load image onto buffer and check for successresult = D3DXLoadSurfaceFromFile(image,NULL,&rect,imageName,&rect,D3DX_DEFAULT,transColor,NULL);if (result != D3D_OK){Error("Failed to load image onto off-screen surface using D3DXLoadSurfaceFromFile() method!");return NULL;}return image;}In the RunGame() method, I use a simple call to StretchRect to throw this image on the backBuffer:d3dDevice->StretchRect(logo, 0, backBuffer, 0, D3DTEXF_NONE);I don't know why, but it doesn't load up my image.logo is created extern and is a global variable, but for some reason, even though it returns the correct values, it's not holding that value in GameRun()...  Any ideas?   ;  Bumpin for ideas on how to fix this image loading issue.   ;  SOLVED!