PDA

View Full Version : .raw loader prob



ben1441
07-31-2003, 02:56 AM
I'm having trouble with a .raw loader, the image (pic of pop singer) is pasted to a square but is just displayed as multicoloured lines going across. I've resized to 256by256, so that isn't the prob. Anyone know what's wrong?

static GLuint texName[1];

void load_texture ( char *file_name, int width, int height, int depth, GLenum colour_type, GLenum filter_type )
{
glGenTextures(1, texName);
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 );
//printf("%f",width);
//system("pause");
fclose ( file);
//glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter_type );
//glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_type );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
gluBuild2DMipmaps ( GL_TEXTURE_2D, colour_type, width, height, colour_type, GL_UNSIGNED_BYTE, raw_bitmap );
free ( raw_bitmap );
}

void init ( void )
{
glEnable ( GL_DEPTH_TEST );
glClearColor ( 0.0, 0.0, 0.0, 0.0 );

glEnable ( GL_TEXTURE_2D );
glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 );
load_texture ( "C:/Documents and Settings/User/My Documents/My Videos/aaliyah.raw", 332, 425, 3, GL_RGB, GL_LINEAR );


}

void square (void)
{

//glColor3f (1.0,1.0,1.0);
//glGenTextures(1, texName);
glBindTexture(GL_TEXTURE_2D, 0);
glBegin (GL_QUADS);
glTexCoord2f (0.0, 0.0);
glVertex3f (0.0, 0.0, 0.0);
glTexCoord2f (1.0, 0.0);
glVertex3f (10.0, 0.0, 0.0);
glTexCoord2f (1.0, 1.0);
glVertex3f (10.0, 10.0, 0.0);
glTexCoord2f (0.0, 1.0);
glVertex3f (0.0, 10.0, 0.0);
glEnd ();
//glutWireCube(1.0) ;

}

soda
08-05-2003, 09:10 AM
If your raw image is RGB, and R, G, B are coded with 1 byte you should only
have a size buffer with (width * height) pixels