KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to set a background image of my openGL window by creating a quad on an orthogonal projection matrix and adding texture to it. I am also making use of GLUT toolkit in my application. However I am having several problems. Below are screenshot illustrating the problem: image is grayscale and it repeats on x and y, even though texture size is set to be the same as the quad. That is what I am trying to achieve: And that is what I am getting: Code for rendering and loading texture looks like this: void orthogonalStart (void) { glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0, w1, 0, h1); glScalef(1, -1, 1); glTranslatef(0, -h1, 0); glMatrixMode(GL_MODELVIEW); } void orthogonalEnd (void) { glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); } GLuint LoadTexture( const char * filename, int width, int height ) { GLuint texture; unsigned char * data; FILE * file; //The following code will read in our RAW 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 ); //even better quality, but this will do for now. glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR ); //to the edge of our shape. glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); //Generate the texture glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
Tags (comma-separated)
Save Edits
Cancel