View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Beginner's Problem with SDL in C++

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1nyl2000  Members

Posted 08 May 2012 - 05:45 AM

I have just gotten started with trying to use SDL/OpenGL for C++. I have followed several tutorials, and have gotten the example programs to compile without error.

However, when I try to run the program, a blank window shows up (instead of the intended image of the tutorial). If I remove the SDL_Delay, the blank window also appears to be unresponsive. Also,

any cin and cout I/O that I add don't seem to show up on the window (cout writes on a txt file and cin does not﻿ wait for keyboard input before moving on in the program)[/background]

I am using a windows 7 64 bit machine, and have attempted the tutorial on both Codeblocks and Visual Studio 2010 with the same problematic result.

I have already tried adjusting for the 32-bit compatibility problem by using WOW64, it seems to have no effect.

This is the tutorial.
http://lazyfoo.net/S...son01/index.php

The full tutorial source code is also attached.

I hope someone can at least tell me what the problem is exactly.

#### Attached Files

Edited by nyl2000, 08 May 2012 - 09:21 AM.

### #2endless11111  Members

Posted 08 May 2012 - 10:14 AM

the image might not be loading up because you don't have the image file in the same folder as the project file. if you are compiling a program, all the files accosiated with the program must be in the same folder as the .cpp files, and if you are running the .exe file, all the files accosiated with the program must be in the same folder as the .exe file. and i am not really familiar with text intput and output in sdl using cin and cout, but as far as i know, you can't use cin or cout like you would with a console application, you can't just output text or input text directly using cin and cout.

### #3Ectara  Members

Posted 08 May 2012 - 10:47 AM

SDL cannot simply print text and get text to the screen; it moves pixels, and watches for events, and such. If you want terminal functionality, you must write that yourself.

As far as stdin and stdout, I'm pretty sure those are redirected to an output text file and something non-keyboard for input when used in a Windows application (as opposed to a console application or most other WM's).

### #4DarkHorseKnight  Members

Posted 08 May 2012 - 11:48 AM

Basically you needed a while loop so the program is continous for ever until done is equal to true:

#undef main
#include <SDL/SDL.h>
int main( int argc, char **argv[] )
{
bool done = false;

SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;

SDL_Init( SDL_INIT_EVERYTHING );

screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );

SDL_Event event;

while(!done)
{

SDL_BlitSurface( hello, NULL, screen, NULL );

while(SDL_PollEvent(&event))
{
switch(event.type)
{

case SDL_QUIT:
return 0;
break;

}

}

SDL_Flip( screen );

}
return 0;
}


Hopefully this works

http://pastebin.com/bJSx40g5

EDIT:

Edited by DarkHorseKnight, 08 May 2012 - 12:16 PM.

### #5nyl2000  Members

Posted 08 May 2012 - 08:20 PM

Thank you, DarkHorseKnight,

May I ask what #undef main is exactly?

Edited by nyl2000, 08 May 2012 - 08:20 PM.

### #6fastcall22  Moderators

Posted 08 May 2012 - 08:29 PM

The SDL_main library part of SDL tries to be clever in renaming your "main" function to "SDL_main", in this way the library provides its own "main" function with some additional features before calling your "main" function. SDL_main provides platform independent non-console window setup: You get the same no-console program in all platforms, along with some additional "features", such as redirecting stdin and stdout to files.

By #undefining main, you forbid SDL from using its own main function, and the linker chooses your main function over SDL_main's main as your program's entry point.

Edited by fastcall22, 08 May 2012 - 08:31 PM.

zlib: eJzVVLsSAiEQ6/1qCwoK i7PxA/2S2zMOZljYB1TO ZG7OhUtiduH9egZQCJH9 KcJyo4Wq9t0/RXkKmjx+ cgU4FIMWHhKCU+o/Nx2R LEPgQWLtnfcErbiEl0u4 0UrMghhZewgYcptoEF42 YMj+Z1kg+bVvqxhyo17h nUf+h4b2W4bR4XO01TJ7 qFNzA7jjbxyL71Avh6Tv odnFk4hnxxAf4w6496Kd OgH7/RxC

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.