PDA

View Full Version : loadtexture prob



ben1441
07-28-2003, 07:40 AM
I'm having trouble loading in a texture in .raw so I can paste it an object. I changedd this line of the tut so I could load my own image:

load_texture ( "C:\Documents and Settings\User\My Documents\My Pictures\aaliyah.raw", 640, 320, 3, GL_RGB, GL_LINEAR );

but I get the following errors:

23 C:\Program Files\c++\Dev-Cpp\ben-prog\texturesphere.cpp:60
[Warning] unknown escape sequence '\D'
23 C:\Program Files\c++\Dev-Cpp\ben-prog\texturesphere.cpp:60
non-hex digit 's' in universal-character-name
23 C:\Program Files\c++\Dev-Cpp\ben-prog\texturesphere.cpp:60
[Warning] unknown escape sequence '\M'

Anyone know what's wrong?

void load_texture ( char *file_name, int width, int height, int depth, GLenum colour_type, GLenum filter_type )
{
GLubyte *raw_bitmap ;
FILE *file;
if ((file = fopen(file_name, "rb"))==NULL)
{
printf("File Not Found : %s\n",file_name);
system("pause");
exit (1);
}
raw_bitmap = (GLubyte *) malloc ( width * height * depth * ( sizeof ( GLubyte )) );

if ( raw_bitmap == NULL )
{
printf ( "Cannot allocate memory for texture\n" );
system("pause");
fclose ( file );
exit ( 1 );
}
fread ( raw_bitmap , width * height * depth, 1 , file );
fclose ( file);
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter_type );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_type );

glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
gluBuild2DMipmaps ( GL_TEXTURE_2D, colour_type, width, height, colour_type, GL_UNSIGNED_BYTE, raw_bitmap );
free ( raw_bitmap );
}


void init(void)
{

glShadeModel(GL_FLAT);
glEnable ( GL_DEPTH_TEST );

glEnable ( GL_LIGHTING );
glLightModelfv ( GL_LIGHT_MODEL_AMBIENT, ambient_light );
glLightfv ( GL_LIGHT0, GL_DIFFUSE, source_light );
glLightfv ( GL_LIGHT0, GL_POSITION, light_pos );
glEnable ( GL_LIGHT0 );
glEnable ( GL_COLOR_MATERIAL );
glColorMaterial ( GL_FRONT, GL_AMBIENT_AND_DIFFUSE );
glEnable ( GL_TEXTURE_2D );
glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 );
load_texture ( "C:\Documents and Settings\User\My Documents\My Pictures\aaliyah.raw", 640, 320, 3, GL_RGB, GL_LINEAR );
glEnable ( GL_CULL_FACE );
glClearColor ( 0.0, 0.0, 0.0, 0.0 );

Bob
07-28-2003, 08:01 AM
In C++, \ is used as an escape character, which takes into account the next craracter in the string aswell. For example a \ followed by n ("\n") means new line, "\t" is a tab, and so on. \D, \U, \M which occurs in your string are not legal escape cratacters, but \a is. If you want a \ in your string, you need to escape the slash using a double slash, \\.

JanHH
07-28-2003, 08:04 AM
you can also use the unix version of path names ("/" instand of "\") in a windows program, might be a good idea because of better portability.

Jan