2012-10-21 3 views
1

왜 SDL 앱이 DOUBLE_BUF를 설정하지 않는지 이해하지 못합니다.HW_SURFACE에서 SDL 더블 버퍼링

여기에 짧은 코드가 있습니다. 이것은 인수없이 실행되며 32 BPP 모드에서 전체 화면 창 1024 * 768을 엽니 다.

#include <stdio.h> 
#include <stdlib.h> 
#include <SDL/SDL.h> 

#include "main.h" 

SDL_Surface *screen; 
Main mainstruct; 

void testModesInFormat(SDL_PixelFormat * format) 
{ 

    SDL_Rect **modes; 
    int i; 

    printf("Available hardware accelerated, fullscreen modes in %d bpp:\n", 
      format->BitsPerPixel); 

    modes = SDL_ListModes(format, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_DOUBLEBUF); 

    // Check is there are any modes available 
    if(modes == (SDL_Rect **) 0) 
    { 
     printf("\tNo modes available!\n"); 
     return; 
    } 

    // Check if our resolution is restricted 
    if(modes == (SDL_Rect **) - 1) 
    { 
     printf("\tAll resolutions available.\n"); 
    } 
    else 
    { 
     // Print valid modes 
     for(i = 0; modes[i]; ++i) 
      printf("\t%d x %d\n", modes[i]->w, modes[i]->h); 
    } 

    free(modes); 

} 

void testModes() 
{ 
    SDL_PixelFormat format; 
    format.BitsPerPixel = 16; 
    testModesInFormat(&format); 
    format.BitsPerPixel = 24; 
    testModesInFormat(&format); 
    format.BitsPerPixel = 32; 
    testModesInFormat(&format); 
} 

int main(int argc, char *argv[]) 
{ 

    printf("Hello world!\n"); 
    Uint32 flags = SDL_DOUBLEBUF; 
    int w, h, bpp; 
    int i; 
    int hw_mem = 1; 
    w = 1024; 
    h = 768; 
    bpp = 32; 

    mainstruct.full_screen = 1; 

    if(SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO) < 0) 
    { 
     fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); 
     exit(1); 
    } 
    atexit(SDL_Quit); 

    for(i = 0; i < argc; i++) 
    { 
     if(!strcmp(argv[i], "--window")) 
     { 
      mainstruct.full_screen = 0; 
     } 
     else if(!strcmp(argv[i], "--no-hardwarememory") || !strcmp(argv[i], "-nohw")) 
     { 
      hw_mem = 0; 
     } 
     else if(!strcmp(argv[i], "--test") || !strcmp(argv[i], "-t")) 
     { 
      testModes(); 
      exit(0); 
     } 
    } 

    if(hw_mem) 
    { 
     flags |= SDL_HWSURFACE; 
    } 
    else 
    { 
     flags |= SDL_SWSURFACE; 
    } 
    if(mainstruct.full_screen) 
    { 
     flags |= SDL_FULLSCREEN; 
    } 
    fprintf(stderr, "Attempting to set %dx%dx%d video mode.\n", w, h, bpp); 
    fflush(stderr); 
    screen = SDL_SetVideoMode(w, h, bpp, flags); 
    if(screen == NULL) 
    { 
     fprintf(stderr, "Unable to set %dx%dx%d video: %s\n", w, h, bpp, 
       SDL_GetError()); 
     exit(1); 
    } 
    fprintf(stderr, "Success:\n"); 
    fprintf(stderr, "\tSDL_HWSURFACE =%s\n", 
      (screen->flags & SDL_HWSURFACE ? "true" : "false")); 
    fprintf(stderr, "\tSDL_FULLSCREEN=%s\n", 
      (screen->flags & SDL_FULLSCREEN ? "true" : "false")); 
    fprintf(stderr, "\tSDL_DOUBLEBUF =%s\n", 
      (screen->flags & SDL_DOUBLEBUF ? "true" : "false")); 
    fprintf(stderr, "\tw=%d h=%d bpp=%d pitch=%d\n", screen->w, screen->h, 
      screen->format->BitsPerPixel, screen->pitch); 
    fflush(stderr); 
    return 0; 
} 

아시다시피 args는 다음과 같습니다. 그래서 여기

내 출력() 함수 testModes를 호출 --test SDL_HWSURFACE 대신에 전체 화면 --no-hardwarememory 설정 SDL_SWSURFACE을 해제 --window;

인수가 없으면 (플래그는 "SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_FULLSCREEN"입니다) 나는 이것을 알게되었습니다. --test 인수와

Attempting to set 1024x768x32 video mode. 
Success: 
    SDL_HWSURFACE =false 
    SDL_FULLSCREEN=true 
    SDL_DOUBLEBUF =false 
    w=1024 h=768 bpp=32 pitch=4096 

, 난이 얻을 :이 컴파일 할 양태에서는 들어

Available hardware accelerated, fullscreen modes in 16 bpp: 
    1920 x 1080 
    1768 x 992 
    1680 x 1050 
    [...] 
    640 x 480 
Available hardware accelerated, fullscreen modes in 24 bpp: 
    No modes available! 
Available hardware accelerated, fullscreen modes in 32 bpp: 
    1920 x 1080 
    1768 x 992 
    1680 x 1050 
    [...] 
    640 x 480 

, 여기에 main.h가

#ifndef MAIN_H 
#define MAIN_H 
#include "SDL.h" 
#include "SDL_thread.h" 

typedef struct _main { 
    int full_screen; 
} Main; 
extern Main mainstruct; 

#endif 

그래서 내가 원하는 DOUBLE_BUF가 32bpp 전체 화면에서 작동하지 않는 이유를 이해하십시오. 몇 가지 아이디어가 있습니까?

SDL 1.2.10 Release Notes 
... 
Windows Notes 
    The "windib" video driver is the default now, to prevent problems with 
    certain laptops, 64-bit Windows, and Windows Vista. The DirectX driver is 
    still available, and can be selected by setting the environment variable 
    SDL_VIDEODRIVER to "directx". 
... 

http://www.libsdl.org/release/changes.html

코드에 programm에 인쇄를 SDL_putenv("SDL_VIDEODRIVER=directx");을 추가 한 후 :

+0

잘 노출 문제는! – makapuf

답변

5

Windows를 사용하는 경우, 문제는 아마입니다

Attempting to set 1024x768x32 video mode. 
Success: 
    SDL_HWSURFACE =true 
    SDL_FULLSCREEN=true 
    SDL_DOUBLEBUF =true 
    w=1024 h=768 bpp=32 pitch=4096 
+0

예! 감사합니다. 왜 내가 HOWSURFACE : D를 얻을 수 없는지 검색하면서 정확하게 동일한 솔루션으로 실행되었습니다. –