• 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.


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


How to load a 24-Bit BMP on a 16-Bit DDraw Surface

2 posts in this topic

Hi, I am trying to do a functionto load 24-bit BMP into a 16-Bit Direct Draw Surface, Currently I have loaded my BMP and stored al my BMP Data in a CHAR *Data array, but my trouble is how to extract the RGB; values of each pixel and convert it to fit exactly in the 16-bit surface (Without lose of color). I am using this formulas, to rectify the 24-bit image onto a 16-BIT DDrawSurface, but I dont know how to get the RGB, of my BMP DATA and store it (the New values) onto my DDraw, surface any Idea? Here is the formulas based in an article done by TANSTAAFL... http://www.gamedev.net/reference/articles/article863.asp GetPixelFormat takes a pointer to a DDPIXELFORMAT structure (not surprisingly). I looked at the DDPIXELFORMAT structure, and I found a couple of fields that interested me… namely dwRBitMask, dwGBitMask, dwBBitMask. Now I had all of the information I wanted, just not in a format I could use. DDPIXELFORMAT ddpf; memset(&ddpf,0,sizeof(DDPIXELFORMAT); ddpf.dwSize=sizeof(DDPIXELFORMAT); lpDDS->GetPixelFormat(&ddpf); What now? Well, in order to figure out how far to shift bits to the left, I had to do this: //warning, this code is UGLY DWORD dwBMask=ddpf.dwBBitMask; DWORD dwRMask=ddpf.dwRBitMask; DWORD dwGMask=ddpf.dwGBitMask; DWORD dwBSHL=0; DWORD dwRSHL=0; DWORD dwGSHL=0; while((dwBMask & 1)==0) { dwBMask=dwBMask >> 1; dwBSHL++; } while((dwGMask & 1)==0) { dwGMask=dwGMask >> 1; dwGSHL++; } while((dwRMask & 1)==0) { dwRMask=dwRMask >> 1; dwRSHL++; } At this point, if we assumed that I had the correct number of bits stored in three UCHARs named Red, Green, and Blue, I could calculate the 16-bit color by doing this: Color=Blue << dwBSHL + Green << dwGSHL + Red << dwRSHL; However, right now, we have 8 bits in each of Red, Green, and Blue, and we need only 5 or 6. We have to be able to shift the bits of the colors to the right before shifting them to the left to make a 16-bit color. So, let''s determine how many bits to the right we have to shift them: DWORD dwBSHR=8; DWORD dwRSHR=8; DWORD dwGSHR=8; while((dwBMask & 1)==1) { dwBMask=dwBMask >> 1; dwBSHR--; } while((dwGMask & 1)==1) { dwGMask=dwGMask >> 1; dwGSHR--; } while((dwRMask & 1)==1) { dwRMask=dwRMask >> 1; dwRSHR--; } Now, we can accurately calculate a 16bit color from a 24Bit color. Color=(Blue >> dwBSHR) << dwBSHL + (Green >> dwGSHR) << dwGSHL + (Red >> dwRSHR) << dwRSHL;

Share this post

Link to post
Share on other sites

16 bits come in two flavours: 565 and rarely 555

as the names say its 5bits for red 6 bits for green and 5 bits for blue

after u get RGB components from 24bits data u AND them with:
0x1f for red
0x3f for green
0x1f for blue

this is on a 5:6:5 board

and then shift them back into positions in order to get 16bits
word data "et voila" thats ur pixel...

of course u will loose color...but u cant make the same thing in 16 bits as in 24 bits....otherwise


Share this post

Link to post
Share on other sites
Oscar: When you want to display a 24-bit bitmap on a 16-bit surface, you have two options. The first is to do it manually, one pixel at a time. From what you said in your post, I assume you already have a char* that points to the actual image data in the bitmap. You have to read it in one pixel at a time. Each pixel will have one byte for red, one byte for green, and one byte for blue. To scale these down to the appropriate range for 16-bit color, you would use this for 565-mode:

#define RGB16BIT565 (((r>>3)<<11) | ((g>>2)<<5) | (b>>3))

Or this for 555-mode:

#define RGB16BIT555 (((r>>3)<<10) | ((g>>3)<<5) | (b>>3))

Each macro yields a USHORT that represents one pixel in the appropriate 16-bit pixel format. So then you write the bitmap onto your surface one pixel at a time. To avoid any sign extension screwing up the results, you should probably cast your char* to a UCHAR*.

Bogdan: I know what you're saying with the bit masks, but I don't think it will yield the correct result. The way you have it, a pixel in the 24-bit bitmap whose red component is 31 will be as bright as possible, and a pixel whose red component is 32 will be as dark as possible. Know what I mean? I think the values should be scaled down rather than just masking out the low bits, hence all those bit shifts in my macros.

Oscar again : A much easier solution is to use device contexts. Load your bitmap by using LoadImage(), then create a memory device context with CreateCompatibleDC() and select the bitmap into the DC using SelectObject(). Next, create another DC (the destination DC) from your DirectDraw surface, using IDirectDrawSurface7::GetDC(), and copy the bitmap from one to the other using BitBlt() -- or StretchBlt() if you want to scale it. In this case, the conversion of color depths is automatic.

If that sounds like something that would work for your particular program, and you want to see it in detail, I have an article covering a bunch of GDI stuff on my website (link below). Just take the function I use as an example, and replace the destination device context with one you get from your surface, and it should work fine.

 Aeon Software

Edited by - Ironblayde on August 29, 2000 10:17:53 PM

Edited by - Ironblayde on August 29, 2000 10:22:33 PM

Share this post

Link to post
Share on other sites