«یا اللهُ یا رَبِّ یا حَیُّ یا قَیّوم یا ذَالجَلالِ وَ الاکرام اَسئَلُکَ بِاسمِکَ اَلعَظیم اَلاَعظَم اَن تَرزُقَنی رِزقاً حَلالاً طَیِّباً بِرَحمَتِکَ الواسِعَه یا اَرحَمَ الرّاحِمِین.»
لود فایل بیت مپ با اپن جی ال+خواندن فایل تصویری و نمایش آن توسط openGL :: گیم اور _ بازیسازی با unity + مطالب متفرقه

گیم اور _ بازیسازی با unity + مطالب متفرقه

آموزش های علمی با اجازه ی خدا تقدیم به هرکس خدا بخواد

آموزش های علمی با اجازه ی خدا تقدیم به هرکس خدا بخواد

به نام خدا
--
گروه قدیم ما promakers.ir یا پرومیکرز بود که بالای هزار اموزش توش ساخته بودم به اسم sajjad3011 ولی حیف ادمین سایتش عوض کرد
حالا سوالی بود کاری بود این شمارمه

قدیمیا دلم براتون تنگ شده... فقط معرفی کنید توی پیامک یا تماس یاد بیارید.
اگه جواب ندادم شاید موقعیت نداشته باشم.
بگید توی پیام از بچه های پرومیکرز هستید.

---
سوالی بود بذارید
نظر خصوصی نذارید
پاسخش سخته
دوست داشتید شماره بذارید تو واتساپ یا ایتا یا .... گروه بزنیم.
09358077198

بایگانی
پیوندها
منبع:gameover.blog.ir
این کد بسیار کمیاب هست و بهترین کدی بود که براتون قرار میدیم:
نمایش فایل bmp:
ابتدا تابع LoadBitmapFile رو کدنویسی می کنیم:

unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader)
{
FILE *filePtr; // the file pointer
BITMAPFILEHEADER bitmapFileHeader; // bitmap file header
unsigned char *bitmapImage; // bitmap image data
int imageIdx = 0; // image index counter
unsigned char tempRGB; // swap variable
// open filename in "read binary" mode
filePtr = fopen(filename, "rb");
if (filePtr == NULL)
return NULL;
// read the bitmap file header
fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);
// verify that this is a bitmap by checking for the universal bitmap id
if (bitmapFileHeader.bfType != BITMAP_ID)
{
fclose(filePtr);
return NULL;
}
// read the bitmap information header
fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);
// move file pointer to beginning of bitmap data
fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);
// allocate enough memory for the bitmap image data
bitmapImage = (unsigned char*)malloc(bitmapInfoHeader->biSizeImage);
// verify memory allocation
if (!bitmapImage)
{
free(bitmapImage);
fclose(filePtr);
return NULL;
}
// read in the bitmap image data
fread(bitmapImage, 1, bitmapInfoHeader->biSizeImage, filePtr);
// make sure bitmap image data was read
if (bitmapImage == NULL)
{
fclose(filePtr);
return NULL;
}

// swap the R and B values to get RGB since the bitmap color format is in BGR
for (imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx+=3)
{
tempRGB = bitmapImage[imageIdx];
bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
bitmapImage[imageIdx + 2] = tempRGB;
}
// close the file and return the bitmap image data
fclose(filePtr);
return bitmapImage;
}
fread تابع خواندن از فایل هست. f به معنی file می باشد.
 توضیحات هر خط در کد بعد از // اومده . اگه یکم زبانتون خوب کنید متوجه میشید.
حالا با کد زیر برنامه رو تکمیل می کنیم و از تابعی که در بالا نوشتیم استفاده می کنیم:
void Initialize()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // clear background to black
glShadeModel(GL_SMOOTH); // use smooth shading
glEnable(GL_DEPTH_TEST); // hidden surface removal
glEnable(GL_CULL_FACE); // do not calculate inside of polys
glFrontFace(GL_CCW); // counterclockwise polygons are out
glEnable(GL_TEXTURE_2D); // enable 2D texturing
// load our bitmap file
bitmapData = LoadBitmapFile("checker.bmp", &bitmapInfoHeader);
glGenTextures(1, &texture); // generate texture object
glBindTexture(GL_TEXTURE_2D, texture); // bind the texture
AN OVERVIEW OF TEXTURE MAPPING
236
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
// load the texture image
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, bitmapInfoHeader.biWidth,
bitmapInfoHeader.biHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, bitmapData);
}


ذخیره اسکرین شات در فایل BMP:
void SaveScreenshot(int winWidth, int winHeight)
{
imageData = malloc(winWidth*winHeight*3); // allocate memory for the imageData
memset(imageData, 0, winWidth*winHeight*3); // clear imageData memory contents
// read the image data from the window
glReadPixels(0, 0, winWidth–1, winHeight–1, GL_RGB, GL_UNSIGNED_BYTE, imageData);
// write the image data to a file
WriteBitmapFile("writeout.bmp", winWidth, winHeight, (unsigned char*)imageData);
// free the image data memory
free(imageData);
}


نظرات (۰)

هیچ نظری هنوز ثبت نشده است

ارسال نظر

ارسال نظر آزاد است، اما اگر قبلا در بیان ثبت نام کرده اید می توانید ابتدا وارد شوید.
شما میتوانید از این تگهای html استفاده کنید:
<b> یا <strong>، <em> یا <i>، <u>، <strike> یا <s>، <sup>، <sub>، <blockquote>، <code>، <pre>، <hr>، <br>، <p>، <a href="" title="">، <span style="">، <div align="">
تجدید کد امنیتی