【问题标题】:C++ SDL, SDL_image issuesC++ SDL、SDL_image 问题
【发布时间】:2013-11-18 02:32:50
【问题描述】:

IDE:代码::块 编译器:MinGW

我正确安装了 SDL 和 SDL_image(它在构建时不会出现任何错误)。 一切都编译得很好,但是当我运行它时,会出现 SDL 窗口,但图像从不闪烁,窗口。我使用 SDL_image,所以我可以加载 PNG 图像(或者我希望如此)。

代码:

#include <cstdlib>
#include <iostream>
#include "SDL_image.h"
#include <SDL/SDL.h>

int main ( int argc, char** argv )
{
    SDL_Surface* test = NULL;
    SDL_Surface* screen = NULL;
    //Start SDL
    SDL_Init( SDL_INIT_EVERYTHING );

    //Name the window
    SDL_WM_SetCaption( "Test-1", NULL );
    //Set up screen
    screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );

    //Load image
    test = IMG_Load("Test.png");
    //Apply image to screen
    SDL_BlitSurface( test, NULL, screen, NULL );
    //Update Screen
    SDL_Flip( screen );

    //Pause
    SDL_Delay( 2000 );
    //Free the loaded image
    SDL_FreeSurface( test );

    //Quit SDL
    SDL_Quit();

    return 0;
}

【问题讨论】:

  • 添加一些错误检查,看看IMG_Load调用是否成功。
  • 如果不是,请致电SDL_GetError 找出问题所在。

标签: c++ mingw sdl codeblocks sdl-image


【解决方案1】:

也许您可以尝试创建一个窗口,然后创建一个表面,然后通过表面将图像粘贴到窗口上?然后你可以试试这个功能: SDL_UpdateWindowSurface(*windowinstance*)

更多信息在这里:link(虽然这是加载 *.bmp 文件,但我确信概念是相同的)。也试试上面提到的答案。可能只是图片找不到...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多