[try Beta version]
Not logged in

 
Help with basic GUIs

Jan 7, 2015 at 1:08am
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;
}
Jan 7, 2015 at 1:57am
is a window coming up at all?
Jan 7, 2015 at 2:00am
Yes, it just immediately closes
Jan 7, 2015 at 2:09am
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 Jan 7, 2015 at 2:09am
Jan 7, 2015 at 2:10am
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.
Jan 7, 2015 at 2:11am
And no, a square does not appear.
Jan 7, 2015 at 2:21am
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 Jan 7, 2015 at 2:22am
Jan 7, 2015 at 2:26am
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.
Jan 7, 2015 at 2:36am
@hambone
I used that exact tutorial
Jan 7, 2015 at 2:37am
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
Jan 7, 2015 at 3:46am
UPDATE:
oh my god I'm retarded. I was hitting compile, not compiler & run. sorry to bother you
Last edited on Jan 7, 2015 at 3:52am
Jan 7, 2015 at 3:47am
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.