Jump to content
  • Advertisement

Archived

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

Gladiator

Object Oriented Bitmap

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

Hello guys & gals, Like most people, i''ve been following the Object Oriented paradigm, but it seems like I still cannot get the hang of it. I''ve ordered a few books now which are on the way, and I''ll have some new stuff to read for quite a while after I get those. Anyways, I still don''t have the books, and I''m stuck on a problem where I''m trying to decide HOW I want to design the interfaces of my CBitmap and CDirectDraw classes. Here are some questions I have that would make it easier for you to understand where I''m coming from: Should I create a CImage and derive CBitmap (in future maybe CJPG, CGIF, etc...) from or do I have to make CBitmap definition on its own. If I do use a CImage from which to derive other image classes, what data members should I define in there. Where do I put the draw method in the CBitmap or CDirectDraw object? In order to make it more abstract, (i.e. let''s say I decide to add another image class CJPG to the draw function) how should I build it so it knows what it''s supposed to draw? I''m sure by now you understand I''m quite lost in the whole OO design process, so if someone is kind enough to give me a hand I''ll appreciate it greatly. TIA -G|aD-

Share this post


Link to post
Share on other sites
Advertisement
Object Oriented Programming is very useful and belongs in many places, but not everywhere. What intrinsic entity are you trying to model? Why is an object hierarchy the best way to model it?

Fundamentally, all bitmapped images are simply a rectangular grid of pixel values (and even vector images are eventually rasterized). Does it make more sense to have a representation for this grid and different functions that load different types of files, populating the grid with the appropriate pixel values?

OO for OO''s sake is a disservice to everyone.

Share this post


Link to post
Share on other sites
I''m no expert, and be warned I program in VB, but I''ll give a shot at answering this.

You''d put the in your CImage class everything that is common to all of the CBitmap, CJPG, CGIF etc classes. Examples - GetWidth(), GetHeight(), GetFileSize(), LoadFromFile(), Draw(). But if something is only possible with a CJPG but not with a CBitmap, then you don''t put it in the CImage, you just put it in the CJPG. For example, CompressThisMuch()

Now lets take the Draw() example. In your CImage class, Draw() does nothing, or maybe it does something simple that you may like to do first such as clear the background, but it doesn''t draw your image. But the Draw() function in the CBitmap class actually handles getting a bitmap on the screen. And the same with the CJPG class, that handles how to get a JPG on the screen.

You COULD have a DrawImage() function in your CDirectDraw class if you liked, which takes a pointer to ANY type of CImage object as input (so you could feed it a CBMP or a CJPG) and the CDirectDraw class would simply call the Draw() function of the object that was fed in.

I hope that was of some little help.

Share this post


Link to post
Share on other sites
This is the time to learn OO, and since I''m starting a new project I would like to re-write everything in OO matter to understand how it works and understand its uses.

Thanks!

-G|aD-

Share this post


Link to post
Share on other sites
bazee, thanks that''s very helpful. Even though I had some idea how to do it I just wanted to make sure I was on the right path of doing it.

On to the draw() function. The current problem that I''m having is that CBitmap requires a pointer to a CDirectDraw object in order to draw it. Is there a way to call the CBitmap::draw() function without passing the CDirectDraw object to the function? Maybe a different way of designing both classes? Anyone with experience in this area?

Let''s say everything was working fine, and I wanted to have a drawImage() function in my direct draw manager, right? Now the DDManager would call the image''s draw() function, but I''m wondering if I should make the draw() function in CImage public/private/protected or a friend to the DDManager class.

All ideas/suggestions are welcome.

Thanks!

-G|aD-

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It seems to me that you would want to separate the loading of bitmaps from bitmaps themselves. This way you could create many different bitmap "loaders" (PNG,GIF,JPEG etc...) without affecting your bitmap class or subclasses (though with this model I''m not sure if you''d have bitmap subclasses at all?).

Share this post


Link to post
Share on other sites
Well now your question is more C++ specific, and I'm very much a newbie in that language. However OOP concepts spread across many languages.

quote:

I'm wondering if I should make the draw() function in CImage public/private/protected or a friend



I would suggest that the Draw() function is public because I don't see any reason to hide it. Otherwise how will you program ever call it? You should only hide the function (by making it private) if it's never going to be used outside of the class, or if it would be invalid to use it outside the class (like it may have a bad side effect). For example (this very inefficient in reality, but it's the first thing that came to mind which shows my point) - lets say you have a function called SetPixel(), a function called Lock() and a function called Unlock(). To set a pixel, you must first lock, and the afterwards you might want to unlock. The SetPixel function would look like this:

Function SetPixel()
{
Lock();
WriteThePixel();
Unlock();
}

Now what you could do is make the Lock() and Unlock() functions private, because the outside program doesn't need to know about them anymore. Also, if the outside program did actually accidentily call the Lock() and Unlock() functions, it may cause problems.

quote:

The current problem that I'm having is that CBitmap requires a pointer to a CDirectDraw object in order to draw it.



I'm sorry I can't help answer that question, because in my graphics engine, I really do give my CBitmap class (the VB equivalent of) a pointer to the CDirectDraw class! Anyone have any better ideas?

[edited by - bazee on September 9, 2002 11:40:11 PM]

Share this post


Link to post
Share on other sites
Awesome! Thanks so far!

If anyone has suggestions from personal experience of implementing this kind of thing, or ideas on how to do it that would be valid, I''ll be glad to hear it.

Also, any recommendations on learning Object Oriented programming would be great and much appreciated!


Thank you all,
-G|aD-

Share this post


Link to post
Share on other sites
quote:
Original post by Gladiator
No one has ever done this in C++ using classes and OO concepts?

Of course people have done it; they simply haven''t responded to you. Why not search the web for object-oriented bitmap class and see what you find.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!