我试图运行此代码,但它一直给我一个错误。 我在调试文件夹中复制了SDL2_image.lib但是徒劳无功。 我正在开始编程,所以请耐心等待。
错误:
错误1错误C3861:' IMG_LoadTexture':未找到标识符
错误2 IntelliSense:标识符" IMG_LoadTexture"未定义
#include<SDL/SDL.h>
#include<iostream>
using namespace std;
int main(int argc, char** argv)
{
bool quit = false;
//*Initializing Window;
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window = NULL;
window = SDL_CreateWindow("Game Test", 100, 100, 640, 480, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
//*If game Crushes;
if (window == NULL)
{
cout << "The game window is not working";
}
//*Creating Update Function
SDL_Renderer* render = NULL;
render = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
SDL_Event* mainEvent = new SDL_Event();
//*End Update Function
//*Adding Textures;
SDL_Texture* grass_image = NULL;
grass_image = IMG_LoadTexture(render, "grass.bmp");
//*Creating a Sprite;
SDL_Rect grass_rect;
grass_rect.x = 10;
grass_rect.y = 50;
grass_rect.w = 250;
grass_rect.h = 250;
//*Content Of the Window;
while (!quit && mainEvent->type!=SDL_QUIT)
{
SDL_PollEvent(mainEvent);
SDL_RenderClear(render);
SDL_RenderCopy(render, grass_image, NULL, &grass_rect);
SDL_RenderPresent(render);
}
//*End Window Content
//*Memory Cleaning
SDL_DestroyWindow(window);
SDL_DestroyRenderer(render);
delete mainEvent;
//*End Memory Cleaning
return 0;
}
答案 0 :(得分:0)
您缺少包含包含IMG_LoadTexture()
声明的标头:
#include <SDL/SDL_image.h>
它是SDL的独立扩展库,除了包含该标题之外,您还需要将该库与项目链接。