Sign in to follow this  

Help with simple SDL program

This topic is 3318 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Im new to SDL and I was following this tutorial: http://pgdc.purdue.org/sdltutorial/sdl_setup.html And I tried to run their sample code. It compiled and ran OK (no errors), except that the "Hello SDL User!" it's not showing up. ¿Any clue?. Im using VS 2008, C++. Thanks in advance. Heres the code:
/* -- Include the precompiled libraries -- */
#ifdef WIN32
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#endif

#include "SDL.h"

int main(int argc, char **argv)
{
	printf("\nHello SDL User!\n");

	/* initialize SDL */
	if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
	{
		fprintf( stderr, "Video initialization failed: %s\n",
			SDL_GetError( ) );
		SDL_Quit( );
	}
	
	SDL_Quit( );

	return 0;
}

Share this post


Link to post
Share on other sites
As 39ster said, printf() doesn't draw text. printf() just writes text to a object called a 'stream', and that stream can be rerouted to different places.
In the Win32 Console you used to use (the black box with white text) printf() was rerouted to show the text on the console.
In SDL, print() is rerouted to a .txt file called 'stdout' that is created and placed in the same folder as your program.

To actually draw text in a actual graphical program, it takes a bit more work, and if you are new to SDL, I won't toss that information at you until you think you are ready for. Instead, it's so much easier (in SDL, anyway) to get a simple image to draw. Normally the first thing you do when learning SDL is drawing a picture that has the text 'Hello world' written on it manually in MSPaint (the paint program that comes with Windows)

I strongly suggest you to learn SDL through this tutorial, as it is very easy to understand compared to other tutorials, and helped me learn SDL easier. If you don't understand anything on that site, just ask, someone here will be glad to answer.

Share this post


Link to post
Share on other sites

This topic is 3318 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this