From: "Dan Goodman" Newsgroups: comp.os.msdos.djgpp Subject: Fiddling around with Allegro bitmaps Date: Mon, 28 Sep 1998 22:01:53 +0100 Message-ID: <907016670.2432.0.nnrp-10.9e989aee@news.demon.co.uk> NNTP-Posting-Host: fcbob.demon.co.uk Lines: 64 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk This is a bit of an Allegro question, but not entirely. I have some code where I combine the information in 2 seperate but equally sized bitmaps into a 3rd equally sized bitmap. Basically, what I do is to take the rgb values from the colour in the 1st bitmap, use the rgb values from the 2nd bitmap as an xyz vector, take the dot product of this vector and another (fixed) vector. And multiply the rgb values from the 1st bitmap by the dot product, and output this changed value to the 3rd bitmap. If you haven't guessed it yet, I'm trying to do some realtime shading with 3d graphics where I stored a copy of the surface normal in the rgb values of a bitmap. Anyway, I originally wrote it like this: lx,ly,lz vary from -256 to 256 // (this is the fixed, lighting vector) for all x,y in the bitmaps c = getpixel(bitmap,x,y); n = getpixel(bitmapnormals,x,y); r = getr(c) etc... nx = getr(n)-128; ny=getg(n)-128; nz=getb(n)-128; i = (nx*lz+ny*ly+nz*lz)/128; // now i should vary from -256 to 256 if(i<50) i=50; // simulates ambient lighting r = (r*i)/256; etc... c = makecol(r,g,b); putpixel(newbitmap,x,y); Well, this was OK and it worked fine, but it was a bit slow. So I changed the getrgb to getrgb32 and put inlining on and that made it faster. But then I decided to get rid of the get and putpixel routines which were obviously slowing it down a lot. So what I did was this: long *bi,*bo; ... for all y in the bitmaps bi = (long *)bitmap->line[y]; bo = (long *)newbitmap->line[y]; for all x in the bitmaps c = *bi++; ... (*bo++) = c; which was many many times faster. This was the best I could do from looking at the Allegro sources, etc.. But still I am only getting about 200fps on a P333 for an 80x60 bitmap (including blitting newbitmap to the screen afterwards) - which is fine on its own, but as part of a whole game with loads of other stuff going on as well, probably isn't fast enough. Basically, it is probably a similar problem to using lighting effects and so forth. My question is: is there a way of doing this faster? Any part of it, the reading and writing from the bitmaps, and generating the shading from the surface normal vector? (BTW, solutions using only C/C++ would be nice as I don't know how to program in ASM). On a related note, is there a quick way of writing allegro bitmap data in vertical as opposed to horizontal lines, without having to find the line[y] segment each time? Many thanks, Dan -- Dan Goodman of FCBOB http://www.fcbob.demon.co.uk