The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Problem using Textures (Hardware Rendering Library)
104809


Joined: 08 May 2015
Posts: 7
Hey I`ve been coding a little bit and tried to make a simple program, that just shows a window and renders a picture into it with the Hardware Rendering library(so SDL_Textures, SDL_Renderers and so on) because I`ve only done it with Surfaces till now. The Problem is: It just doesn`t work at all, It worked fine for the surfaces, but it seems like I can`t deal with the Textures and stuff.
I am looking Forward if anyone can help me out.

This is the Code:

Code:
#include <SDL.h>
#include <SDL_image.h>
#include "Sprite.h"

int main(int argc, char* argv[])
{
   SDL_Texture *Texture = nullptr;
   SDL_Renderer *Renderer = nullptr;
   SDL_Window *Window = nullptr;

   int imgFlags = IMG_INIT_PNG;

   SDL_CreateWindowAndRenderer(200, 200, SDL_WINDOW_SHOWN, &Window, &Renderer);
   Texture = IMG_LoadTexture(Renderer, "test.png");
   bool bRunning = true;
   SDL_Event *ev = nullptr;


   while (bRunning == true)
   {
      while (SDL_PollEvent(ev))
      {

      }
      SDL_RenderClear(Renderer);
      SDL_RenderCopy(Renderer, Texture, NULL, NULL);
      SDL_RenderPresent(Renderer);
   }



   return 0;
}


For Explanation: In the Loop i just took a random bool that always stays true, so that it never Ends and then made an Event Loop, that should check for Events,
For the rest I just tried to make a window and render a .png inside of it, as I already said.


Greetings
104809


Joined: 08 May 2015
Posts: 7
Edit: I added
Code:
   if (ev.type == SDL_QUIT)
         {
            SDL_Quit();
            exit(1);
         }

in the Event Loop, to make the WIndow closeable by the "X" Button.

When I call the ErrorFunction IMG_GetError() after the Loading of the Picture it tells me:

Failed loading libpng16-16.dll: The named Module has not been found

So assume something went wrong at Loading the Texture. But I got no Idea what.

I hope someone can figure it out for me!

Thanks in advantage