2014-03-12 1 views
0

좋아요, 그래서 창을로드하고 함수를 사용하여 두 개의 이미지를 표시하려고합니다. 창은로드되지만 내 오류는 이미지로드 실패로 표시되지 않지만 창은 흰색으로 유지됩니다. 그게 왜 어떤 아이디어일까요? 이것은 아래 코드입니다.SDL 2.0 문제 - 이미지를로드하려고 시도했지만 흰색 상자 만 사용합니다.

#include "stdafx.h" 
#include "SDL.h" 
#include <iostream> 
#include <string> 

using namespace std; 

const int Window_Width = 640; 
const int Window_Height = 480; 

SDL_Window *window = NULL; 
SDL_Renderer *render = NULL; 

SDL_Texture* loadImage(string imagename) //function that loads the image, useful for handling multiple image imports 

{ 

SDL_Surface* loadedImage = NULL; 
SDL_Texture* texture = NULL; 

loadedImage = SDL_LoadBMP(imagename.c_str()); //loads the image with the passed file name 

if (loadedImage == NULL) //checks for any errors loading the image 
{ 
    cout<<"The image failed to load.."<<endl; 
} 

texture = SDL_CreateTextureFromSurface(render, loadedImage); 
SDL_FreeSurface(loadedImage); 

return texture; 
} 


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

    if (SDL_Init(SDL_INIT_EVERYTHING) == -1) 

    {  
    cout << SDL_GetError() << endl; 
    return 1; 
    } 

    window = SDL_CreateWindow("Frogger", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Window_Width, Window_Height, SDL_WINDOW_SHOWN); 
    //creates a window in the centre of the screen, it uses const int's to define the size of the window 

    if (window == NULL) 
    { 
    cout << SDL_GetError()<<endl; 
    return 1; 
    } 

    render = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); 
    //this renders the window 

    if (render == NULL) 
    { 
    cout << SDL_GetError()<<endl; 
    return 1; 
    } 

    //loading the images using the function 
    SDL_Texture* background = NULL; 
    SDL_Texture* frog = NULL; 

    background = loadImage("background.bmp"); 
    frog = loadImage("frogger.bmp"); 

    SDL_Delay(2000); 

    SDL_RenderClear(render); 

    SDL_RenderPresent(render); 

    SDL_UpdateWindowSurface(window); 

    //freeing the memory back up 
    SDL_DestroyRenderer(render); 
    SDL_DestroyWindow(window); 
    SDL_DestroyTexture(background); 
    SDL_DestroyTexture(frog); 

    SDL_Quit(); 

return 0; 

}

답변

0

당신은 아무것도 렌더링되지 않습니다, 당신은 단지 몇 가지 질감을로드하고 프로그램을 종료합니다.

+0

물론. 미안 나는 그것을 보지 않았다! 고마워, 그걸 시도해 볼게. – Peter