PDA

View Full Version : textures?



CyBBe
03-24-2000, 11:52 PM
How do I import textures? Is there any easy way, does somebody have any kind of xtra libraries or something??? And as a subquestion, whats an arc fillet, and how do I use one???

Humus
03-25-2000, 01:45 AM
Import textures, just load a bitmap ... it's no harder than that.

CyBBe
03-25-2000, 01:51 AM
Exactly how do I import a bitmap, I asked for an easy way, can U give me some code examples???

holy_moly
03-25-2000, 04:25 AM
hi,
check this out...
www.codeguru.com (http://www.codeguru.com)
nehe.gamedev.net

CyBBe
03-26-2000, 12:45 AM
Someone else, som xtra libraries???

dans
03-27-2000, 02:50 AM
Originally posted by CyBBe:
Someone else, som xtra libraries???

Here you go.. This should tide you over for awhile.
///////////////////////////////////////////////////////////////////////////////
// This function loads a 24-bit color (RGB)Windows bitmap and sets it as the current
// texture. The bitmap must be 24-bit color, and the dimensions must be powers
// of 2 (no additional checks are performed).
///////////////////////////////////////////////////////////////////////////////

loadBitmap(char* filename)
{
FILE* bmpfile;
BITMAPFILEHEADER bmfileheader;
BITMAPINFOHEADER bminfoheader;
RGBTRIPLE rgb;

int nTextureWidth;
int nTextureHeight;
int i,j,texpos = 0;
BYTE *pBitmapData;

bmpfile = fopen(filename, "rb");

if (!bmpfile)
exit(1);

fread(&bmfileheader, sizeof(BITMAPFILEHEADER), 1, bmpfile);
fread(&bminfoheader, sizeof(BITMAPINFOHEADER), 1, bmpfile);


nTextureWidth = bminfoheader.biWidth;
nTextureHeight = bminfoheader.biHeight;

pBitmapData = (GLubyte*)malloc(nTextureWidth * nTextureHeight *3);

// read color
for (i = 0; i < nTextureWidth; i++)
{
for(j = nTextureHeight - 1; j>=0 ; j--) //start with the height because the first data you read in the color array of the bitmap
{ // is coord (1.0).
fread(&rgb, sizeof(RGBTRIPLE),1,bmpfile);
pBitmapData[texpos] = rgb.rgbtRed ;
pBitmapData[texpos+1] = rgb.rgbtGreen;
pBitmapData[texpos+2] = rgb.rgbtBlue;
}
}
fclose(bmpfile);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, nTextureWidth, nTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, pBitmapData);
return TRUE;

}


[This message has been edited by dans (edited 03-27-2000).]