Why is this SDL program not loading my image?

55 views Asked by At

I was recently trying to understand how to load an image in SDL. However, when I followed a guide on how to do this, the code wasn't working for some reason. Instead, I get an unresolved external symbol error:

unresolved external symbol IMG_LoadPNG_RW referenced in function "void __cdecl windowcr(void)" (?windowcr@@YAXXZ)

Code:

windowcreate.h

#pragma once

#ifndef WINDOWCREATE_H

#define WINDOWCREATE_H

#include <iostream>
#include "SDL.h"
#include "SDL_image.h"
#include <cstdio>
#include <Windows.h>

using namespace std;

void windowcr() {

    SDL_Init(SDL_INIT_EVERYTHING);

    SDL_Window* window = SDL_CreateWindow("SDLwindow", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN);

    SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0);

    SDL_SetRenderDrawColor(renderer, 46, 139, 87, 255);

    SDL_RenderClear(renderer);

    SDL_RenderPresent(renderer);

    SDL_Surface* image = IMG_LoadPNG_RW(SDL_RWFromFile("worldmap.png", "rb"));
    SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, image);

    SDL_RenderCopy(renderer, texture, NULL, NULL);
    SDL_RenderPresent(renderer);

    SDL_Event event;
    bool running = true;

    while (running) {
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT) {
                running = false;
            }
        }

        if (GetAsyncKeyState(0x0D) & 0x8000) {
            SDL_DestroyRenderer(renderer);
            SDL_DestroyWindow(window);
            SDL_Quit();
            break;
        }
    }

}

#endif

main.cpp

#include <iostream>
#include "SDL.h"
#include "SDL_image.h"
#include <cstdio>
#include <Windows.h>
#include "windowcreate.h"

using namespace std;

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

    windowcr();

    return 0;

}

I have tried to look up ways to fix this, I moved the image to the same directory as the project itself, but that didn't seem to work either.

0

There are 0 answers