我想要在屏幕上显示.bmp
图像,该图像与我的.cpp
文件位于同一文件夹中。
我可以成功构建程序,但是当我运行该程序时,它会显示一个透明窗口并立即关闭,而我所拥有的只是分段错误(核心转储)进程在控制台中返回139
我检查了一下,没有表面,纹理,渲染器等于NULL
。
调试告诉了我
SDL_HasColorKey_REAL中的0x00007ffff788b00b(surface = surface @ entry = 0x555555cbdf70)
SDL_CreateTextureFromSurface_REAL中的0x00007ffff78156a3
main()中的0x0000555555554d6c
但是,我不知道那里发生了什么
#include <stdio.h>
#include<SDL2/SDL.h>
#include<SDL2/SDL_main.h>
#include<iostream>
using namespace::std;
int screen_w =640;
int screen_h =480;
bool quit=false;
SDL_Event event;
SDL_Window*window;
SDL_Renderer*render;
SDL_Surface*sur;
SDL_Texture*textura;
int main()
{
SDL_Init(SDL_INIT_VIDEO);
window=SDL_CreateWindow("aaaa",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,screen_w,screen_h,SDL_WINDOW_SHOWN);
render=SDL_CreateRenderer(window,-1,0);
sur=SDL_LoadBMP("obrazek.bmp");
textura=SDL_CreateTextureFromSurface(render,sur);
while (!quit)
{
SDL_RenderCopy(render, textura, NULL, NULL);
SDL_RenderPresent(render);
SDL_PollEvent(&event);
switch (event.type)
{
case SDL_QUIT:
quit = true;
break;
}
SDL_RenderCopy(render, textura, NULL, NULL);
SDL_RenderPresent(render);
}
SDL_DestroyTexture(textura);
SDL_FreeSurface(sur);
SDL_DestroyRenderer(render);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}