i load a texture using
int loadTexture ( char *filename ) { GLuint retval; SDL_Surface *sdlimage; void *raw; int w, h, i, j, bpp; Uint8 *srcPixel, *dstPixel; Uint32 truePixel; GLenum errorCode; sdlimage = IMG_Load(filename); if ( !sdlimage ) { printf("SDL_Image load error: %s\n", IMG_GetError()); return 0; } if ( sdlimage->format->BytesPerPixel < 2 ) { printf("Bad image -- not true color!\n"); return 0; } w = sdlimage->w; h = sdlimage->h; raw = (void *)malloc( w * h * 4 ); dstPixel = (Uint8 *)raw; SDL_LockSurface( sdlimage ); bpp = sdlimage->format->BytesPerPixel; for ( i = h ; i > 0 ; i-- ) { for ( j = 0 ; j < w ; j++ ) { srcPixel = (Uint8 *)sdlimage->pixels + i * sdlimage->pitch + j * bpp; switch (bpp) { case 1: truePixel = *srcPixel; break; case 2: truePixel = *(Uint16 *)srcPixel; break; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { truePixel = srcPixel[0] << 16 | srcPixel[1] << 8 | srcPixel[2]; } else { truePixel = srcPixel[0] | srcPixel[1] << 8 | srcPixel[2] << 16; } break; case 4: truePixel = *(Uint32 *)srcPixel; break; default: printf("Image bpp of %d unusable\n", bpp); return 0; break; } SDL_GetRGBA( truePixel, sdlimage->format, &(dstPixel[0]), &(dstPixel[1]), &(dstPixel[2]), &(dstPixel[3])); dstPixel++; dstPixel++; dstPixel++; dstPixel++; } } SDL_UnlockSurface( sdlimage ); SDL_FreeSurface( sdlimage ); glGenTextures( 1, &retval ); glBindTexture( GL_TEXTURE_2D, retval ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); errorCode = glGetError(); if ( errorCode != 0 ) { if ( errorCode == GL_OUT_OF_MEMORY ) { printf("Out of texture memory!\n"); } return 0; } gluBuild2DMipmaps( GL_TEXTURE_2D, 4, w, h, GL_RGBA, GL_UNSIGNED_BYTE, (Uint8 *)raw); errorCode = glGetError(); if ( errorCode != 0 ) { if ( errorCode == GL_OUT_OF_MEMORY ) { printf("Out of texture memory!\n"); } return 0; } return retval;}
put the value in a global var called menu, when i try to texture it onto a quad using
glBindTexture(GL_TEXTURE_2D, menu); glTexEnvf(GL_TEXTURE_2D,GL_TEXTURE_ENV_MODE,GL_REPLACE); glBegin( GL_QUADS ); glTexCoord2d(0.0,0.0); glVertex2d(0.0,0.0); glTexCoord2d(1.0,0.0); glVertex2d(1.0,0.0); glTexCoord2d(1.0,1.0); glVertex2d(1.0,1.0); glTexCoord2d(0.0,1.0); glVertex2d(0.0,1.0); glEnd();
i get an untextured basic quad... i really dont know wth is wrong with it... also if anyone could tell me how to have this quad over all other objects in the scene(need it for a 2d hud kind of thing) aswell, id be very grateful
thanks!