Texture mapping problem
Here:
#include<stdio.h>
#include<conio.h>
#include <graphics.h>
#include <stdlib.h>
#include <alloc.h>
///////////////////////////////////////////////// BMP format structures
typedef struct tagBITMAPFILEHEADER {
int bfType;
long bfSize;
int bfReserved1;
int bfReserved2;
long bfOffbits;
}BITMAPFILEHEADER;
typedef struct tagBITMAPINFOHEADER {
long biSize;
long biWidth;
long biHeight;
int biPlanes;
int biBitCount;
long biCompression;
long biSizeImage;
long biXPelsPerMeter;
long biYPelPerMeter;
long biClrUsed;
long biClrImportant;
} BITMAPINFOHEADER;
typedef struct tagRGBQUAD {
char rgbRed;
char rgbGreen;
char rgbBlue;
char rgbRserved;
} RGBQUAD;
typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[256];
}BITMAPINFO;
///////////////////////////////////////////////// SVGA256 set functions
int huge p(void) { return(2); }
void setvideo()
{ int gdriver,gmode;
// gdriver=installuserdriver("svga256",p);
gdriver=DETECT;
initgraph(&gdriver,&gmode,"c:\\minc\\bgi");
}
///////////////////////////////////////////////// MAIN
void main(){
FILE *bmpfile;
BITMAPFILEHEADER bheader;
BITMAPINFO binfo;
char color, huge *buff;
long rest, width, i, j, k;
clrscr();
bmpfile=fopen("my.bmp", "rb");
// read info
fread(&bheader, sizeof(bheader), 1, bmpfile);
fread(&binfo, sizeof(binfo), 1, bmpfile);
fseek(bmpfile, bheader.bfOffbits, 0);
// picture width score
if(rest=binfo.bmiHeader.biWidth % 4)
width = binfo.bmiHeader.biWidth+ 4-rest;
else
width = binfo.bmiHeader.biWidth;
// from file to array (64K==MAX)
buff=(char far *)farmalloc(binfo.bmiHeader.biHeight*width);
k=0;
for(j=0; j<binfo.bmiHeader.biHeight; j++)
for(int i=0; i<width; i++){
fread(&color, sizeof(color), 1, bmpfile);
buff[k++]=color;
}
setvideo();
// set palette
for(i=0; i<256;i++)
setrgbpalette(i, binfo.bmiColors[i].rgbBlue>>2,
binfo.bmiColors[i].rgbGreen>>2,
binfo.bmiColors[i].rgbRed>>2
);
// drowing
k=0;
for(j=binfo.bmiHeader.biHeight; j>0; j--)
for(int i=0; i<width; i++){
putpixel(i, j, buff[k++]);
}
getch();
closegraph();
fclose(bmpfile);
}
Rate me please.
×