I can't describe this one...
Ok stupid newbie question here:
Working from LaMothe''s basic BOB engine in WGPFD, I was trying to encapsulate it in classes and get rid of all those globals. So I have my main class, CDirectXEngine - which has in it, protected, LPDIRECTDRAW lpdd. Now when I publicy inherit this class into CBitmapImage and I attempt to make another surface by calling lpdd->CreateSurface(...) the whole thing dies.
This was happening in a function called Intialise(...) so I tried many things, and the only way I got it working was leaving lpdd public in the base class, and passing it through the Initialise function''s parameters - an obviously stupid way to do things.
Can somebody explain to me please why using directly lpdd in a derived class makes things go boom?
Thanx
r.
You''ve done something wrong with how you define the classes or how you set up inheritence. What you are trying to do should be no problem, as it is normal C++. For starters, it might help if you posted your class definitions.
Also, and I don''t think this is related to your problem, why have an "Initialize" function instead of just putting that code in the constructor?
the Gent
Also, and I don''t think this is related to your problem, why have an "Initialize" function instead of just putting that code in the constructor?
the Gent
aig
May 19, 2000 11:35 AM
There is no reason why I am not using a constructor to initialise the class - I just normally do it this way to begin with. Ok, here is the base class:
class
CDirectXEngine {
int screen_width;
int screen_height;
int screen_bpp;
int RBitMask;
int GBitMask;
int BBitMask;
int RBitShift;
int GBitShift;
int BBitShift;
DDSURFACEDESC ddsd;
DDSCAPS ddscaps;
DDPIXELFORMAT ddpixelformat;
protected:
LPDIRECTDRAW lpdd;
LPDIRECTDRAWSURFACE lpddsprimary;
LPDIRECTDRAWSURFACE lpddsback;
LPDIRECTDRAWSURFACE lpddsworking;
public:
int GetScreenWidth(void) {return screen_width;}
int GetScreenHeight(void) {return screen_height;}
int GetScreenBPP(void) {return screen_bpp;}
int Initialise(int width, int height, int bpp);
int Release(void);
int LockSurface(LPDIRECTDRAWSURFACE lpdds, DDSURFACEDESC *ddsd);
int UnlockSurface(LPDIRECTDRAWSURFACE lpdds, DDSURFACEDESC *ddsd);
int RGB16BIT(int r, int g, int b) {return (((r << RBitShift) & RBitMask)+((g << GBitShift) & GBitMask)+(b & BBitMask));}
And here is the derived class:
class
CBitmapImage : public CDirectXEngine {
protected:
LPDIRECTDRAWSURFACE lpddsbitmap;
int width;
int height;
int width_fill;
int x;
int y;
public:
int GetWidth(void) {return width;}
int GetHeight(void) {return height;}
int GetWidth_Fill(void) {return width_fill;}
int GetX(void) {return x;}
int GetY(void) {return y;}
void SetX(int x_in) {x = x_in;}
void SetY(int y_in) {y = y_in;}
void SetPos(int x_in, int y_in) {x = x_in; y = y_in;}
int Initialise(int x_in, int y_in, int width_in, int height_in, int mem_flags);
int LoadImageFromBitmapFile(BITMAP_FILE_PTR bitmap, int cx, int cy, int mode);
int DrawOnSurface(LPDIRECTDRAWSURFACE dest);
int DrawOnSurfaceAt(LPDIRECTDRAWSURFACE dest, int x_in, int y_in);
};
Hope the formatting came out ok.
What am I doing thats stupid?
r.
class
CDirectXEngine {
int screen_width;
int screen_height;
int screen_bpp;
int RBitMask;
int GBitMask;
int BBitMask;
int RBitShift;
int GBitShift;
int BBitShift;
DDSURFACEDESC ddsd;
DDSCAPS ddscaps;
DDPIXELFORMAT ddpixelformat;
protected:
LPDIRECTDRAW lpdd;
LPDIRECTDRAWSURFACE lpddsprimary;
LPDIRECTDRAWSURFACE lpddsback;
LPDIRECTDRAWSURFACE lpddsworking;
public:
int GetScreenWidth(void) {return screen_width;}
int GetScreenHeight(void) {return screen_height;}
int GetScreenBPP(void) {return screen_bpp;}
int Initialise(int width, int height, int bpp);
int Release(void);
int LockSurface(LPDIRECTDRAWSURFACE lpdds, DDSURFACEDESC *ddsd);
int UnlockSurface(LPDIRECTDRAWSURFACE lpdds, DDSURFACEDESC *ddsd);
int RGB16BIT(int r, int g, int b) {return (((r << RBitShift) & RBitMask)+((g << GBitShift) & GBitMask)+(b & BBitMask));}
And here is the derived class:
class
CBitmapImage : public CDirectXEngine {
protected:
LPDIRECTDRAWSURFACE lpddsbitmap;
int width;
int height;
int width_fill;
int x;
int y;
public:
int GetWidth(void) {return width;}
int GetHeight(void) {return height;}
int GetWidth_Fill(void) {return width_fill;}
int GetX(void) {return x;}
int GetY(void) {return y;}
void SetX(int x_in) {x = x_in;}
void SetY(int y_in) {y = y_in;}
void SetPos(int x_in, int y_in) {x = x_in; y = y_in;}
int Initialise(int x_in, int y_in, int width_in, int height_in, int mem_flags);
int LoadImageFromBitmapFile(BITMAP_FILE_PTR bitmap, int cx, int cy, int mode);
int DrawOnSurface(LPDIRECTDRAWSURFACE dest);
int DrawOnSurfaceAt(LPDIRECTDRAWSURFACE dest, int x_in, int y_in);
};
Hope the formatting came out ok.
What am I doing thats stupid?
r.
Why are you inheriting the CDirectXEngine class? I''m betting that when inheriting you''re instantiate multiple LPDIRECTDRAWs and that one of them is returning an error value you aren''t trapping. Then the call on to CreateSurface refers to an invalid LPDIRECTDRAW causing the whole thing to fall out of whack. You only need one instance of LPDIRECTDRAW for your entire program, ergo, only one instance of CDirectXEngine. By creating a separate CBitmapImage you''ve instantiated two CDirectXEngine objects. Create just one CDirectXEngine object and pass a reference to that object to a CBitmapImage object without subclassing the CDirectXEngine.
I have a question, if the DX stuff was made static, wouldn''t that mean that every sub class that inherits from engine would be using the same copy of the DD objects (sounds right, but I never use static like that). Althoughg I agree with SiCrane, unless there is something in the Engine that needs to be in the bitmap class, just seperate em.
Dare To Think Outside The Box
_____________________________
|____________________________|
http://www.inversestudios.com
Dare To Think Outside The Box
_____________________________
|____________________________|
http://www.inversestudios.com
Write more poetry.http://www.Me-Zine.org
Doh! Sometimes you (well me) forget even the simplest things
So would making it static be an ideal solution - when the child classes are destroyed, does it remain in the parent class? It''s probably not worth it anyhow.
Sicrane - what would be the best way to reference LPDIRECTDRAW to another class? Also the reason I was subclassing from CDirectXEngine is because it holds the 3 screen surfaces and I was planning use them in the same class to simply draw the bitmaps onto the surface. There must be a better way to organise the surfaces, dd obj and bitmaps than what I have attempted.
So would making it static be an ideal solution - when the child classes are destroyed, does it remain in the parent class? It''s probably not worth it anyhow.
Sicrane - what would be the best way to reference LPDIRECTDRAW to another class? Also the reason I was subclassing from CDirectXEngine is because it holds the 3 screen surfaces and I was planning use them in the same class to simply draw the bitmaps onto the surface. There must be a better way to organise the surfaces, dd obj and bitmaps than what I have attempted.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement