What's wrong with this code?
ok, the problem here is that it loads tstfile.txt which holds
''data/hull.bmp'' in it. This filename is loaded into pText which passes it to AUX_RGBBMP load function.
The BMPloader will not load it. Unless I put in direct quotes:
pText="data/hull.bmp" it will load.
*ps This code was a pain to format and get into this message box-
how do you people do it in an easier way?
int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
int Status=FALSE; // Status Indicator
char *pText;
char text[256];
FILE *fp;
fpos_t pos;
if ((fp=fopen("data/tstfile.txt","r"))!=NULL)
{
fgets(text,256,fp);
fgetpos(fp,&pos);
//pText = strstr(text,"Shawn");
pText = strstr(text,"d");
pText = strtok(pText,"\"");
}
fclose(fp);
// "data/tstfile.txt" holds this:
// data/hull.bmp
// it loads it into pText
// so I get a messagebox to tell me what''s in
// pText, and it tells me this:
// data/hull.bmp, so I know pText
// holds ''data/hull.bmp'' with no quotes.
// but auxDIBLoadBMP function will not load that,
// however if I give it the filename
// directly in quotes it will load.
AUX_RGBImageRec *TextureImage[1]; // Create Storage
// Space For The
// Texture
memset(TextureImage,0,sizeof(void *)*1); // Set The
// Pointer To NULL
// Load The Bitmap, Check For Errors, If Bitmap''s Not
// Found Quit
// if (TextureImage[0]=LoadBMP("data/hull.bmp"))
// This works
// pText="data/hull.bmp"; this works also
if (TextureImage[0]=LoadBMP(pText))
{
Status=TRUE; // Set
// The Status To TRUE
glGenTextures(3, &texture[0]); //
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
}
AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image
{
FILE *File=NULL; // File Handle
if (!Filename) // Make Sure A Filename Was Given
{
return NULL; // If Not Return NULL
}
File=fopen(Filename,"r"); // Check To See If The File Exists
if (File) // Does The File Exist?
{
fclose(File); // Close The Handle
return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer
}
return NULL; // If Load Failed Return NULL
}
I really tried to debug it ( created workspace in msvc6, copy paste, cut, add )
its realy pain in the A$$ to debug that, so i wrote a substitute to at least have something to offer =)
text.txt contained data\file.bmp...its complied and works.
(just call getline again if there are more lines in the file, it reads 512 chars or to next new line)
the / at ios:: is binary or
Edited by - Claus Hansen Ries on June 21, 2000 2:17:15 PM
its realy pain in the A$$ to debug that, so i wrote a substitute to at least have something to offer =)
text.txt contained data\file.bmp...its complied and works.
(just call getline again if there are more lines in the file, it reads 512 chars or to next new line)
the / at ios:: is binary or
#include "stdafx.h"#include "stdio.h"#include "gl\gl.h"#include "gl\glaux.h"#include "fstream.h"int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ fstream file; file.open( ".\\data\\text.txt", ios::in/ios::nocreate ); if( !file ) { MessageBox( NULL, "no file", "INFO", NULL ); return 0; } char scanline[512]; file.getline( scanline, 512 ); MessageBox( NULL, scanline, "INFO", NULL ); AUX_RGBImageRec *TextureImage = NULL; // Create Storage TextureImage = auxDIBImageLoad(scanline); // Load The Bitmap And Return A Pointer if( !TextureImage ) { MessageBox( NULL, "Failed to load bmp", "INFO", NULL ); return 0; } MessageBox( NULL, "Loaded succesfully", "INFO", NULL ); return 1;}
Edited by - Claus Hansen Ries on June 21, 2000 2:17:15 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement