|
-
Jan 5th, 2001, 10:59 PM
#1
Thread Starter
Lively Member
Ok. Here's what I need. You know how starcraft have all the sprites of the units with a color magenta as the team color, and when it blits it replaces all shades of magenta with the color of the player that owns that unit? I need to replicate that effect. I have an old sub that could do it for me:
Code:
For i2 = 0 To 49
For i3 = 0 To 49
pixel = GetPixel(Picture1.hdc, i2, i3)
If pixel <> 0 Then
For i4 = 0 To 15
If pixel = RGB(90 + i4 * 11, 0, 90 + i4 * 11)
>> Then SetPixelV Picture1.hdc, i2, i3,
>> RGB(Color(1, 1) * (i4 / 16), Color(1, 2) * (i4 / 16),
>> Color(1, 3) * (i4 / 16))
Next i4
End If
Next i3
Next i2
(the variable Color(1, #) refers to the three values of RGB the magenta will be replaced with)
and I could easily convert it to my directdraw code. I would have to make the game blit the original sprite to a spare buffer, replace the color, and then blit what's on the spare buffer to the backbuffer and then clear the spare buffer. The problem is that I'm afraid it may be slow. It was terribly slow the way it is now, but even if I convert it to directdraw I don't want it to end up being slow later. Isn't there a way I can palette the sprite's surface so that I can just change the palette indexes' colors, blit directly to the backbuffer, and then change the palette back?
Last edited by Vuen; Apr 14th, 2001 at 09:34 PM.
Vuen
-
Jan 8th, 2001, 07:47 PM
#2
Addicted Member
Why don't you create all sprites before the game starts (before displaying the battlefield) and then you can easily blit them without performance loss...
-
Jan 12th, 2001, 07:16 PM
#3
Frenzied Member
-
Jan 20th, 2001, 11:26 PM
#4
Thread Starter
Lively Member
um, thanks dude, but thats EXACTLY what I'm trying to do. My question was mostly how do I do that. I know what I want. I want the sprite surfaces PALETTED so I can easily change the indexes before I blit. I just don't know how. I can't seem to make the game create my surface 256 colors. I don't know which flag to set. Help?
-
Jan 21st, 2001, 08:18 AM
#5
Frenzied Member
Easy!
If you load a 24-bits bitmap, it will be 24-bits. If you load a 256-colors bitmap or a GIF image, it will be those colors!
There's also a function to retrieve the palette of a surface. You can use it for terrain animations too if you change the colors of the backbuffer before blitting, like in the water and hot lava of Starcraft!
If you have the DX7 SDK, look for the DDraw demo called "DDBlend". It has palette rotation like I said above, which also covers modifying a surface's palette.
-
Jan 21st, 2001, 04:43 PM
#6
Thread Starter
Lively Member
NO MAN! I'm not using the CreateSurfaceFromFile method because I'm getting my sprites from a resource file! I have to create the surfaces and then StretchDIBits the bitmap onto the surface. IM NOT CREATING THE SURFACE OFF OF A BITMAP, I'm creating the surface BLANK! How do I make it 256-colors?!?!?
-
Jan 23rd, 2001, 11:59 AM
#7
Frenzied Member
I'm not sure, it may be the flags you set when creating it. I know you can change the color depth when creating the screen surface, but I'm not sure about others...
-
Jan 23rd, 2001, 10:20 PM
#8
Thread Starter
Lively Member
Yeah. I tried lookin around in the flags, and I couldnt find anything that would let me use the palette functions. I'm sure it's a flag somewhere. I just can't find it...
-
Jan 24th, 2001, 10:35 AM
#9
Frenzied Member
It's easy to find out, just see how do you set the color depth of the primary surface and do it that way. There are other functions to access the palette, but of course it's only in 8-bits mode!
-
Jan 24th, 2001, 10:51 AM
#10
Frenzied Member
You don't set the colour depth of the primary surface, you use the SetDisplayMode method of the DDraw object.
Harry.
"From one thing, know ten thousand things."
-
Jan 24th, 2001, 11:01 AM
#11
Frenzied Member
Huh... THAT... yeah, you're right 
But I know there's a way of setting it. THEN you can use a palette.
-
Apr 13th, 2001, 10:43 PM
#12
Thread Starter
Lively Member
Alright, I realize that this topic is incredibly way old, but I was clearing my email which i haven't checked in ages, and found a reply to this topic 
Anyways, I found out how to make the surface 8-bit! Now here's my problem . How do I blit from this 8-bit surface to the 16/24/32-bit buffer? I can't use blt, blt just copies the bits. In other words, if for example my screen is 32-bit, the blt function thinks the 8-bit sprite is in fact just a 32-bit sprite 1/4 the size. IOW, blt causes pixel parties. Now I think there's a way to do it with bltfx, because in some of the flags of the bltfx object you can tell it the pixel format of the source and destination, but I tried playing around with the values and others that may seem like they have to do with it but it didn't work, it just crashed when I tried to blit. Can somebody teach me how to blit from an 8-bit surface to an other-bit surface?
(and on a side note, I don't think Starcraft's primary surface is other-bit, I'm pretty sure it's 8-bit. Hold on I'll try setting my display to 640x480x8 (ohmyGOD everything will be huge!), and then I'll see if the screen flashes when it tries to change the screen res/depth. brb...)
-
Apr 13th, 2001, 10:55 PM
#13
Good Ol' Platypus
While this thread is still old-new I'll say a few things.
If you dont want to have bitmaps along with your program when you distribute it, load em into picture boxes and create the surface from the DC!
It's really easy to do.
You can also blit them from a resource file, not sure how to do that, though...
PS> On a sidenote, I am almost positive that it is 16 bit colour. I'll take a screenshot and put it into my image editor and see if there is any degredation, brb.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Apr 13th, 2001, 11:01 PM
#14
Good Ol' Platypus
Proved myself wrong and Vuen right... *erg* read this portion of the FAQ from Blizzard:
What resolution does Starcraft run at?
Starcraft runs in SVGA mode at 640x480, 256-color. We chose this resolution to provide the best combination of performance, compatibility, and appearance. Allowing multiple resolutions would give too much of an advantage to players with newer or higher-end systems.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Apr 13th, 2001, 11:05 PM
#15
Thread Starter
Lively Member
Bah crap, just as i thought. Starcraft runs in 8-bit primary surface mode. That means that those 24 colors for the palette are in the palette on the same place on each sprite, and it loops through ALL the pixels of the sprite it's gonna blit and changes the pixels to the correct colors on the palette. Because of the fact that the primary surface is 8-bit, it can't just attach a new palette before blitting because blt ignores the palette anyways and just copies the bits, so it would just adapt to the palette of the buffer instead of optimizing to it. I tried doing this pixel-looping and its slow like a *****. And I don't have the means to write a C++ DLL. GRR! Besides, I want to be able to put an unlimited amount of players on a map, not just 8 (this may seem like a lot but its not, ill explain later.) So I can't have the primary surface paletted, I'll be using half the palette just for the color-changing and that's a total nono.
-(on a side know, what does this PHP button do above the text window? It adds a [PHP*] tag, and I dont know what it does. Does it do the same as [code*]?
-
Apr 14th, 2001, 12:42 AM
#16
Starcraft is allowed to loop through every pixel in a sprite. Its wirtten in C++ (and ASM, too). If you know a bit of C++, you could write a small DLL for just that one function.
Also, Media in resource files is a BAD idea. Not only does it make your .exe big, you cant update your media without a recompile. So, 10,000 lines of code later, you screwed up on Sprite 400 of 600, you have to sit through 7 or 8 minutes (hopefully) of compile. Then your users get to download that X-teen MB patch =(.
Z.
-
Apr 14th, 2001, 09:17 PM
#17
Thread Starter
Lively Member
Well guess what, turns out that according to vbexplorer, Blt takes into account both palettes while blitting and optimizes the colors! So that means that if both my surfaces are 8-bit, I can attach a new palette to my sprites and blit! So I don't need to learn how to use BltFx to blit between pixel formats after all! HOWEVER, I would still like to know HOW to blit between pixel formats, because I want to be able to have the most color-depth possible I don't want to have to reserve such and such amount of colors for terrain, and such and such colors for units, and such and such for the hud, and such and such as constants, AARRGG its just too much work, and I STILL lose color depth. THATS why I want to learn how to blit between pixel formats. IF SOMEBODY KNOWS HOW, SAY IT!!!
-
Apr 14th, 2001, 09:32 PM
#18
Thread Starter
Lively Member
Oh yeah, and about the resource file, thats quite correct. That's why my app is set up to read the files from a custom binary resource file. In other words, I just append all my files one after the other into my own file, and then build a table in a text file that shows where in the big file all the seperate files are. Then I call the big file 'stuff.dat' or whatever, and then only the text file gets added into the exe. So when I want to load a bitmap for DX7, it looks in the resource file of the EXE and finds the filename in it, and then reads the number associated with it, and then loads the surface from the stuff.dat at that specific location. That way people can download my 'stuff.dat' and my exe seperately, and then when I give an update they just need to download the exe back, and its only gonna be some hundred k, and it still uses all the same sprites from the stuff.dat, AND all my pictures are protected from modification because to modify the pics you'd need to heavily modify the text file in the EXE!
-
Apr 15th, 2001, 08:20 PM
#19
Frenzied Member
Well you can use the GetPalette method of the DirectDraw surface (I think it's GetPalette) to get an array of 256 colours. Then you can just index into this array with the palette entry number to get the 32-bit RGB value of the pixel. You can easily get any format of colour from that (although you will lose colour info if you go to 16-bit colour). If you want to extract the colours for conversion purposes then the fastest way is probably to use CopyMemory.
Harry.
"From one thing, know ten thousand things."
-
Apr 15th, 2001, 08:24 PM
#20
Frenzied Member
In case that seemed a bit pointless, the point was that you can't use hardware to do the blitting for you if you are changing colour depths (AFAIK) so you will have to copy the data to the surface yourself, translating it along the way.
Harry.
"From one thing, know ten thousand things."
-
Apr 15th, 2001, 09:09 PM
#21
Thread Starter
Lively Member
Are you serious?? I was just thinking about the map editor for starcraft! Obviously the thing blits from the 8-bit sprites to the other-bit buffer, or else it would be ungodly slow! So it's gotta be doable to blit between pixel formats, right?
-and what's an AFAIK?
-
Apr 15th, 2001, 09:11 PM
#22
PowerPoster
-
Apr 15th, 2001, 09:49 PM
#23
Frenzied Member
Vuen, the original Quake was all software rendering Later versions were released with hardware support, but the first release was just software. The second release, the Windows 95 version, called WinQuake, used only Windows GDI. Think about how fast that was. Think about how complicated that is compared to a simple 2D tile-based map editor. Consider the improvements in computer performance since Quake came out. If you find that your map editor is too slow, then I think you have some problems with the code
Harry.
"From one thing, know ten thousand things."
-
Apr 16th, 2001, 05:52 AM
#24
Fanatic Member
If anyone finds out how to blit between 8 bit and 16 or 32 bit surfaces, I'm interested for sure...
Btw, just a quick thought, can't you use BitBlt to blit from the 8 bit surface to the 16 bit? Maybe it's a little bit slower, but at least it should be faster than going trough every pixel
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
-
Apr 17th, 2001, 02:03 PM
#25
Frenzied Member
Here's how I'm (probably!) gonna make my RPG, as to graphics:
I'll use a simple 32x32 pixels tile engine.
The screen size is gonna be 800x600 because nowadays computers can support great graphics with big resolutions with no problems (Ex: my cousin's Pentium 133 runs Starcraft in a map with hundreds of units/lots of special effects with no problems!).
For the same reason, the color depth is gonna be 16-bits, and the surfaces, 8-bits (I can optimize palettes for each image, it's just so they're small).
I know how to make lookup tables for 16-bits special effects (!): it's simple, just make a general one for all three RGB values! This kind of lookup tables is much smaller, because it's for 64 values instead of 256. That allows for more levels of translucency, and even alpha masks! Of course, I'm gonna need a C++ DLL for that.
Ok. So I have everything in my head. I though there was no problem with blting from 8-bits palettes, and my system for making images smaller was based on that... maybe I should read all replies again: so, is it possible or not?
Also, shouldn't we make a kind of binary file that also compresses data? I have this Huffmann encoding ("Ziping") article that might help...
-
Apr 18th, 2001, 01:58 AM
#26
-
Apr 18th, 2001, 04:02 AM
#27
Frenzied Member
Hey, nice site! 
But the type of compression I was talking about was ZIP... do you know if zLib works the same way? Just curious 
Also, if anyone knows of another type of compression, please tell me!
I also had an idea for my own format, without any loss of color. It would look like this: header, and then the bitmap data, followed by how much pixels to the left that color would extend. If it overlaps the width, it would continue being drawn in the next line.
What do you think? I know that, in ZIP compression, the more bytes look the same in each file, the better results you'll get in size. Each file has its own "key" that is built according to it. So, maybe 2 different keys, one for the colors, and another for the lenght? This way, if we use the same colors lots of times, and the same size lots of times, we'd get an even smaller file size!
Code:
EXAMPLE:
--------
[Header][ImageWidth]
[PixelColor][PixelWidth] [PixelColor][PixelWidth] [PixelColor][PixelWidth] [PixelColor][PixelWidth]
[PixelColor][PixelWidth] [PixelColor][PixelWidth] [PixelColor][PixelWidth] [PixelColor][PixelWidth] ...
If this seems confusing, search the web for "Huffmann Encoding", because I'm at school and don't have the file here
Last edited by Jotaf98; Apr 18th, 2001 at 04:07 AM.
-
Apr 18th, 2001, 04:46 AM
#28
Fanatic Member
zLib doesn't work exactly like ZIP compression, I think ZIP uses huffman and some more compression methods. But zLib does compress the bitmaps nicely, and you don't have to write temporary files to decompress them, that's why I use it...
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
-
Apr 18th, 2001, 12:44 PM
#29
Frenzied Member
Hey, I didn't say anything about zLib being a bad compression! Huffmann doesn't need temporary files too because it's in native VB code, but since it's very basic (or at least that's what the author of this 50 pages long program says ) it might not be as good or fast!
What do you think of my compression method? Do you think it might work, or it will be the same, since it doubles the byte size for each pixel?
-
Apr 18th, 2001, 12:49 PM
#30
Fanatic Member
First of all, I think the compression and decompressions shouldn't be done in VB if you're going to use large files, but it could be done easily, I agree...
Secondly, your compression method could reduce the size of a bitmap, but mostly if it has a lot of pixels next to each other in the same color, else it would probably increase the size.
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
-
Apr 18th, 2001, 12:56 PM
#31
Frenzied Member
Heh, that was my idea - because of all the transparent areas around the unit!
Wait... now that I'm thinking for a bit... wouldn't it be better to, instead of spending lots of pixels in the transparent areas, have 2 more bytes per line: one with the X position at which the pixels of that line would start, the other with the lenght of the line. All the pixels that weren't drawn would be considered transparent. Of course, we would still have to use a color for transparency, just in case there are transparent pixels in the middle of the image!
What do you think? (This is getting kind of an habit here... )
-
Apr 18th, 2001, 01:03 PM
#32
Fanatic Member
I think you'll never get the file size down as much as you would with things like zLib or ZIP compression.
And I also think that we're thinking too much about things we should not think about, I think, because someone already though about better compression methods... 
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
-
Apr 19th, 2001, 01:54 PM
#33
-
Apr 19th, 2001, 01:58 PM
#34
Fanatic Member
Mhhhh.... I wonder if RAR would work too?
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
-
Apr 19th, 2001, 02:05 PM
#35
Frenzied Member
~Hey, all I need is something that works fast and can compress the files a bit! I don't think RAR or ZIP are that fast; that's why Starcraft uses MPQ files
-
Apr 19th, 2001, 02:08 PM
#36
Fanatic Member
Well, in that case I do recommend zLib
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
-
Apr 19th, 2001, 02:17 PM
#37
Frenzied Member
Hehe, yeah, I'm sure it's faster than VB code
-
Apr 19th, 2001, 02:23 PM
#38
Fanatic Member
Well, it has been an interesting discussion, but we still don't know how to blit from 8 to 16 bit surfaces...
So, since I want to know it too, if anyone has suggestions...
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
-
Apr 19th, 2001, 02:30 PM
#39
Frenzied Member
Well, you either make your own BLT function that looks at the values in the palette, or blt from 16 bits surfaces
-
Apr 21st, 2001, 12:49 PM
#40
Frenzied Member
Just make your own function to do it. Unless your game is already making intensive use of CPU time I don't think you're going to notice the difference all that much. At least if you package it all up into a function then you can change it later if you find out that there is a more efficient way of doing it (ie you might find out that you can do it in hardware after all, or you could pass a pointer to the surfaces [VarPtr function] to a C DLL and use some pointer arithmetic and other optimisaitons to speed it up), you can easily just change the code within the function without worrying about affecting the rest of the code.
Harry.
"From one thing, know ten thousand things."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|