Tuesday, May 8, 2007

Tips At Bonefish Grille

Previous Previous 8 8

Aide Program to create 2 cubes, two lights, texture and materials used

# include GL / glut.h

# include stdlib.h # include stdio.h math.h

# include # include "bitmap.h" int Width
;
int Height;
int bd, bi;
BITMAPINFO * BITMAPINFO;
GLubyte *BitmapBits;
char *nomimage;
float xRot=0;
float yRot=0;

void init(void)
{
bd=0;
bi=0;
//glClearColor (0.0, 0.0, 1.0, 0.0);
glClear( GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT);
//glEnable(GL_DEPTH_TEST);
glShadeModel (GL_SMOOTH);


}
void carcatex(){
BitmapBits = LoadDIBitmap(nomimage, &BitmapInfo);
glTexImage2D(GL_TEXTURE_2D,0,3,BitmapInfo->bmiHeader.biWidth,BitmapInfo->bmiHeader.biHeight,0,GL_RGB,GL_UNSIGNED_BYTE,BitmapBits);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
/ / glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND)
glTexImage2D (GL_TEXTURE_2D, 0, 3 , 128,128,0, GL_RGB, GL_UNSIGNED_BYTE, BitmapBits);}

void cmaterial (x, y) {float
colorf [4] = {} 0.0,0.4,0,1;
float color [4] = {0.2, .4,1,1};
colord float [4] = {} 0.3,0,1,1;
float color [4] = {0.5, .0,0,1};
float colors [4] = {0.5, .6,0,1};
colorin float [4] = {0.0, .6,0,1};
glShadeModel (GL_SMOOTH)
glPushMatrix ();
glRotatef (45,0,1,1);
glTranslatef (x, y, 0);
/ * Faces cross * /
nomimage = "mountain.bmp" / Name the image
carcatex ();
glMaterialfv (GL_FRONT, GL_DIFFUSE, colord)
glEnable (GL_TEXTURE_2D);
glBegin (GL_QUADS)
/ * Vertical back * /
glTexCoord2f (0.0, 0.0);
glVertex3f (1, 0, 0);
glTexCoord2f (1.0, 0.0);
glVertex3f (0, 0, 0);
glTexCoord2f (1.0, 1.0);
glVertex3f (0, 1, 0);
glTexCoord2f (0.0, 1.0 )
glVertex3f (1, 1, 0);
glEnd ();
glMaterialfv (GL_FRONT, GL_SPECULAR, color);
nomimage = "mountain1.bmp"
carcatex ();
glEnable (GL_TEXTURE_2D);
glBegin (GL_QUADS)
/ * Superior, horizontal * /
glTexCoord2f (0.0, 0.0 )
glVertex3f (1, 1, 1);
glTexCoord2f (1.0, 0.0);
glVertex3f (0, 1, 1);
glTexCoord2f (1.0, 1.0);
glVertex3f (0, 1, 0);
glTexCoord2f (0.0, 1.0);
glVertex3f (1, 1, 0);
glEnd ();
glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, colorf)
nomimage = "mountain2.bmp"
carcatex ();
glEnable (GL_TEXTURE_2D) ;
glBegin (GL_QUADS )
/ * Vertical front * /
glTexCoord2f (0.0, 0.0);
glVertex3f (1, 0, 1);
glTexCoord2f (1.0, 0.0);
glVertex3f (1, 0, 0);
glTexCoord2f (1.0, 1.0);
glVertex3f (1 1, 0);
glTexCoord2f (0.0, 1.0);
glVertex3f (1, 1, 1);
glEnd ();
glMaterialfv (GL_FRONT, GL_EMISSION, colorin)
nomimage = " mountain3.bmp "
carcatex ();
glEnable (GL_TEXTURE_2D);
glBegin (GL_QUADS)
/ * Bottom * /
glTexCoord2f (0.0, 0.0);
glVertex3f (0, 0, 1);
glTexCoord2f (1.0 , 0.0);
glVertex3f (0, 0, 0);
glTexCoord2f (1.0, 1.0);
glVertex3f (0, 1, 0);
glTexCoord2f (0.0, 1.0);
glVertex3f (0, 1, 1);
glEnd ();
glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color);
/ * Sides * /
nomimage = "mountain4.bmp"
carcatex ();
glEnable (GL_TEXTURE_2D);
glBegin (GL_QUADS)
glTexCoord2f (0.0, 0.0);
glVertex3f (1, 0, 1);
glTexCoord2f (1.0, 0.0);
glVertex3f (1, 0, 0);
glTexCoord2f (1.0, 1.0);
glVertex3f (0, 0, 0);
glTexCoord2f (0.0, 1.0);
glVertex3f (0, 0 , 1);
glEnd ();
glMaterialfv (GL_FRONT, GL_AMBIENT, colors);
nomimage = "aide.bmp" / / photo
carcatex ();
glEnable (GL_TEXTURE_2D);
glBegin (GL_QUADS)
glTexCoord2f (0.0f, 1.0f);
glVertex3f (1, 0 , 1);
glTexCoord2f (1.0f, 1.0f);
glVertex3f (1, 1, 1);
glTexCoord2f (1.0f, 0.0f);
glVertex3f (0, 1, 1);
glTexCoord2f (0.0f, 0.0f);
glVertex3f (0, 0, 1);
glEnd ();
glPopMatrix ();}

void cmaterial1 (x, y) {float
colorf [4] = {0.0,0.4,0,1 };
float color [4] = {0.2, .4,1,1};
colord float [4] = {} 0.3,0,1,1;
float color [4] = {0.5, .0, 0.1};
float colors [4] = {0.5, .6,0,1};
colorin float [4] = {0.0, .6,0,1};
glShadeModel (GL_SMOOTH)
glPushMatrix ();
glRotatef ( 45,0,1,1);
glTranslatef (x, y, 0);
/ * Faces cross * /
glBegin (GL_QUADS)
/ * Vertical back * /
glVertex3f (1, 0, 0);
glVertex3f (0, 0, 0);
glVertex3f (0, 1, 0);
glVertex3f (1, 1, 0);
glEnd ();

glMaterialfv (GL_FRONT, GL_SPECULAR, colori)
glBegin (GL_QUADS )
/ * Upper horizontal * /
glVertex3f (1, 1, 1);
glVertex3f (0, 1, 1);
glVertex3f (0, 1, 0);
glVertex3f (1, 1, 0);
glEnd ();
glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, colorf)
glBegin (GL_QUADS)
/ * Vertical front * / glVertex3f
(1, 0, 1);
glVertex3f (1, 0, 0);
glVertex3f (1, 1, 0);
glVertex3f (1, 1, 1);
glEnd ();
glMaterialfv (GL_FRONT, GL_EMISSION, colorin)
glBegin (GL_QUADS)
/ * Bottom * /
glVertex3f (0, 0, 1);
glVertex3f (0, 0, 0);
glVertex3f (0, 1, 0);
glVertex3f (0, 1, 1);
glEnd ();
glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, colora );
/* Costados */
glBegin( GL_QUADS );
glVertex3f( 1, 0, 1 );
glVertex3f( 1, 0, 0 );
glVertex3f( 0, 0, 0 );
glVertex3f( 0, 0, 1 );
glEnd();
glMaterialfv(GL_FRONT, GL_AMBIENT, colors );
glBegin( GL_QUADS );
glVertex3f( 1, 0, 1 );
glVertex3f( 1, 1, 1 );
glVertex3f( 0, 1, 1 );
glVertex3f( 0, 0, 1 );
glEnd();
glPopMatrix();
}
void display(void)
{
GLfloat light_ambient[]={0.0, 0.0, 0.0, 1.0};
GLfloat light_diffuse[]={1.0, 1.0, 1.0, 1.0};
GLfloat light_specular[]={1.0, 1.0, 1.0, 1.0};
GLfloat light_position[]={xRot, yRot, 1.0, 1.0};
GLfloat light1_ambient[]={0.0, 0.0, 0.0, 1.0};
GLfloat light1_diffuse[]={.5, .5, .5, .5};
GLfloat light1_specular[]={.1, .1, .1, .1};
GLfloat light1_position[]={1.0, 1.0, 10, 10.0};
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glLoadIdentity (); /* clear the matrix */
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse);
glLightfv(GL_LIGHT1, GL_SPECULAR, light1_specular);
glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable( GL_LIGHTING );
if(bi==1){
glDisable( GL_LIGHT0 );
glEnable( GL_LIGHT1 );}
if(bi==2){
glEnable( GL_LIGHT0 );
glDisable( GL_LIGHT1 );}
cmaterial(-1,1);
cmaterial1(-1,-1);
glFlush ();
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
}
void onMouse(int button, int state, int x, int y)
{
int aux;
if ( (button == GLUT_LEFT_BUTTON) & (state == GLUT_DOWN) ) {
bi=1;
}
if ( (button == GLUT_RIGHT_BUTTON) & (state == GLUT_DOWN) ) {
bi=2;
}
display();
}
void keyboard(int key, int x, int y)
{
if(key == GLUT_KEY_UP)
xRot-= 0.2f;
if(key == GLUT_KEY_DOWN)
xRot += 0.2f;
if(key == GLUT_KEY_LEFT)
yRot -= 0.2f;
if(key == GLUT_KEY_RIGHT)
yRot += 0.2f;
if(key > 1.0f)
xRot = 0.0f;
if(key < 0.0f)
xRot = 1.0f;
if(key > 1.0f)
yRot = 0.0f;
if(key < 0.0f)
yRot = 1.0f;
// Refresh the Window
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (300,230);
glutCreateWindow (argv [0]);
Init ();
glutDisplayFunc (display);
glutMouseFunc (onMouse);
glutReshapeFunc (reshape);
glutKeyboardFunc (Keyboard);
glutMainLoop ();
return 0;}


Bookstore Assistant to load texture LA BITMAP.C

# include "bitmap.h"
# include stdio.h # include stdlib.h # include errno.h



# ifdef Win32
GLubyte * / * O - Bitmap date * /
LoadDIBitmap (const char * filename, / * I - File to load * /
BITMAPINFO ** info) / * O - Bitmap information * /

{FILE * fp / * Open file pointer * / GLubyte *
bits; /* Bitmap pixel bits */
int bitsize; /* Size of bitmap */
int infosize; /* Size of header information */
BITMAPFILEHEADER header; /* File header */

/* Try opening the file; use "rb" mode to read this *binary* file. */
if ((fp = fopen(filename, "rb")) == NULL)
return (NULL);
/* Read the file header and any following bitmap information... */
if (fread(&header, sizeof(BITMAPFILEHEADER), 1, fp) < 1)
{
/* Couldn't read the file header - return NULL... */
fclose(fp);
return (NULL);
}
if (header.bfType != 'MB') /* Check for BM reversed... */
{
/* Not a bitmap file - return NULL... */
fclose(fp);
return (NULL);
}
infosize = header.bfOffBits - sizeof(BITMAPFILEHEADER);
if ((*info = (BITMAPINFO *)malloc(infosize)) == NULL)
{
/* Couldn't allocate memory for bitmap info - return NULL... */
fclose(fp);
return (NULL);
}
if (fread(*info, 1, infosize, fp) < infosize)
{
/* Couldn't read the bitmap header - return NULL... */
free(*info);
fclose(fp);
return (NULL);
}
/* Now that we have all the header info read in, allocate memory for *
* the bitmap and read *it* in... */
if ((bitsize = (*info)->bmiHeader.biSizeImage) == 0)
bitsize = ((*info)->bmiHeader.biWidth *
(*info)->bmiHeader.biBitCount + 7) / 8 *
abs((*info)->bmiHeader.biHeight);
if ((bits = malloc(bitsize)) == NULL)
{
/* Couldn't allocate memory - return NULL! */
free(*info);
fclose(fp);
return (NULL);
}
if (fread(bits, 1, bitsize, fp) < bitsize)
{
/* Couldn't read bitmap - free memory and return NULL! */
free(*info);
free(bits);
fclose(fp);
return (NULL);
}
/* OK, everything went fine - return the allocated bitmap... */
fclose(fp);
return (bits);
}

/*
* 'SaveDIBitmap()' - Save a DIB/BMP file to disk.
*
* Returns 0 on success or -1 on failure...
*/
int /* O - 0 = success, -1 = failure */
SaveDIBitmap(const char *filename, /* I - File to load */
BITMAPINFO *info, /* I - Bitmap information */
GLubyte *bits) /* I - Bitmap data */
{
FILE *fp; /* Open file pointer */
int size, /* Size of file */
infosize, /* Size of bitmap info */
bitsize; /* Size of bitmap pixels */
BITMAPFILEHEADER header; /* File header */

/* Try opening the file; use "wb" mode to write this *binary* file. */
if ((fp = fopen(filename, "wb")) == NULL)
return (-1);
/* Figure out the bitmap size */
if (info->bmiHeader.biSizeImage == 0)
bitsize = (info->bmiHeader.biWidth *
info->bmiHeader.biBitCount + 7) / 8 *
abs(info->bmiHeader.biHeight);
else
bitsize = info->bmiHeader.biSizeImage;
/* Figure out the header size */
infosize = sizeof(BITMAPINFOHEADER);
switch (info->bmiHeader.biCompression)
{
case BI_BITFIELDS :
infosize += 12; /* Add 3 RGB doubleword masks */
if (info->bmiHeader.biClrUsed == 0)
break;
case BI_RGB :
if (info->bmiHeader.biBitCount > 8 &&amp;
info->bmiHeader.biClrUsed == 0)
break;
case BI_RLE8 :
case BI_RLE4 :
if (info->bmiHeader.biClrUsed == 0)
infosize += (1 <<> bmiHeader.biBitCount) * 4;
else
infosize += info->bmiHeader.biClrUsed * 4;
break;
}
size = sizeof(BITMAPFILEHEADER) + infosize + bitsize;
/* Write the file header, bitmap information, and bitmap pixel data... */
header.bfType = 'MB'; /* Non-portable... sigh */
header.bfSize = size;
header.bfReserved1 = 0;
header.bfReserved2 = 0;
header.bfOffBits = sizeof(BITMAPFILEHEADER) + infosize;
if (fwrite(&header, 1, sizeof(BITMAPFILEHEADER), fp) < sizeof(BITMAPFILEHEADER))
{
/* Couldn't write the file header - return... */
fclose(fp);
return (-1);
}
if (fwrite(info, 1, infosize, fp) < infosize)
{
/* Couldn't write the bitmap header - return... */
fclose(fp);
return (-1);
}
if (fwrite(bits, 1, bitsize, fp) < bitsize)
{
/* Couldn't write the bitmap - return... */
fclose(fp);
return (-1);
}
/* OK, everything went fine - return... */
fclose(fp);
return (0);
}

#else /* !WIN32 */
/*
* Functions for reading and writing 16- and 32-bit little-endian integers.
*/
static unsigned short read_word(FILE *fp);
static unsigned int read_dword(FILE *fp);
static int read_long(FILE *fp);
static int write_word(FILE *fp, unsigned short w);
static int write_dword(FILE *fp, unsigned int dw);
static int write_long(FILE *fp, int l);

/*
* 'LoadDIBitmap()' - Load a DIB/BMP file from disk.
*
* Returns a pointer to the bitmap if successful, NULL otherwise...
*/
GLubyte * /* O - Bitmap data */
LoadDIBitmap(const char *filename, /* I - File to load */
BITMAPINFO **info) /* O - Bitmap information */
{
FILE *fp; /* Open file pointer */
GLubyte *bits; /* Bitmap pixel bits */
GLubyte *ptr; /* Pointer into bitmap */
GLubyte temp; /* Temporary variable to swap red and blue */
int x, y; /* X and Y position in image */
int length; /* Line length */
int bitsize; /* Size of bitmap */
int infosize; /* Size of header information */
BITMAPFILEHEADER header; /* File header */

/* Try opening the file; use "rb" mode to read this *binary* file. */
if ((fp = fopen(filename, "rb")) == NULL)
return (NULL);
/* Read the file header and any following bitmap information... */
header.bfType = read_word(fp);
header.bfSize = read_dword(fp);
header.bfReserved1 = read_word(fp);
header.bfReserved2 = read_word(fp);
header.bfOffBits = read_dword(fp);
if (header.bfType != BF_TYPE) /* Check for BM reversed... */
{
/* Not a bitmap file - return NULL... */
fclose(fp);
return (NULL);
}
infosize = header.bfOffBits - 18;
if ((*info = (BITMAPINFO *)malloc(sizeof(BITMAPINFO))) == NULL)
{
/* Couldn't allocate memory for bitmap info - return NULL... */
fclose(fp);
return (NULL);
}
(*info)->bmiHeader.biSize = read_dword(fp);
(*info)->bmiHeader.biWidth = read_long(fp);
(*info)->bmiHeader.biHeight = read_long(fp);
(*info)->bmiHeader.biPlanes = read_word(fp);
(*info)->bmiHeader.biBitCount = read_word(fp);
(*info)->bmiHeader.biCompression = read_dword(fp);
(*info)->bmiHeader.biSizeImage = read_dword(fp);
(*info)->bmiHeader.biXPelsPerMeter = read_long(fp);
(*info)->bmiHeader.biYPelsPerMeter = read_long(fp);
(*info)->bmiHeader.biClrUsed = read_dword(fp);
(*info)->bmiHeader.biClrImportant = read_dword(fp);
if (infosize > 40)
if (fread((*info)->bmiColors, infosize - 40, 1, fp) < 1)
{
/* Couldn't read the bitmap header - return NULL... */
free(*info);
fclose(fp);
return (NULL);
}
/* Now that we have all the header info read in, allocate memory for *
* the bitmap and read *it* in... */
if ((bitsize = (*info)->bmiHeader.biSizeImage) == 0)
bitsize = ((*info)->bmiHeader.biWidth *
(*info)->bmiHeader.biBitCount + 7) / 8 *
abs((*info)->bmiHeader.biHeight);
if ((bits = malloc(bitsize)) == NULL)
{
/* Couldn't allocate memory - return NULL! */
free(*info);
fclose(fp);
return (NULL);
}
if (fread(bits, 1, bitsize, fp) < bitsize)
{
/* Couldn't read bitmap - free memory and return NULL! */
free(*info);
free(bits);
fclose(fp);
return (NULL);
}
/* Swap red and blue */
length = ((*info)->bmiHeader.biWidth * 3 + 3) & ~3;
for (y = 0; y < (*info)-> bmiHeader.biHeight; y ++)
for (ptr = bits + y * length, x = (*info)->bmiHeader.biWidth;
x > 0;
x --, ptr += 3)
{
temp = ptr[0];
ptr[0] = ptr[2];
ptr[2] = temp;
}
/* OK, everything went fine - return the allocated bitmap... */
fclose(fp);
return (bits);
}

/*
* 'SaveDIBitmap()' - Save a DIB/BMP file to disk.
*
* Returns 0 on success or -1 on failure...
*/
int /* O - 0 = success, -1 = failure */
SaveDIBitmap(const char *filename, /* I - File to load */
BITMAPINFO *info, /* I - Bitmap information */
GLubyte *bits) /* I - Bitmap data */
{
FILE *fp; /* Open file pointer */
int size, /* Size of file */
infosize, /* Size of bitmap info */
bitsize; /* Size of bitmap pixels */

/* Try opening the file; use "wb" mode to write this *binary* file. */
if ((fp = fopen(filename, "wb")) == NULL)
return (-1);
/* Figure out the bitmap size */
if (info->bmiHeader.biSizeImage == 0)
bitsize = (info->bmiHeader.biWidth *
info->bmiHeader.biBitCount + 7) / 8 *
abs(info->bmiHeader.biHeight);
else
bitsize = info->bmiHeader.biSizeImage;
/* Figure out the header size */
infosize = sizeof(BITMAPINFOHEADER);
switch (info->bmiHeader.biCompression)
{
case BI_BITFIELDS :
infosize += 12; /* Add 3 RGB doubleword masks */
if (info->bmiHeader.biClrUsed == 0)
break;
case BI_RGB :
if (info->bmiHeader.biBitCount > 8 &&amp;
info->bmiHeader.biClrUsed == 0)
break;
case BI_RLE8 :
case BI_RLE4 :
if (info->bmiHeader.biClrUsed == 0)
infosize += (1 <<> bmiHeader.biBitCount) * 4;
else
infosize += info->bmiHeader.biClrUsed * 4;
break;
}
size = sizeof(BITMAPFILEHEADER) + infosize + bitsize;
/* Write the file header, bitmap information, and bitmap pixel data... */
write_word(fp, BF_TYPE); /* bfType */
write_dword(fp, size); /* bfSize */
write_word(fp, 0); /* bfReserved1 */
write_word(fp, 0); /* bfReserved2 */
write_dword(fp, 18 + infosize); /* bfOffBits */
write_dword(fp, info->bmiHeader.biSize);
write_long (fp, info-> bmiHeader.biWidth);
write_long (fp, info-> bmiHeader.biHeight);
write_word (fp, info-> bmiHeader.biPlanes);
write_word (fp, info-> bmiHeader.biBitCount );
write_dword (fp, info-> bmiHeader.biCompression);
write_dword (fp, info-> bmiHeader.biSizeImage);
write_long (fp, info-> bmiHeader.biXPelsPerMeter);
write_long (fp, info-> bmiHeader . biYPelsPerMeter);
write_dword (fp, info-> bmiHeader.biClrUsed);
write_dword (fp, info-> bmiHeader.biClrImportant);
if (info-size> 40)
if (fwrite (info-> bmiColors, info-size - 40 , 1, fp) < 1)
{
/* Couldn't write the bitmap header - return... */
fclose(fp);
return (-1);
}
if (fwrite(bits, 1, bitsize, fp) < bitsize)
{
/* Couldn't write the bitmap - return... */
fclose(fp);
return (-1);
}
/* OK, everything went fine - return... */
fclose(fp);
return (0);
}

/*
* 'read_word()' - Read a 16-bit unsigned integer.
*/
static unsigned short /* O - 16-bit unsigned integer */
read_word(FILE *fp) /* I - File to read from */
{
unsigned char b0, b1; /* Bytes from file */
b0 = getc(fp);
b1 = getc(fp);
return ((b1 << 8) b0);
}

/*
* 'read_dword()' - Read a 32-bit unsigned integer.
*/
static unsigned int /* O - 32-bit unsigned integer */
read_dword(FILE *fp) /* I - File to read from */
{
unsigned char b0, b1, b2, b3; /* Bytes from file */
b0 = getc(fp);
b1 = getc(fp);
b2 = getc(fp);
b3 = getc(fp);
return ((((((b3 << 8) b2) << 8) b1) << 8) b0);
}

/*
* 'read_long()' - Read a 32-bit signed integer.
*/
static int /* O - 32-bit signed integer */
read_long(FILE *fp) /* I - File to read from */
{
unsigned char b0, b1, b2, b3; /* Bytes from file */
b0 = getc(fp);
b1 = getc(fp);
b2 = getc(fp);
b3 = getc(fp);
return ((int)(((((b3 << 8) b2) << 8) b1) << 8) b0);
}

/*
* 'write_word()' - Write a 16-bit unsigned integer.
*/
static int /* O - 0 on success, -1 on error */
write_word(FILE *fp, /* I - File to write to */
unsigned short w) /* I - Integer to write */
{
putc(w, fp);
return (putc(w >> 8, fp));
}

/*
* 'write_dword()' - Write a 32-bit unsigned integer.
*/
static int /* O - 0 on success, -1 on error */
write_dword(FILE *fp, /* I - File to write to */
unsigned int dw) /* I - Integer to write */
{
putc(dw, fp);
putc(dw >> 8, fp);
putc(dw >> 16, fp);
return (putc(dw >> 24, fp));
}

/*
* 'write_long()' - Write a 32-bit signed integer.
*/
static int /* O - 0 on success, -1 on error */
write_long(FILE *fp, /* I - File to write to */
int l) /* I - Integer to write */
{
putc(l, fp);
putc(l >> 8, fp);
putc(l >> 16, fp);
return (putc(l >> 24, fp));
}
#endif /* WIN32 */

LIBRERIA AUXILIAR BITMAP.H
#ifndef _BITMAP_H_
# define _BITMAP_H_
/*
* Include necessary headers.
*/
# include
# ifdef WIN32
# include
# include
# endif /* WIN32 */
/*
* Make this header file work with C and C++ source code...
*/
# ifdef __cplusplus
extern "C" {
# endif /* __cplusplus */

/*
* Bitmap file data structures (these are defined in under
* Windows...)
*
* Note that most Windows compilers will pack the following structures, so
* when reading them under MacOS or UNIX we need to read individual fields
* to avoid differences in alignment...
*/
# ifndef WIN32
typedef struct /**** BMP file header structure ****/
{
unsigned short bfType; /* Magic number for file */
unsigned int bfSize; /* Size of file */
unsigned short bfReserved1; /* Reserved */
unsigned short bfReserved2; /* ... */
unsigned int bfOffBits; /* Offset to bitmap data */
} BITMAPFILEHEADER;
# define BF_TYPE 0x4D42 /* "MB" */
typedef struct /**** BMP file info structure ****/
{
unsigned int biSize; /* Size of info header */
int biWidth; /* Width of image */
int biHeight; /* Height of image */
unsigned short biPlanes; /* Number of color planes */
unsigned short biBitCount; /* Number of bits per pixel */
unsigned int biCompression; /* Type of compression to use */
unsigned int biSizeImage; /* Size of image data */
int biXPelsPerMeter; /* X pixels per meter */
int biYPelsPerMeter; /* Y pixels per meter */
unsigned int biClrUsed; /* Number of colors used */
unsigned int biClrImportant; /* Number of important colors */
} BITMAPINFOHEADER;
/*
* Constants for the biCompression field...
*/
# define BI_RGB 0 /* No compression - straight BGR data */
# define BI_RLE8 1 /* 8-bit run-length compression */
# define BI_RLE4 2 /* 4-bit run-length compression */
# define BI_BITFIELDS 3 /* RGB bitmap with RGB masks */
typedef struct /**** Colormap entry structure ****/
{
unsigned char rgbBlue; /* Blue value */
unsigned char rgbGreen; /* Green value */
unsigned char rgbRed; /* Red value */
unsigned char rgbReserved; /* Reserved */
} RGBQUAD;
typedef struct Bitmap information structure ****/ /****
{BITMAPINFOHEADER bmiHeader
/ * Image header * /
RGBQUAD bmiColors [256] / * Image colormap * /}
BITMAPINFO;
# endif / *! WIN32 * /
/ * * Prototypes
...
* / extern GLubyte * LoadDIBitmap
(const char * filename, BITMAPINFO ** info);
SaveDIBitmap extern int (const char * filename, BITMAPINFO * info,
GLubyte * bits);

# ifdef __cplusplus} # endif
/ * __cplusplus * /
# endif / *! _BITMAP_H_ * /

Note: To observe the texture is necessary to take pictures

0 comments:

Post a Comment