• Advertisement


This topic is now archived and is closed to further replies.

structuring a class

This topic is 5808 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

OK, I am having problems structuring my DirectX app (I am writing it in Visual Basic). I have a class that allows me to do the following: - initialise DX - create a surface - draw surface to the backbuffer - flip surfaces - shutdown dx My problem is as follows: When I draw a surface to the backbuffer, the Blit function needs a source rect to be specified. However, I don't want the user of the class to have to specify the source rect (width and height of the image) each time. I just want it to accept the surface's default width and height (as specified when calling the CreateSurface procedure). However, I don't know how this can be done, since surfaces don't seem to have a width and height property... EDIT: I guess I ultimately want to create a 'sprite' object that will hold the surface, its dimensions, and even its current x and y coordinates so that I can track its position on the screen. I want to be able to use this object to support animated sprites in the future. However, the problem with this is that I hav a seperate class used to initialize DirectX and destroy it, and since classes can't reference external variables, I don't know how, in the sprite class, I could make use of the DX and DD objects, and everything else needed to successfuly create and Blit a surface. Any suggestions? Edited by - fredjordans on February 25, 2002 9:13:31 PM

Share this post

Link to post
Share on other sites
Use BltFast(...)

I forgot what parameters you''re required to pass because I haven''t been doing graphics for a long time. Okay, I''m too lazy to look it up as well...

Also, you might want to add more functionality to the class:
- Load Bitmaps to a surface
- Draw Lines, Pixels, Rects
- Alpha Blending

Also, what I do is create functions that blit for you. So I have
DrawToSurface(int x, int y, LPDIRECTDRAWSURFACE7 source); //<- Bare bones (Uses BltFast(...))

DrawToSurface to surface(int x, int y, LPDIRECTDRAWSURFACE7 source, LPDIRECTDRAWSURFACE7 dest);
DrawToSurfaceSourceRect(RECT source_rect, LPDIRECTDRAWSURFACE7 source, LPDIRECTDRAWSURFACE7 dest);
DrawToSurfaceTargetRect(RECT target_rect, LPDIRECTDRAWSURFACE7 source, LPDIRECTDRAWSURFACE7 dest);
DrawToSurfaceTargetRectSourceRect(RECT source_rect, RECT target_rect, LPDIRECTDRAWSURFACE7 source, LPDIRECTDRAWSURFACE7 dest);

Also, you might want to have another set of functions that draw directly on the back buffer. So you''ll have:

DrawSurface(int x, int y); //<- No target. Target is backbuffer


Note that only the DrawSurface(...) and DrawToSurface(...) uses BltFast(...), which does not need a RECT.

Share this post

Link to post
Share on other sites

  • Advertisement