Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


What's wrong with this code?

This topic is 6724 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 }

Share this post

Link to post
Share on other sites
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


#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

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!