• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Magos

Blizzard's BLP image format

15 posts in this topic

In Warcraft 3 Blizzard uses their own image format - blp which contains multiple JPEG images with a shared header, one per mipmap (the mipmaps are stored in the image). Now each image shares one single header so to construct a JPEG image you append the header with any of the mipmap blocks and you get a usable JPEG image. I've written a loader that does this and it works fine. The problem however is when I'm trying to write a saver for this image format. How do you create jpeg images so that all mipmaps use the same header? Blizzard managed somehow, but I'm not sure how. I naively tried to take the header of the first mipmap but when appended to the others it generates screwed up images all of the size as the first one. I'm not surprised, since they use the same header. Does anyone have any ideas? If the width/height information lies in the header, how can one single header be used for all mipmaps (which has different sizes)??? I'm kinda lost here!
0

Share this post


Link to post
Share on other sites
Can't you assume that successive mipmaps will have their height and width divided by 2?
0

Share this post


Link to post
Share on other sites
Well if your loader works, what did you do for size in the loader? Anywas there's probably some procedural interval. Like half the size as the previous or something. Or it's in the header but I have no idea but try it out, I'm sure you'll get it eventually.
0

Share this post


Link to post
Share on other sites
I guess my question is, after generating the first mipmap how can I generate the next mipmap so it uses the same JPEG header as the first? If I generate another image it won't have the same huffman tables etc... as the previous, right?
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Code-R
they actually use JPEGs for textures??!!


You seem surprised, why?
0

Share this post


Link to post
Share on other sites
for one, it's lossy, the bad way, not DXT way:
[url]http://www.sjbaker.org/steve/omniv/jpegs_are_evil_too.html[/url]
0

Share this post


Link to post
Share on other sites
Quake 3 used JPEGs for non-alpha blended texturing as well, I didn't see any really bad artifacts there.
0

Share this post


Link to post
Share on other sites
*checks* Nope, JPEGs. There are TGAs in there too, but mostly JPEGs.
0

Share this post


Link to post
Share on other sites
We use this function to load out BLP textures in a project I'm involved with.
This is used to load BLP textures from World of Warcraft, but I'm pretty sure that they didn't modify their BLP format from Warcraft3 so this should work with it aswell.


void TextureManager::LoadBLP(GLuint id, Texture *tex)
{
// load BLP texture
glBindTexture(GL_TEXTURE_2D, id);

int offsets[16],sizes[16],w,h;
GLint format;

char attr[4];

MPQFile f(tex->name.c_str());
if (f.isEof()) {
tex->id = 0;
return;
}

f.seek(8);
f.read(attr,4);
f.read(&w,4);
f.read(&h,4);
f.read(offsets,4*16);
f.read(sizes,4*16);

tex->w = w;
tex->h = h;

bool hasmipmaps = attr[4]>0;
int mipmax = hasmipmaps ? 16 : 1;

if (attr[0] == 2) {
// compressed

unsigned char *ucbuf;
if (!supportCompression) ucbuf = new unsigned char[w*h*4];

format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
int blocksize = 8;

// guesswork here :(
if (attr[1]==8) {
format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
blocksize = 16;
} else {
if (!attr[3]) format = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
}

tex->compressed = true;

unsigned char *buf = new unsigned char[sizes[0]];

// do every mipmap level
for (int i=0; i<mipmax; i++) {
if (w==0) w = 1;
if (h==0) h = 1;
if (offsets[i] && sizes[i]) {
f.seek(offsets[i]);
f.read(buf,sizes[i]);

int size = ((w+3)/4) * ((h+3)/4) * blocksize;

if (supportCompression) {
glCompressedTexImage2DARB(GL_TEXTURE_2D, i, format, w, h, 0, size, buf);
} else {
decompressDXTC(format, w, h, size, buf, ucbuf);
glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ucbuf);
}

} else break;
w >>= 1;
h >>= 1;
}

delete[] buf;
if (!supportCompression) delete[] ucbuf;
}
else if (attr[0]==1) {
// uncompressed
unsigned int pal[256];
f.read(pal,1024);

unsigned char *buf = new unsigned char[sizes[0]];
unsigned int *buf2 = new unsigned int[w*h];
unsigned int *p;
unsigned char *c, *a;

int alphabits = attr[1];
bool hasalpha = alphabits!=0;

tex->compressed = false;

for (int i=0; i<mipmax; i++) {
if (w==0) w = 1;
if (h==0) h = 1;
if (offsets[i] && sizes[i]) {
f.seek(offsets[i]);
f.read(buf,sizes[i]);

int cnt = 0;

p = buf2;
c = buf;
a = buf + w*h;
for (int y=0; y<h; y++) {
for (int x=0; x<w; x++) {
unsigned int k = pal[*c++];

k = ((k&0x00FF0000)>>16) | ((k&0x0000FF00)) | ((k& 0x000000FF)<<16);

int alpha;
if (hasalpha) {
if (alphabits == 8) {
alpha = (*a++);
} else if (alphabits == 1) {
//alpha = (*a & (128 >> cnt++)) ? 0xff : 0;
alpha = (*a & (1 << cnt++)) ? 0xff : 0;
if (cnt == 8) {
cnt = 0;
a++;
}
}
} else alpha = 0xff;

k |= alpha << 24;
*p++ = k;
}
}

glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf2);

} else break;
w >>= 1;
h >>= 1;
}

delete[] buf2;
delete[] buf;
}

f.close();

if (hasmipmaps) {
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
} else {
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}

// some models require texture wrapping though
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);

}



Naturally you would have to change things like "MPQFile f(tex->name.c_str());" and actually open the BLP file instead, but this should give you the gist of it.

Also the BLP format is closer to TGA's, not JPEG's.
0

Share this post


Link to post
Share on other sites
BLP can store both JPEG's and a palettizized version of the image. They started using palettes in War3 - FT and WoW mainly because the MPQ compression was good enough plus it didn't get lossy.

However, I already have functional loaders for both types. As mentioned in the first post it's the saver I'm interested in...
0

Share this post


Link to post
Share on other sites
Never mind this thread now, it's solved. It turned out that I was saving one mipmap less than neccessary (and Warcraft 3 wasn't smart enough to fix it or tell me :) ).
0

Share this post


Link to post
Share on other sites
By the way Magos, how do you load the first JPG mip map from a BLP? Cause I tried that based on the specifications but I get a JPG with wrong colors that is only openable by windows XP and not ijl
0

Share this post


Link to post
Share on other sites
I just appended the header with the first mipmap (of size Size[0] at offset Offset[0]) and got a working JPEG. Note that it has 4 channels (RGBA), not 3. If the colors are reversed it may be stored as BGR rather than RGB, can't remember right now. If this is the case just swap the R and B components after loading.

I put up my own interpretation of the BLP (and MDX) format here, it may (or may not) be of help:
http://Magos.TheJeffFiles.com/War3ModelEditor/
0

Share this post


Link to post
Share on other sites
Wow that seems to be one of the best tools ever made for war3 although the war3 community has been dying latelly. Thanks, it would of course be of help mostly because it is the first time in 3 months I finally find help about the subject
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0