Here is my (abbreviated) code (it’s Ada, sorry! The calls are all the same though):
with SDL; use SDL;
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
with System; use System;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
procedure Main is
Background_Surface : access SDL_Surface;
No_Ui : Boolean := false;
Window : access SDL_Window;
Surface : access SDL_Surface;
procedure Init is
begin
if SDL_Init(SDL_INIT_VIDEO) < 0 then
No_Ui := true;
Put_Line("Init failed!");
Put_Line(Value(SDL_GetError));
return;
end if;
end Init;
procedure Get_Background is
begin
Background_Surface := SDL_LoadBMP(To_C("background.bmp"));
if Background_Surface = null then
Put_Line("SDL_LoadBMP failed!");
Put_Line(Value(SDL_GetError));
No_Ui := true;
return;
end if;
end Get_Background;
procedure Show_Window is
begin
Put_Line("Showing Window!");
--Window := SDL_CreateWindow(To_C("SDL Tutorial"), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Background_Surface.w, Background_Surface.h, SDL_WINDOW_SHOWN + SDL_WINDOW_FULLSCREEN);
Window := SDL_CreateWindow(To_C("SDL Tutorial"), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Background_Surface.w, Background_Surface.h, SDL_WINDOW_SHOWN);
if Window = null then
No_Ui := true;
Put_Line(Value(SDL_GetError));
SDL_Quit;
return;
end if;
SDL_SetWindowBordered(Window, SDL_TRUE);
Surface := SDL_GetWindowSurface(Window);
if Surface = null then
No_Ui := true;
Put_Line(Value(SDL_GetError));
return;
end if;
end Show_Window;
procedure Draw is
Temp : Interfaces.C.Int;
begin
Temp := SDL_BlitSurface(Background_Surface, NULL, Surface, NULL );
Temp := SDL_UpdateWindowSurface(Window);
end Draw;
procedure Clean_Up is
begin
if Background_Surface /= null then
SDL_FreeSurface(Background_Surface);
Background_Surface := null;
end if;
if Surface /= null then
SDL_FreeSurface(Surface);
Surface := null;
end if;
if Window /= null then
SDL_DestroyWindow(Window);
Window := null;
end if;
SDL_Quit;
end Clean_Up;
begin
Init;
Get_Background;
Show_Window;
Draw;
declare
E : aliased SDL_Event;
Quit : Boolean;
begin
while not Quit loop
while Integer(SDL_PollEvent(E'Access)) /= 0 loop
if E.typ = SDL_SHUTDOWN then
Quit := true;
end if;
if E.typ = SDL_KEYDOWN then
Quit := true;
end if;
end loop;
delay 0.1;
end loop;
end;
Clean_Up;
end Main;
If I run it with the SDL_VIDEO_FULLSCREEN flag, it works (although for some reason the image only fills a quarter of the screen… It’s just the Lazy Foo image saved as a bmp), but if I try to run it without, SDL refuses to show anything. Not sure what I could be forgetting; this should be a pretty simple exercise.
To clarify, the Put_Line commands are basic console output commands (like printf or cout), and the only output I’m receiving is “Showing Window!”, so it doesn’t look like any of these calls are failing; just for some reason, no window appears.
Any help is appreciated.