direct draw jpgs and gifs

Started by
2 comments, last by Khaos Dragon 21 years, 2 months ago
Does anyone know how to load jpgs and gifs onto direct draw 7 surfaces via c++? The bitmaps for my large backgrounds are just getting way too large.
Advertisement
While I don''t have any code to offer you, you might think about the following:

( 1 ) JPG(s) and GIF(s) save DISK space be employing compression alogroithms. You will need to have decoder functions or libraries in order to read / display them. Again the key point is that they save you DISK space.

( 2 ) Neither will save you SURFACE memory space ( READ: Video memory ). Bitmaps, GIFs, JPEGs all will utimately be decoded and require precious Video memory. Bitmaps and GIFs are better here because Bitmaps and GIFs can be made to use a maximum of 256 colors. JPGs on the other hand will require 16, 24, or 32 Bits per pixel surfaces. Which again will chew your video memory very quickly.

( 3 ) Consider very carefully the hardware requirements for your game. If you want to support the broadest range of users you might be forced to deal with the fact that some people have only 2 or 4 MB of video memory on their video cards.

Once again the key point to remember is GIFs and JPGs save DISK space not SURFACE MEMORY space.

- J
Jeff OutlawPresidentDigitalOutlawhttp://www.digitaloutlaw.com
You might consider making your own custom format specific to your needs. For example, if you are only using a small number of colors, like say 20, some sort of run-length encoding might work well. I.E. (Red)(25 pixels)(Blue)(3 pixels)(Green)(1 pixel). The bonus of this is that you can write a routine to blit directly from the compressed data, rather than having to unencode it and then blit. Likewise, if you aren''t using that many colors, convert to a format that uses less bits per pixel. No reason to use 3 bytes for a single pixel when there are less than 256 colors being employeed for instance. You can even write a blitter for this too, like make an array of 256 for your palette, then do something like screen[pixelImOn] = Palette[Background[x + (y*height]];

Or perhaps tile up your backgrounds so you can reuse parts of them.

Or halve the size and just blit them double sized.

But yeah, .gif and .jpeg have to be decoded before you can actually blit them. They are just methods to store the data in a file, not nessisarily in memory in a form that can easily be blitted.
*Only in darkness can one truely shine*
I just learned SDL today and have gotten furthur in it with less than 2 hours than 2 weeks of DX, and what''s more its just as fast and portable. I''m not bashing DX or anything and still plan on learning all of the API''s but it does get frustrating sometimes when I just want to relax and have fun with making a game.

This topic is closed to new replies.

Advertisement