SDL Image / PNG or JPG cannot be displayed

1.4k views Asked by At

I am trying to display an png or jpg file with SDL 2.0.1, SDL Image 2.0.0 and c++, but it does not work. (I am new to SDL) I wrote a program that does the following things:

  • Drawing background (is working)
  • Creating random pixels / displaying them (is working often (still got problem with random values))
  • Display the png /jpg file (none of them is working)

I'm using visual studio 2012 express / visual studio 2013 professional. due to the fact that i am developing on windows OS I can see the image (by hovering the application in the task bar) is being loaded in the buffer (or what ever) but it is not being displayed in the real application. the rest could be rendered, except the image. All functions are returning the right values. clean up and rebuild doesn't work either.

The project links the following libraries:

  • SDL2.lib
  • SDL2main.lib
  • SDL2_image.lib

The include folders are the x86 folders. DLL files from x86 folders are placed in my project folder.

It's not much code really, so I inserted a link to the project files, so that it can be downloaded and I would be very thankful for any help. I'm kind of desperate, cause I'm trying to handle that bug for a few days now.

I also tried coding on 2 different computers. same problem on both of them.

Download the project: here

(You may have to restart application, because of the random pixel problem)

Is there anyone who could tell me what I am doing wrong?

1

There are 1 answers

1
cup On

This is what I did to debug it.

1) In CBuild::Init, it gets stuck at CreateWindow: no idea what is happening but the CPU is at 99%! Change SDL_WINDOW_BORDERLESS | SDL_WINDOW_FULLSCREEN to SDL_WINDOW_SHOWN so we can continue.

2) Hit the random pixel problem. Just comment out and restart.

3) Everything is OK until createIMG at SDL_ConvertSurface: crashes because format is 0. Go backwards and see where this gets clobbered. It is in SDL_CreateRenderer. Shouldn't this be before SDL_GetWindowSurface? Try it and yes it works. So the fix in cbuild_init is.

pWindow = SDL_CreateWindow(
  "kartoffel", 
  SDL_WINDOWPOS_CENTERED,
  SDL_WINDOWPOS_CENTERED,
  displaymode.w,
  displaymode.h,
  SDL_WINDOW_SHOWN);

// create renderer
pRenderer = SDL_CreateRenderer(pWindow, -1, SDL_RENDERER_ACCELERATED);

pSurfWnd = SDL_GetWindowSurface(pWindow);

SDL_FillRect ...
// ignore random pixels
pIMG_logo->createIMG ...

Unfortunately, I'm new to SDL too, so I can't really tell you why it is wrong and this sequence works. Perhaps someone else reading this can tell you that.