Jump to content

  • Log In with Google      Sign In   
  • Create Account


Image loading for textures


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 05 September 1999 - 09:13 PM

I found the recent article on texture mapping helpful, but I need a little help on how to load an image.

Could someone explain how to load an image, and what formats to use?

thanks.


Sponsor:

#2 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 22 August 1999 - 06:48 AM

It really depends if you are in 16 or 24 bit or not (not that anybody makes games with less than 16bit anymore). If you are using this to create a commercial game and not worrying on Hard Drive or CD space I would recommend something that is quick and easy to read like raw(interleaved), yeah it does not have the width,height and bytes pixel but that can easily be put into it using a structure...
If in the case you want some compression try PCX if you can get away with it without losing the beauty of true color. You will have to convert the palette to RGB values if in anything above 256 color. but that should not be difficult.

I hope this helped you or anyone...any questions, comments or disagreements e-mail I love getting new ideas and fixing bad ones
dieraxx@stega.smoky.org

P.S. If anyone out there can help me out with Transitional Screen effects in 24bit e-mail me please...


#3 NuFAN   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 August 1999 - 07:26 AM

Why not use simple bmp's or tga's ? They're easy to read, 24 bit, ... and if you've got problems on how to load them as textures, you could have a look at some sources, for example the DirectX SDK. It's quite easy and you'll step through within 2 days.

Many guys think they gotta use their own formats, it's no problem, too. You could, for example change the header of a BMP and that's it. No one else could read it without some problems.

But that's not really important, even Kingpin uses TGA's as textures (so I can use fine textures in my engine ).

CU

------------------
Skullpture Entertainment
#40842461


#4 Sengir   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 August 1999 - 07:22 AM

have a look at http://www.wotsit.org
a lot of graphics file format specifications, but I recomm you to use .TGA, it's very simple to read and there is simple compression(RLE).


#5 mutex   Members   -  Reputation: 1109

Like
Likes
Like

Posted 23 August 1999 - 08:04 AM

here's some code for loading a BMP onto a ddraw surface:

code:

bool LoadBitmapOntoSurface
(IDirectDrawSurface* surf, const char*
sFile)
{
HBITMAP hbm = LoadBitmapFromFile(sFile);
if (!hbm)
return false;

BITMAP bm;
GetObject(hbm, sizeof BITMAP, &bm);

// create DC for bitmap
HDC hdcBitmap = CreateCompatibleDC(NULL);
if (!hdcBitmap)
return false;

HGDIOBJ hbmOld = SelectObject(hdcBitmap, hbm);

// blit bitmap image to surface
HDC hdc;
if (FAILED(surf->GetDC(&hdc)))
{
SelectObject(hdcBitmap, hbmOld);
DeleteDC(hdcBitmap);
DeleteObject(hbm);
return false;
}

StretchBlt(hdc, 0, 0, m_obj.nWidth,
m_obj.nHeight,
hdcBitmap, 0, 0, bm.bmWidth, bm.bmHeight,
SRCCOPY);
surf->ReleaseDC(hdc);

// cleanup
SelectObject(hdcBitmap, hbmOld);
DeleteDC(hdcBitmap);
DeleteObject(hbm);
return true;
}




#6 CJ   Members   -  Reputation: 122

Like
Likes
Like

Posted 05 September 1999 - 09:13 PM

You can also write your own loader. But you need to know how the information in a BMP is stored. I would recommend you to go to http://www.wotsit.org and see which image you would like to use.

I found out that BMP is the easiest to use.
It's something like.....you can use a DirectDrawSurface, or something else (note that I've used DirectDrawSurfaces)

Note pdata is the start of the image.

code:

//Copy 888 .BMP image to 1555 DirectDraw texture surface in video
//memory, converting as we go. BMP data is stored bottom to top
//(i.e., from left to right along a row, but the rows are
//stored bottom to top in memory). For applications that support
//multiple texture formats, this code fragment can be broken
//out into a separate function, and then copied and modified
//for each supported texture format.

unsigned char r,g,b;
unsigned char *oldpdata;
unsigned short color1555;
unsigned short *texSurfBase;
int x, y;
int skip; //actual vs. asked for surface width
int imageWidthInBytes;

oldpdata = pdata;
texSurfBase = (unsigned short *)ddsd.lpSurface;
imageWidthInBytes = BMPh->biWidth*IMAGEDEPTH_IN_BYTES;
skip = ddsd.lPitch - BMPh->biWidth*COLORDEPTH_IN_BYTES;

//start at beginning of last row of image
pdata += BMPh->biHeight*imageWidthInBytes - imageWidthInBytes;

for (y=0; ybiHeight; y++)
{
for (x=0; xbiWidth; x++)
{
b = *pdata++;
g = *pdata++;
r = *pdata++;

color1555 = (unsigned short)( ((r >> 3) << 10) |
((g >> 3) << 5) |
(b >> 3) );
*texSurfBase++ = color1555;
}

//go to next row of texture surface
texSurfBase += skip;

//go to start of previous row (i.e., go back
//two rows worth of bytes, the one just completed,
//and the one we want to get to the start of...
pdata -= imageWidthInBytes*2;
}

pdata = oldpdata; //reset pdata's original address


------------------
Dance with me......





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS