2013-02-05 2 views
0

제가 작업하고있는 게임의 경우, 많은 그래픽에서 OpenGL을 사용하고 텍스트에 SDL_TTF을 사용하고 싶습니다. 둘 다 일할 수는 있지만 동시에 할 수는 없습니다. 이 두 SDL_TTF와 OpenGL을 사용합니다 true로 설정되어있는 경우 변수 useOpenGl이 프로그램은 SDL_TTF 사용 false로 설정되어있는 경우SDL_TTF와 OPENGL이 함께 작동하는 데 문제가 있습니다.

#include "SDL/SDL.h" 
#include "SDL/SDL_ttf.h" 
#include "GL/gl.h" 

const bool useOpenGl = true; 

//The surfaces 
SDL_Surface *message = NULL; 
SDL_Surface *screen = NULL; 

//The event structure 
SDL_Event event; 

//The font that's going to be used 
TTF_Font *font = NULL; 

//The color of the font 
SDL_Color textColor = {255, 255, 255}; 

void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL) 
{ 
    //Holds offsets 
    SDL_Rect offset; 

    //Get offsets 
    offset.x = x; 
    offset.y = y; 

    //Blit 
    SDL_BlitSurface(source, clip, destination, &offset); 
} 

bool init() 
{ 
    SDL_Init (SDL_INIT_EVERYTHING); 
    if (useOpenGl) 
    { 
     screen = SDL_SetVideoMode (1280, 720, 32, SDL_SWSURFACE | SDL_OPENGL); //With SDL_OPENGL flag only opengl is sceen, without only text is 
    } else { 
     screen = SDL_SetVideoMode (1280, 720, 32, SDL_SWSURFACE); 
    } 

    TTF_Init(); 

    SDL_WM_SetCaption ("TTF Not Working With OpenGL", NULL); 

    if (useOpenGl) 
    { 
     glClearColor(1.0, 0.0, 0.0, 0.0); 
     glMatrixMode(GL_PROJECTION); 
     glLoadIdentity(); 
     glOrtho(0.0, screen->w, screen->h, 1.0, -1.0, 1.0); 
     glEnable(GL_BLEND); 
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
    } 

    return true; 
} 

bool load_files() 
{ 
    font = TTF_OpenFont ("arial.ttf", 28); 

    return true; 
} 

void clean_up() 
{ 
    SDL_FreeSurface (message); 

    TTF_CloseFont (font); 
    TTF_Quit(); 

    SDL_Quit(); 
} 

int main(int argc, char* args[]) 
{ 
    //Quit flag 
    bool quit = false; 

    init(); 
    load_files(); 

    if (useOpenGl) 
    { 
     glClear(GL_COLOR_BUFFER_BIT); //clearing the screen 
     glPushMatrix(); 


     glBegin(GL_QUADS); 
     glColor3f(1.0, 0.0, 0.0); 
     glVertex2f(0, 0); 
     glColor3f(0.0, 1.0, 0.0); 
     glVertex2f(1280, 0); 
     glColor3f(0.0, 0.0, 1.0); 
     glVertex2f(1280, 720); 
     glColor4f(0.5, 0.5, 1.0, 0.1); 
     glVertex2f(0, 720); 
     glEnd(); 

     glPopMatrix(); 
     glFlush(); 
    } 

    //Render the text 
    message = TTF_RenderText_Solid (font, "The quick brown fox jumps over the lazy dog", textColor); 

    //Apply the images to the screen 
    apply_surface (0, 150, message, screen); 

    //I'm guessing this is where the problem is coming from 
    SDL_GL_SwapBuffers(); 
    SDL_Flip (screen); 


    while (quit == false) 
    { 
     while (SDL_PollEvent (&event)) 
     { 
      if (event.type == SDL_QUIT) 
      { 
       quit = true; 
      } 
     } 
    } 

    clean_up(); 

    return 0; 
} 

: 여기에 (게으른 푸 기반으로) 내 코드입니다. 윈도우를 만들 때 "SDL_OPENGL"플래그를 사용하는지 여부에 문제가있는 것 같습니다.

답변

0

SDL_TTF는 소프트웨어 렌더링을 사용하며 OpenGL 모드와 호환되지 않습니다.

FTGL 또는 freetype-gl과 같은 다른 라이브러리를 찾아야하는 경우가 있습니다.

관련 문제