void render() { //Clear color buffer glClear( GL_COLOR_BUFFER_BIT ); //Calculate texture maxima GLfloat textureRight = (GLfloat)SCREEN_WIDTH / (GLfloat)gRepeatingTexture.textureWidth(); GLfloat textureBottom = (GLfloat)SCREEN_HEIGHT / (GLfloat)gRepeatingTexture.textureHeight(); //Use repeating texture glBindTexture( GL_TEXTURE_2D, gRepeatingTexture.getTextureID() ); //Switch to texture matrix glMatrixMode( GL_TEXTURE ); //Reset transformation glLoadIdentity(); //Scroll texture glTranslatef( gTexX / gRepeatingTexture.textureWidth(), gTexY / gRepeatingTexture.textureHeight(), 0.f ); //Render glBegin( GL_QUADS ); glTexCoord2f( 0.f, 0.f ); glVertex2f( 0.f, 0.f ); glTexCoord2f( textureRight, 0.f ); glVertex2f( SCREEN_WIDTH, 0.f ); glTexCoord2f( textureRight, textureBottom ); glVertex2f( SCREEN_WIDTH, SCREEN_HEIGHT ); glTexCoord2f( 0.f, textureBottom ); glVertex2f( 0.f, SCREEN_HEIGHT ); glEnd(); //Update screen glutSwapBuffers(); }
void handleKeys( unsigned char key, int x, int y ) { //If q is pressed if( key == 'q' ) { //Bind texture for modification glBindTexture( GL_TEXTURE_2D, gStretchedTexture.getTextureID() ); //Toggle linear/nearest filtering if( gFiltering != GL_LINEAR ) { glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); gFiltering = GL_LINEAR; } else { glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); gFiltering = GL_NEAREST; } //Unbind texture glBindTexture( GL_TEXTURE_2D, NULL ); } }
void handleKeys( unsigned char key, int x, int y ) { //If q is pressed if( key == 'q' ) { //Cycle through texture reptetitions gTextureWrapType++; if( gTextureWrapType >= 2 ) { gTextureWrapType = 0; } //Set texture repetition glBindTexture( GL_TEXTURE_2D, gRepeatingTexture.getTextureID() ); switch( gTextureWrapType ) { case 0: glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); printf( "%d: GL_REPEAT\n", gTextureWrapType ); break; case 1: glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); printf( "%d: GL_CLAMP\n", gTextureWrapType ); break; } } }