SDL无法正确下载libpng16-16dll?

我在vs里使用sdl的第三方库SDL_image的时候,库及lib文件引用正常,待显示的图片资源也放置在了合适的位置,在执行exe文件的时候报错

LoadTexture error: Failed loading libpng16-16.dll: 鎵句笉鍒版寚瀹氱殑妯″潡銆

图片描述

可是它所依赖的dll文件确实已经正确放在和.cpp同级的目录下了呀。。

顺便付一下我的代码

#include <string>

#include <iostream>

#include <SDL.h>

#include <SDL_image.h>

//Screen attributes

const int SCREEN_WIDTH = 640;

const int SCREEN_HEIGHT = 480;

void logSDLError(std::ostream &os, const std::string &msg){

os << msg << " error: " << SDL_GetError() << std::endl;

}

SDL_Texture* loadTexture(const std::string &file, SDL_Renderer *ren){

SDL_Texture *texture = IMG_LoadTexture(ren, file.c_str());

if (texture == nullptr){

logSDLError(std::cout, "LoadTexture");

}

return texture;

}

void renderTexture(SDL_Texture *tex, SDL_Renderer *ren, int x, int y, int w, int h){

//Setup the destination rectangle to be at the position we want

SDL_Rect dst;

dst.x = x;

dst.y = y;

dst.w = w;

dst.h = h;

SDL_RenderCopy(ren, tex, NULL, &dst);

}

void renderTexture(SDL_Texture *tex, SDL_Renderer *ren, int x, int y){

int w, h;

SDL_QueryTexture(tex, NULL, NULL, &w, &h);

renderTexture(tex, ren, x, y, w, h);

}

int main(int, char**){

//Start up SDL and make sure it went ok

if (SDL_Init(SDL_INIT_VIDEO) != 0){

logSDLError(std::cout, "SDL_Init");

return 1;

}

SDL_Window *window = SDL_CreateWindow("Lesson 4", SDL_WINDOWPOS_CENTERED,

SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);

if (window == nullptr){

logSDLError(std::cout, "CreateWindow");

SDL_Quit();

return 1;

}

SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

if (renderer == nullptr){

logSDLError(std::cout, "CreateRenderer");

//cleanup(window);

SDL_Quit();

return 1;

}

SDL_Texture *bg = loadTexture("buttonBg.bmp", renderer);

SDL_Texture *boggle = loadTexture("loggle.bmp", renderer);

SDL_Texture *bulbOff = loadTexture("background.png", renderer);

SDL_Texture *bulbOn = loadTexture("bulb_off.bmp", renderer);

if (bg == nullptr){

// cleanup(image, renderer, window);

IMG_Quit();

SDL_Quit();

return 1;

}

int iW, iH;

int bW, bH;

int moveDis;

SDL_QueryTexture(bg, NULL, NULL, &iW, &iH);

SDL_QueryTexture(bulbOff, NULL, NULL, &bW, &bH);

int x = SCREEN_WIDTH / 2 - iW / 2;

int y = SCREEN_HEIGHT / 2 + iH;

int bX = SCREEN_WIDTH / 2 - bW / 2;

int bY = SCREEN_HEIGHT / 2 - 220;

moveDis = iW;

/*

每次显示图画的时候必须清理一次render渲染器

然后调用renderTexture

最后用renderPresent显示图画

*/

//Rendering

SDL_RenderClear(renderer);

//Draw the image

renderTexture(bg, renderer, x, y);

renderTexture(boggle, renderer, x + 30, y + 10);

renderTexture(bulbOff, renderer, bX, bY);

//Update the screen

SDL_RenderPresent(renderer);

//Our event structure

int flag = 0; //控制灯泡亮灭

int flagDown = false;

SDL_Event e_down;

SDL_Event e_move;

//For tracking if we want to quit

bool quit = false;

int xButton = x;

int yButton = y;

while (!quit){

//Read any events that occured, for now we'll just quit if any event occurs

while (SDL_PollEvent(&e_down)){

if (e_down.type == SDL_MOUSEBUTTONDOWN)

//当事件为触屏

{

std::cout << "down";

flagDown = true;

}

}

while (SDL_PollEvent(&e_move)){

if (e_down.type == SDL_MOUSEMOTION && flagDown)

//当事件为触屏

{

std::cout << "OK";

}

}

}

//Destroy the various items

//cleanup(image, renderer, window);

IMG_Quit();

SDL_Quit();

return 0;

}

请问到底是哪里有问题,求指导??

以上是 SDL无法正确下载libpng16-16dll? 的全部内容, 来源链接: utcz.com/p/195002.html

回到顶部