문제

텍스처를 게임에 매핑하려고하지만 이미지는 정확하게 매핑되지 않았습니다. .BMP 형식 사진을 사용했습니다

내 코드는 다음과 같습니다.

GLuint LoadTexture( const char * filename, int width, int height ){
    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 );
    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 );

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
    free( data ); 
    return texture; 
}

here is the images

도움이 되었습니까?

해결책

BMP 파일의 크기가 14 바이트 인 BMP 파일의 "헤더"섹션이 항상 있으므로 15 번째 바이트에서 읽기 시작하는 것이 가장 좋습니다. 나는 많은 달 전에 당신과 똑같은 문제를 겪었습니다.

그래서 ... 당신의 앞에 이와 같은 함수 호출을 사용하십시오. fread:

 fseek ( file, 15, SEEK_SET);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top