2013-06-08 3 views
0

SDL_CreateRGBSurfaceSDL_FillRect 함수 인 을 사용하여 텍스처를 만들려고하고 있지만 슬프게도 실패합니다. 나가 얻는 모두는 까만 직사각형이다.OpenGL 텍스처를 사용하는 SDL_CreateRGBSurface가 검은 텍스처를 생성합니다.

내가 (IMG_Load와 파일에서로드 텍스처를 위해 노력하고 있습니다) 코드의 조각 다음 사용하고 그 작업을 달성하기

#if SDL_BYTEORDER == SDL_BIG_ENDIAN 
     rmask = 0xff000000; 
     gmask = 0x00ff0000; 
     bmask = 0x0000ff00; 
     amask = 0x000000ff; 
#else 
     rmask = 0x000000ff; 
     gmask = 0x0000ff00; 
     bmask = 0x00ff0000; 
     amask = 0xff000000; 
#endif 
     rect = SDL_CreateRGBSurface(SDL_SWSURFACE, _w,_h,24,rmask,gmask,bmask,amask); 
     if(rect == NULL) { 
      fprintf(stderr, "CreateRGBSurface failed: %s\n", SDL_GetError()); 
      exit(1); 
     } 

     Uint32 color = SDL_MapRGBA(rect->format,255,255,0,126); 
     SDL_FillRect(rect,NULL,color); 
     render.load(rect); 

텍스처 로딩에 앉아 코드를 다음과 같이를

void Texture::load(SDL_Surface* surface){ 
    ogl_check_error("surface load"); 
    GLenum texture_format; 
    GLint nOfColors; 
    if ( surface ) { 

     // get the number of channels in the SDL surface 
     nOfColors = surface->format->BytesPerPixel; 

     if (nOfColors == 4)  // contains an alpha channel 
     { 
       if (surface->format->Rmask == 0x000000ff) 
         texture_format = GL_RGBA; 
       else 
         texture_format = GL_BGRA; 
     } else if (nOfColors == 3){ // no alpha channel 

      if (surface->format->Rmask == 0x000000ff) 
        texture_format = GL_RGB; 
      else 
        texture_format = GL_BGR; 
     }else { 
      cerr<<"bad surface"<<endl; 
      exit(1); 
      } 

    // Have OpenGL generate a texture object handle for us 
    glGenTextures(1, &texture); 

    // Bind the texture object 
    glBindTexture(GL_TEXTURE_2D, texture); 

    // Set the texture's stretching properties 
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 

    // Edit the texture object's image data using the information SDL_Surface gives us 
    glTexImage2D(GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0, 
        texture_format, GL_UNSIGNED_BYTE, surface->pixels); 
} 
else { 
    printf("SDL could not load image.bmp: %s\n", SDL_GetError()); 
    SDL_Quit(); 
    exit(1); 
}  
ogl_check_error("after surface load"); 
width = surface->w; 
height = surface -> h; 


} 

답변

0

다음 세대를 위해서 - 나는 rect의 잘못된 깊이를 설정했습니다. 24 대신 32가되어야합니다 ....

0

sdl_gl_attributes를 설정 하시겠습니까?

과 같은 SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, 8); SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute (SDL_GL_BUFFER_SIZE, 8);

관련 문제