C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 2nd, 2003, 01:37 PM
leftfield leftfield is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 55 leftfield User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 19 sec
Reputation Power: 6
bmp loader prob

I'm trying to load a bitmap so I can paste it to a square, but I don't think that the fopen(file, "rb"); function is getting the file name. Do I have to write something like -

file=" C:/Documents and Settings/User/My Documents/My Videos/aaliyah.bmp"

before fopen?

#define BITMAP_ID 0x4D42
BITMAPINFOHEADER bitmapInfoHeader;
unsigned char *bitmapData;
unsigned int texture;
bool InitializeGL();

unsigned char *LoadBitmapFile(char *file, BITMAPINFOHEADER *bitmapInfoHeader)
{

char image[] = { "C:/Documents and Settings/User/My Documents/My Videos/aaliyah.bmp" };

// Bitmaps are made up of 3 parts, the file header, info header, and
// the image. Once we load in the file and info headers we can then
// load the image into our unsigned char variable called bitmapData.

FILE *pFile; // Need this to open a file.
BITMAPFILEHEADER header; // This will hold the bitmap header information.

unsigned char *textureData; // This will hold the bitmap image itself.

// This will be used to swap the image colors from BGR to RGB.
unsigned char textureColors;
//bitmapData = LoadBitmapFile(image, &bitmapInfoHeader);

pFile = fopen(file, "rb"); // Open the file.

if(pFile == NULL) return NULL;// Check and make sure there are no errors.

// Read in the bitmap header info into the BITMAPFILEHEADER variable.
fread(&header, sizeof(BITMAPFILEHEADER), 1, pFile);

// Make sure this is a real bitmap by checking the ID.
if(header.bfType != BITMAP_ID)
{
fclose(pFile);
return NULL;
}

// Read in the second header info into the BITMAPINFOHEADER variable.
fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, pFile);

// Place the pointer in front of where the image data starts.
fseek(pFile, header.bfOffBits, SEEK_SET);

// Dynamically create enough memory for the image.
textureData = (unsigned char*)malloc(bitmapInfoHeader->biSizeImage);

// Error checking. Make sure the memory was allocated.
if(!textureData)
{
free(textureData);
fclose(pFile);
return NULL;
}

// Read in the image.
fread(textureData, 1, bitmapInfoHeader->biSizeImage, pFile);

// Error checking. Make sure an image was loaded.
if(textureData == NULL)
{
fclose(pFile);
return NULL;
}

// Bitmaps are saved in BGR format so we will make the image RGB by...
for(int index = 0; index < bitmapInfoHeader->biSizeImage; index+=3)
{
textureColors = textureData[index];
textureData[index] = textureData[index + 2];
textureData[index + 2] = textureColors;
}

fclose(pFile); // We are done with the file so close it.
return textureData; // Send the image to the function that called this.
}

Reply With Quote
  #2  
Old August 2nd, 2003, 02:01 PM
Woltan Woltan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 8 Woltan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hey
I had the problem a few days ago, just check load a bitmap post.
insted of using fopen, try the loadimage() mothod, it returns a handle to your bitmap. then you can draw the bitmap by bltbit().
but as i said check the posts
if you still have problems just post again and i will try to find some code for you

Reply With Quote
  #3  
Old August 2nd, 2003, 02:48 PM
leftfield leftfield is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 55 leftfield User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 19 sec
Reputation Power: 6
When u say check ur posts,do u mean the debug column? If so, how do u get that up and running, cos every time I open it, it's just blank. Thanks for your help, ben

Reply With Quote
  #4  
Old August 3rd, 2003, 05:26 PM
leftfield leftfield is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 55 leftfield User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 19 sec
Reputation Power: 6
I think the problem is with loading the file name into the image variable. Can anyone see why this won't load? (ie what I have to change about char image[] = { "C:/Documents and Settings/User/My Documents/My Pictures/aaliya.bmp" };
-

#define BITMAP_ID 0x4D42
BITMAPINFOHEADER bitmapInfoHeader;
unsigned char *bitmapData;
unsigned int texture;
unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader);

bool InitializeGL()
{
// Add to the status report that we are starting initialization. If
// the program crashed here we would know this was the function that
// caused a problem.
cout << "Starting Initialization...\n\n";

int PopUp;

// I decided to place the texture image name in a variable. This
// way if there was a problem with it (this is only useful if
// there was more than one) the name of the texture will be printed
// to the console screen along with a error message. I printed to
// the console screen instead of using MessageBoxes because I think
// its cooler.
char image[] = { "C:/Documents and Settings/User/My Documents/My Pictures/aaliya.bmp" };
// Enable texture mapping by sending GL_TEXTURE_2D to glEnable().
glEnable(GL_TEXTURE_2D);

// Now we load the image into memory.
// The line below shows why I decided to place the texture image name in a variable.
cout << "Loading image file " << image << " ...\n";

// Load the bitmap image into our global variable bitmapData.
bitmapData = LoadBitmapFile(image, &bitmapInfoHeader);

// If there was any errors then print this error message to the console screen.
if(!bitmapData)
{
cout << "Loading image " << image << " failed (check if file exist)...\n\n";
free(bitmapData);
return false;
}

// Next you must generate the texture in OpenGL.
glGenTextures(1, &texture);

// Lastly you bind the texture to the variable texture.
glBindTexture(GL_TEXTURE_2D, texture);

Reply With Quote
  #5  
Old August 5th, 2003, 04:10 AM
TechNoFear TechNoFear is offline
Offensive Member
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2002
Location: in the perfect world
Posts: 594 TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 14 h 6 m 15 sec
Reputation Power: 22
>>C:/Documents and Settings/User/My Documents/My Pictures/aaliya.bmp

using forward slashes where you need backslashes

try

C:\\Documents and Settings\\User\\My Documents\\My Pictures\\aaliya.bmp

need to use two backslashes to get one backslash.
__________________
The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

Frank Zappa

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > bmp loader prob


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT