• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
cignox1

cout to console in SDL

41 posts in this topic

I find it very hard using the debugger provided with Dev-C++ as I cannot make him stop where I want and check the value of every variable, so I would like to print them on the console of course, not on the actual SDL window, but on the dos prompt). It happens that cout doesn't work: is there a way to get cout working as always? Thank you all!
0

Share this post


Link to post
Share on other sites
try to put these lines in your code

freopen( "CON", "wt", stdout );
freopen( "CON", "wt", stderr );

0

Share this post


Link to post
Share on other sites
If that does not work, make sure you are outputting endl's at the end of the line. I opened up a test project and w/o them, I got no text, but after I added them, it worked fine.

- Drew
0

Share this post


Link to post
Share on other sites
Thank you all for replying:
happybara and Drew_Benton: don't know why, but I tried both the tips and it still doesn't work.. my fault?

Oluseyi: I'm not using the win32 api. The project was initially set up with the SDL template of Dev-C++ wich includes windows.h just in order to use MessageBox(). I would like to keep the code as portable as possible, using only c++ standard libraries... thank you anyway for the link, it may come handy someday.

0

Share this post


Link to post
Share on other sites
Ok then give C-styled output a try.


#include <stdio.h>

printf("This is a test!\n");
int val = 5;
printf("Value of val: %i\n",val);


And as a side note, you are outputting *before* the breakpoint correct?

- Drew
0

Share this post


Link to post
Share on other sites
The above wont work because the stdout is no longer the console it is stdout.txt
I did see a solution to this problem not too long ago here somewhere, unfortunately i cant remember what it was :)
0

Share this post


Link to post
Share on other sites

Quote:

And as a side note, you are outputting *before* the breakpoint correct?


I'm not debugging now, I'm just trying to make it work -sigh-

0

Share this post


Link to post
Share on other sites
Quote:
Original post by sand_man
The above wont work because the stdout is no longer the console it is stdout.txt
I did see a solution to this problem not too long ago here somewhere, unfortunately i cant remember what it was :)

One solution is to recompile SDL.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Easca
Quote:
Original post by sand_man
The above wont work because the stdout is no longer the console it is stdout.txt
I did see a solution to this problem not too long ago here somewhere, unfortunately i cant remember what it was :)

One solution is to recompile SDL.


I just clicked ahead a few posts from that link and this seems a little easier:

Quote:
Actually, all that needs to be done is to recompile with "NO_STDIO_REDIRECT"
defined in src/main/SDL_main.c (you can either modify the file or re-compile
SDL_main.lib by hand with -DNO_STDIO_REDIRECT, your mileage may varry)
0

Share this post


Link to post
Share on other sites
I cannot see why this is not working. Can you please post your code. It makes no sense that none of the suggestions have yet to work. What OS and IDE are you using? What version of SDL as well. My cout and printf work fine in Dev, VS6, and VS7, so there's one detail that is missing somewhere.

- Drew
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Drew_Benton
I cannot see why this is not working. Can you please post your code. It makes no sense that none of the suggestions have yet to work. What OS and IDE are you using? What version of SDL as well. My cout and printf work fine in Dev, VS6, and VS7, so there's one detail that is missing somewhere.

- Drew

I don't get any output on the console. I didn't try the winapi redirects though.
I use dev-cpp 4.9.9.1 and SDL 1.2.4. The freopen works fine if I just put a arbituary filename and stops any output to stdout.txt using freopen( "CON", "wt", stdout ).


#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>


/* The screen surface */
SDL_Surface *screen = NULL;

int main (int argc, char *argv[])
{
int done;
printf( "Hello World1\n");
/* Initialize SDL */
if (SDL_Init (SDL_INIT_VIDEO) < 0)
{
printf ("Couldn't initialize SDL: %s\n", SDL_GetError ());
exit (1);
}
atexit (SDL_Quit);
freopen( "CON", "wt", stdout ); //hello world2 doesn't get outputted
// freopen( "filename", "wt", stdout ); //hello world2 goes to filename
printf( "hello world2\n");

exit( 0 );
}





It is compiled as a console application (Win32 console).
0

Share this post


Link to post
Share on other sites
Well, that's my code (just the basic stuff):

#include <stdio.h>
#include <stdlib.h>
#include "SDL.h"
#include <iostream>

using namespace std;

/* The screen surface */
SDL_Surface *screen = NULL;

int
main (int argc, char *argv[])
{
char *msg;
int done;

freopen( "CON", "wt", stdout );
freopen( "CON", "wt", stderr );
printf("ciccio\n");


/* Initialize SDL */
if (SDL_Init (SDL_INIT_VIDEO) < 0)
{
sprintf (msg, "Couldn't initialize SDL: %s\n", SDL_GetError ());
free (msg);
exit (1);
}
atexit (SDL_Quit);

/* Set 640x480 16-bits video mode */
screen = SDL_SetVideoMode (640, 480, 32, SDL_SWSURFACE | SDL_DOUBLEBUF);
if (screen == NULL)
{
sprintf (msg, "Couldn't set 640x480x16 video mode: %s\n",
SDL_GetError ());
free (msg);
exit (2);
}

SDL_WM_SetCaption ("SDL MultiMedia Application", NULL);

done = 0;
while (!done)
{
SDL_Event event;

/* Check for events */
while (SDL_PollEvent (&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
break;
case SDL_QUIT:
done = 1;
break;
default:
break;
}
}
}

return 0;
}



The Dev-C++ version is 4.9.9.1 with SDL version 1.2.4. Note that the program I tested was initially created by the Dev template, but I think that this makes no differences since parameters should be the same.
0

Share this post


Link to post
Share on other sites
I will take a look at the code, but I am sure the problem lies in the fact you are using SDL 1.2.4. However, you are free to use it, but take a look at all the updates made! I would strongly suggest using at least version 1.2.7, but once again, you are free to use whatever you want. I know I have 1.2.8 and my console functions work just fine, cout and c-style alike. I'd say download a more recent version, but do not install over your current, simply make a test project, and move the files into that project and see if you get the same errors.

Instead of linking SDL.lib and such, use relative path names - ie

#pragma comment ( lib, "C:\\sdl 1.2.7\\lib\\sdl.lib" )


That's just an example of what you can do. I think it would be better for whatever you are doing because of the serious bugs that are fixed as of 1.2.7, but you can determine that for yourself.

- Drew
1

Share this post


Link to post
Share on other sites
First of all thank you for having point out that there are more recent versions of sdl... I'm so lazy that I trusted that if it were a new version, it would have been released as package for Dev-C++ (sometimes I feel stupid :-( ((Uh, this sentences were too complex for my bad english: I hope they are at least understandable))

Second: it still doesn't work. I will try others configurations (don't know if #pragma used to link libraries is supported by Dev-C++, I thought that it was VC++ specific).

@Easca: could you tell me if the problem was solved on your system by updating SDL? (...if you want to update it, of course)

Thank you all anyway!
0

Share this post


Link to post
Share on other sites
Ahh! [lol] I'm sorry, I got confused and thought that Easca was the OP. Ok for dev-cpp that #pragma will not work for the most part with SDL, so I would just copy the current version of SDL you have to a folder then install the new one. Then you can try your program again, since the linker libs will now be updated. Do not forget to update the .DLL in the system directory as well.

- Drew
0

Share this post


Link to post
Share on other sites
Ok at work I had sdl 1.2.4 I also assumed it would automatically give me the latest version through the package manager :-(.

Anyway at home I have SDl 1.2.7 installed and I also put in a copy of SDL 1.2.8 and both of them still print to stdout.txt.
0

Share this post


Link to post
Share on other sites
Ok I'd like to say sorry for not trying out my suggestions first. I was using VS6 and VS7 the whole time and it worked fine. I am thinking that the only way to fix this under Dev-CPP and MingGW is by recompiling per the response to the link that Easca posted. I tried the redirecting output myself and could not get it to work either. I then tried Oluseyi's link as well, but it failed the same. As of now that is all I can think of.

- Drew
0

Share this post


Link to post
Share on other sites
Ah, well I'll just put up with the stdout.txt. It would be nice to be able to do it without recompiling though.
0

Share this post


Link to post
Share on other sites
Ok. The funny thing is that I don't even get the stdout.txt file. Uhm... I will use some font library (I would have to use it however, soon or later).
Thank you again!
0

Share this post


Link to post
Share on other sites
Quote:
Original post by cignox1
Ok. The funny thing is that I don't even get the stdout.txt file. Uhm... I will use some font library (I would have to use it however, soon or later).
Thank you again!

Did you try using:

freopen( "stdout.txt", "wt", stdout );
freopen( "stderr.txt", "wt", stderr );

0

Share this post


Link to post
Share on other sites
Quote:
Original post by cignox1
Ok. The funny thing is that I don't even get the stdout.txt file. Uhm... I will use some font library (I would have to use it however, soon or later).
Thank you again!


Are you aware that the file deletes itself after your program ends? To make anything of it you'll most likely run your program in windowed mode and look at the text file during debugging/testing.

Edit: If nothing is written to it :)

[Edited by - Rhaal on February 10, 2005 5:43:36 PM]
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Rhaal
Quote:
Original post by cignox1
Ok. The funny thing is that I don't even get the stdout.txt file. Uhm... I will use some font library (I would have to use it however, soon or later).
Thank you again!


Are you aware that the file deletes itself after your program ends? To make anything of it you'll most likely run your program in windowed mode and look at the text file during debugging/testing.


It should only do that when no text is sent there. If the file contains text, it is left intact.
0

Share this post


Link to post
Share on other sites
Quote:

freopen( "stdout.txt", "wt", stdout );
freopen( "stderr.txt", "wt", stderr );


Uh, I thought that it would have been opened from the program without specific instructions...
0

Share this post


Link to post
Share on other sites

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  
Followers 0