Archived

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

AngelForce

better format than .jpg in DD?

Recommended Posts

which graphic format is best for a 2d-game(using directdraw)? at the moment i use bitmaps for the smaller sprites(which is fine i think) and jpegs for the whole-screen images. but i''m not very happy with the .jpg format because i dunno how to load them from resources and the loss of quality so, which format should i use for the bigger images? and, if it''s possible, i''d like to load them from a resource(at the moment i''m using .dlls for res) plz help me, guys! If you find any mistakes, you''re allowed to keep ''em! ''When I look back I am lost.''

Share this post


Link to post
Share on other sites
I'm a great big ol' fan of the PNG format (check out http://www.libpng.org/pub/png). Better compression than GIF, no lossiness... loads fast, loads nice. ( =

Edit: Sorry 'bout that. I asked a question you answered in that third paragraph. I shouldn't be awake right now.

What kind of problems are you having?

[edited by - RavenEris on August 15, 2002 8:02:24 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by RavenEris

What kind of problems are you having?

[edited by - RavenEris on August 15, 2002 8:02:24 AM]


well, at the moment everything''s working but i''m not happy with it...to use bitmaps as 1024*768 images isn''t the best solution i think and i don''t know how to load the jpgs i''m using at the moment from resource file(s)
now, this sounds like the first post i know i just want to avoid misunderstandings. so, i''m looking for a format that
-isn''t very big
-doesn''t loose (much) quality
-is _easy_ to load from a resource file(with easy i mean somebody''s done it before and there''s a tut somewhere about it)

it would be nice to get some more answers


AngelForce

--
If you find any mistakes, you''re allowed to keep ''em!

''When I look back I am lost.''

Share this post


Link to post
Share on other sites
So you''re using FindResource() and LoadResource()? Just checking.

What kind of problems are you having? I prefer using fopen() myself... does the library you have not let you load from memory? Only from disk? Most do.

If the textures are photorealistic then you''re probably better off using JPEGs... but if it''s not, you might be able to finagle better compression out of PNG... I haven''t needed to play around with the compression settings myself, though.

Seems like the main problem is that both of these libraries ask for files, not for memory spaces... Maybe if you did a LockResource() and wrote the image to disk temporarily? Using a call to SizeResource() perhaps? Check out GetTempFileName()... maybe you could do that...

Also, you may want to think about putting these images in their own files on disk anyway, since they''re huge when loaded... that''s a pretty big memory footprint.

These are all just ideas and babble, no criticisms. ( =

Share this post


Link to post
Share on other sites
Well, the libpng allows you actually to use a custom read function, so you you can load the bitmap from memory (and so from a resource).

Share this post


Link to post
Share on other sites
Yeah PNG is a really nice format... best I''ve ever seen actually. It can be told to compress with no quality loss (compressed color maps and RLE, etc.) or compress like JPEGs, etc. They can also have tranparent colors and (I think) be animated. (??)

However, they are a bit more difficult to load than other images... athough only marginally. Depending on your needs though, you could use TGA. It only has RLE compression, but it can be of any color format as well. Depending on your image, RLE might even end up being the best compression there is.

So TGA might work, and it is very easy to load... but if not, PNG is a really nice format too. Both can also have Alpha channels and can be loaded as textures if you ever feel like moving to DX Graphics.

Share this post


Link to post
Share on other sites
PNG supports lossless compression only (but that's usually what you want anyway) and does not support animation (although there's a related multiple-image format called MNG).

PNG is a versatile and easy-to-use image file format, and a good choice for game development. IMHO.

About the file size: try to save your large images as PNGs and check if they are small enough. If they are not, you'll pretty much have to trade size for lower quality and use some kind of lossy compression (like JPEG).

[edited by - spock on August 15, 2002 7:34:58 PM]

Share this post


Link to post
Share on other sites
If you want to use another format than BMP from resource, use LoadResource to load any custom binary resource into memory. Then create the texture using D3DXCreateTextureFromFileInMemory().

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I hope you aren''t assuming that you can load a compressed format onto a surface and use it as is. Most video cards don''t support a variety of compressed formats. The blitter may convert the format for you to a compatable format on the fly (doubtly though), but this is VERY slow.

For instance, I attempted to load DDS files onto a TNT2. Worked fine, and I was ever able to use them with without converting them myself, but it was slower than molasses.

Fortunately, I found some code that could enumerate the surface formats and choose a format that was compatable with the compressed image. This is a great idea since you don''t know what formats the hardware supports upfront.

Share this post


Link to post
Share on other sites
storing images in a dll resource is a bad idea. create your own simple pack file format or use straight images. its easier in the long run, and less windows overhead (ie the whole mapping the dll to memory space, etc). while its nice and easy to use windows functions for dealing with images its not the best option. use a jpeg library or png library. libpng allows you to override the read/write/open/close function so you can use memory to mimic a file if you wish. same iwth teh standard jpg library from the jpeg group. png would be best fro anything that required keeping the image exact (ie for masks, sprites with masks, etc). jpg is better suited for full screen images. they can be quite good quaulity assuming teh image manipulator you use allows you to set the quality to 100 instead the default of ussualy 75. this quality of 0-100 determines how much compression is done. the number dont translate directly to savings (at least i dont think, i have not looked into the jpeg algo and how the number is used in depth). its more a rough estimate and osme images can use a lower quality setting without noticing a difference.

using d3d functions is bad. that is a roundabout way of handling things and will lead to problems.

qriting a resource in a dll to disk for reading by a library is VERY bad. i dont want some game writing temp files for resources which could have just as easily been stored seperatly since that is how they are being loaded.

win98 and higher support loading images directly form resources using LoadImage() (pretty sure). you could do that and neglect win95 users who are left. i would not, but thats your desciion.

personally i think you should spend the time to learn to use libpng and the jpeg group library. you should also go ahead and create your own resource format. this will allow better control and ease of use compared to the limited dll resource approach. for instance your not at the whim of windows in how mcuh of the dll gets loading into memory when dealing with the resources. though you could just use seperate image files for things.

if you even think about syaing you are attempting to protect the artwork please realize its less then trivial to read the resources from a dll by anyone who want the artwork (plenty of such utilities exist, you even use one of them).

Share this post


Link to post
Share on other sites
heh, a lot of answers, i think my post is going to be long =)

first i'll tell you how i do things now and than comment on your comments
so, here we go

for bitmaps i use
-m_hModGrafik = LoadLibrary("bitmaps.dll") in the construktor
-hbm = (HBITMAP) LoadImage(m_hModGrafik, FileName, IMAGE_BITMAP, bWidth,bHeight, LR_CREATEDIBSECTION) to load the bmp into a surface and
-FreeLibrary(m_hModGrafik) in the deconstruktor
beforehand i loaded the bmps just from the HD but i didn't like 20 or so small images so i collected them in the .dll
for jpgs i use intel's library

now, i have to ask you nicely to be a little patient with me because i'm not an expert yet...actually i'm just working on my 1. game ;-)
i loaded it up so you guys can see what i'm talking about, just click here .

i know i'm only talking about the images here but PLEASE don't look at them in my game too closly(danger of vomiting). i wanted to code, not to draw(and i'm not an artist anyway..)
if you comment on my game(would be nice), don't comment on the sprites or backgrounds or the language(it's german =D) or the missing features(eg so far it only runs fine in 1024*768/32 at the moment) but comment on the good things(you aren't allowed to burn my first game^^).
and - VERY IMPORTANT - i haven't done ANY level-designing so far, i just put here some sprites, there some sprites so don't comment on that too plz(by now you must be wondering on what the hell you're actually allowed to comment :-D )
arrows: moving
space: fire1
ctrl: fire2
note: you get a better ship after 5 ship-powerups(the ones which always come from the right top corner), actually there are 3 types of ships but in the little demo you cannot get the 3. one

so, to speak(or write) of something different than my great game =)

i really like the idea to create my own image format yet, guess what's to come, i don't know how.
oh, i surly could write some code which puts files together and changes the binary code that much that nobody except big me could read them...but i wonder what's the gain
surly i should compress the data then and i _really_ don't know how!

after reading the replies i'm also held by the idea to use PNGs(or MNGs, for that matter) but i'd need some examples to get it working ;-)


and i haven't begun to program in d3d so far so i won't use anything from there.

last word: why should i protect MY artwork :-D

*me hopes my english isn't that bad so nobody will talk with me anymore*

AngelForce

--
If you find any mistakes, you're allowed to keep 'em!

'When I look back I am lost.'

[edited by - AngelForce on August 16, 2002 3:08:09 PM]

Share this post


Link to post
Share on other sites
first off you misunderstood. i never said to create your own image format. i suggested creating our own pak file format with which to store multiple files in. see the virtual file system example on this very site *ie see articles and resources) though i may have seen the example at flipcode.com which you may wish to check.

as to protecting artwork. you cant. no matter what you do its quite easy for someone to get the data. whether its to figure it how its stored or just take screen grabs and seperate things. sure you could make it difficult, but as you said this is your FIRST game thus you cant expect to do everything. you dont seem to be able to read docs and need actual code to understand. this is not bad since libpng comes with plenty of example code rught within the library.

again, your code that you show for loading images is EASILY used by anyone to read your images. you are not protecting anything that way. art is copyrighted thus cant be arbitraly copied by ppl. i assume you never downloaded illeagal music (ie popular bands, or basically anything not at a site like mp3.com) over the net. if you have then you are just as bad as ppl who would steal your artwork.

you do yourself a disservice by not wanting to hear bad comments. those are the most impoartant since they allow you to know what needs to be fixed. while out right flames which dont describe what is bad or even methods to help fix it are in poor taste. you require bad comments otherwsie you cant fix anything that may be broken. as such i wont download the demo since i feel it would a bad idea. especially since you mention so many things that you say you need to fix it probably would be better to what till you have something more solid.

tiff has terrible compression compared to png. while both are lossless, tiff uses Run Length Encoding like bmps can. png actually uses methods similar to a zip file. jpg is lossy thus quality can be an issue but the compression ratios like mp3 are outstanding compared to other formats. the new jpeg2000/deja vu compresses even better then jpeg with less loss in quality. however the new formats are sligtly restricted in ways and you may not want to use them.

also just an fyi. when you release a game you release the roadmap on how to read your files and access your data. simply put some one with a disaasembler could figure out whta you did by looking at the asm code. while it requires a great deal of knowledge and most can to that, it is possible to release a tool anyone can use. of course some ppl can just figure out the file format without resorting to looking at the disassembly. almost every game in existence that was popular has had its file format hacked and tools created to replace and change things. even nes games. dont waste time on protecting things until you understand what you are doing. as you said you are no expert thus you should not try to do things that are too advanced.

Share this post


Link to post
Share on other sites
a person i''m happy you''re talking with me

quote:
Original post by a person
first off you misunderstood. i never said to create your own image format. i suggested creating our own pak file format with which to store multiple files in. see the virtual file system example on this very site *ie see articles and resources) though i may have seen the example at flipcode.com which you may wish to check.


thnx, i''ll remeber that for later, but i don''t think it''s important for me at the moment(i''ll come back to it later)

quote:

as to protecting artwork. you cant. no matter what you do its quite easy for someone to get the data. whether its to figure it how its stored or just take screen grabs and seperate things. sure you could make it difficult, but as you said this is your FIRST game thus you cant expect to do everything. you dont seem to be able to read docs and need actual code to understand. this is not bad since libpng comes with plenty of example code rught within the library.

again, your code that you show for loading images is EASILY used by anyone to read your images. you are not protecting anything that way. art is copyrighted thus cant be arbitraly copied by ppl. i assume you never downloaded illeagal music (ie popular bands, or basically anything not at a site like mp3.com) over the net. if you have then you are just as bad as ppl who would steal your artwork.


i never said i want to protect my images, and i really don''t care at the moment if somebody uses my artwork
this would maybe become of importance if i got images from another person who would want to ''potect'' it
oh and i am able to learn from docs - yet, IMHO, learning from code(along with a description) is a lot faster and easier

quote:

you do yourself a disservice by not wanting to hear bad comments. those are the most impoartant since they allow you to know what needs to be fixed. while out right flames which dont describe what is bad or even methods to help fix it are in poor taste. you require bad comments otherwsie you cant fix anything that may be broken. as such i wont download the demo since i feel it would a bad idea. especially since you mention so many things that you say you need to fix it probably would be better to what till you have something more solid.


i think you didn''t get my point(ok, i hadn''t made it really clear )
i just fired the demo out to show what kind of graphics i''m using and it isn''t any kind of public release. when i get to version 1.0 i''d be happy to send you a copy and i''d also be very happy to hear about all the things i did wrong. but at the moment i am well aware that it''s only a alpha-version(if you can call it that) which only shows some effects and the general system of the game.

quote:

tiff has terrible compression compared to png. while both are lossless, tiff uses Run Length Encoding like bmps can. png actually uses methods similar to a zip file. jpg is lossy thus quality can be an issue but the compression ratios like mp3 are outstanding compared to other formats. the new jpeg2000/deja vu compresses even better then jpeg with less loss in quality. however the new formats are sligtly restricted in ways and you may not want to use them.


i''m happy to learn something new

quote:

also just an fyi. when you release a game you release the roadmap on how to read your files and access your data. simply put some one with a disaasembler could figure out whta you did by looking at the asm code. while it requires a great deal of knowledge and most can to that, it is possible to release a tool anyone can use. of course some ppl can just figure out the file format without resorting to looking at the disassembly. almost every game in existence that was popular has had its file format hacked and tools created to replace and change things. even nes games. dont waste time on protecting things until you understand what you are doing. as you said you are no expert thus you should not try to do things that are too advanced.


i think i answered this already

handling the ''i''ll come back to it later'':
i really don''t care about it and i bet you didn''t either when creating your first game.
anyway, i''m always happy to get informations because i can easily store them for later

kepp talking to me

AngelForce

--
If you find any mistakes, you''re allowed to keep ''em!

''When I look back I am lost.''

Share this post


Link to post
Share on other sites