Help with basic GUIs

I'm learning how to use SDL to, for right now, just print a square. It compiles, but the problem is, the console immediately closes down. I've tried using cin.ignore(), and the tutorial says to use SDL_Delay(2000). Here's the code, can you tell me what's wrong with it?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "SDL/SDL.h"
using namespace std;
int main()
{
SDL_Init( SDL_INIT_EVERYTHING );
SDL_Surface* hello = nullptr;
SDL_Surface* screen = nullptr;
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
hello = SDL_LoadBMP ( "hello.bmp" );
SDL_BlitSurface( hello, nullptr, screen, nullptr);
SDL_Flip (screen);
SDL_Delay(2000);
SDL_FreeSurface( hello );
SDL_Quit();
return 0;
}
is a window coming up at all?
Yes, it just immediately closes
you may want to do some error checking as it looks like you may not be doing any, maybe the bmp is not being loaded or something like that? Can you see the square on the screen when the window comes up?
Last edited on
Wait, let me rephrase. A window doesn't pop up, but it compiles errorless and then creates a .exe file that I can open but immediately closes.
And no, a square does not appear.
ah, it looks like you might be having other issues, maybe try some error checking? If I may, work through this first tutorial set starting from setup to getting something on the screen -> http://lazyfoo.net/tutorials/SDL/01_hello_SDL/index.php . You just may be missing something or it cant find a file.
Last edited on
You didnt loop for it to stay on the screen, so it would close immediately.
For more: http://lazyfoo.net/tutorials/SDL/02_getting_an_image_on_the_screen/index.php

Hope it helps.
@hambone
I used that exact tutorial
loopdydoo is using sdl_delay, so for now, loopdydoo should not need to use a loop for the image to stay drawn to the viewport. loopdydoo should be able to see the image for 2000 miliseconds or, 2 seconds.

hambone
UPDATE:
oh my god I'm retarded. I was hitting compile, not compiler & run. sorry to bother you
Last edited on
maybe try seeing it to like 5000 miliseconds instead of 2000. should not matter though, 2 seconds should be long enough to see.


Hambone
Topic archived. No new replies allowed.