Basic texturing problem

I’m having a little problem with a very basic texturing program.

The program is supposed to display 2 textured polygons (squares in this case).

Unfortunately, I only seem to get the top part of each square showing the texture.
http://photos-c.ak.fbcdn.net/hphotos-ak-…0_6442172_n.jpg

Here is the code.



#include <GLUT/GLUT.h>
#include <stdio.h>

GLuint texture;

GLuint LoadTexture( const char * filename, int width, int height, int wrap )
{
    GLuint texture;
    unsigned char * data;
    FILE * file;
	
    file = fopen( filename, "rb" );
    if ( file == NULL ) return 0;
    data = (unsigned char *)malloc( width * height * 3 );
    fread( data, width * height * 3, 1, file );
    fclose( file );
	
    glGenTextures( 1, &texture );
    glBindTexture( GL_TEXTURE_2D, texture );
    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,	GL_MODULATE );
		
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap ? GL_REPEAT : GL_CLAMP );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap ? GL_REPEAT : GL_CLAMP );
	
    gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGB, width, height, GL_RGB, GL_UNSIGNED_BYTE, data );
    free( data );
    return texture;
}
	
void FreeTexture( GLuint texture )
{	glDeleteTextures( 1, &texture ); }

void drawplane()
{
	
	glBegin(GL_TRIANGLE_STRIP);
	glTexCoord2f(1.0,0.0); glVertex3f(2.0,-2.0,-2.0);
	glTexCoord2f(0.0,0.0); glVertex3f(-2.0,-2.0,-2.0);
	glTexCoord2f(1.0,1.0); glVertex3f(2.0,-2.0,2.0);
	glTexCoord2f(0.0,1.0); glVertex3f(-2.0,-2.0,2.0);
	glEnd();
}

void drawPlanes()
{
	glPushMatrix();
	glTranslated(-2.5,0.0,0.0);
	glRotatef(90.0, 1.0, 0.0, 0.0);
	drawplane();
	glPopMatrix();
	
	glPushMatrix();
	glTranslated(2.5,0.0,0.0);
	glRotatef(90.0, 1.0, 0.0, 0.0);
	drawplane();
	glPopMatrix();
}
	
void display (void) 
{
    glClearColor (0.0,0.0,0.0,1.0);
    glClear (GL_COLOR_BUFFER_BIT);
    glLoadIdentity();  
    gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

    texture = LoadTexture( "texture.raw", 256, 256, TRUE); 

    glEnable(GL_TEXTURE_2D); //enable 2D texturing
    glBindTexture(GL_TEXTURE_2D, texture);
    drawPlanes();
    FreeTexture(texture);
    glutSwapBuffers();
}
	
void reshape (int w, int h) 
{
    glViewport (0, 0, (GLsizei)w, (GLsizei)h);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    gluPerspective (60, (GLfloat)w/(GLfloat)h, 1.0, 100.0);
    glMatrixMode (GL_MODELVIEW);
}
	
int main (int argc, char **argv) 
{
    glutInit (&argc, argv);
    glutInitDisplayMode (GLUT_DOUBLE);
    glutInitWindowSize (600, 500);
    glutInitWindowPosition (20, 100);
    glutCreateWindow ("Texturing");
    glutDisplayFunc (display);
    glutIdleFunc (display);
    glutReshapeFunc (reshape);
    glutMainLoop ();
    return 0;
}  

You may recognize some of the code, most of it is taken from Swiftless’ Tutorial.

Any advice is appreciated.

Raw files consist of a short header file.You need to skip the header file and read the actual image data.gluBuild2DMipmaps() accepts the image data without any extra information.

Ok.

Huh?

The extra information that is ignored by gluBuild2DMipmaps() is not the header file? But if this extra information isn’t the header file then, according to your first sentence, it should be ignored while the rest of the image data is read?

Your wording is a bit misleading.

What i think you mean to say is that when the raw file is being read, the header file is included which is causing the error in the display. I need to remove/skip the header file before gluBuild2DMipmaps is called.

Yes?

you must send the “image data” to gluBuild2DMipmaps() :slight_smile: each image file consists of a header file and data. you need to read the header file to access the actual data. then you create a new buffer and copy that data into the new buffer.After that you send the address of this buffer to gluBuild2DMipmaps().