Game Development Community

Writing a file

by David Spuhler · in Torque Game Engine · 06/05/2005 (5:52 am) · 4 replies

In order to find out what is going on in the Torque rendering process i wanted to write out the graphics framebuffer
in the GuiCanvas::renderFrame() by calling the fallowing self-defined function:

void GuiCanvas::writeBufferOut()
{
	
    if (!framebufferWritten && ((Platform::getVirtualMilliseconds() - createdAtTime) > 300000))
    {
	GLint viewport_params[4];

	glGetIntegerv(GL_VIEWPORT, viewport_params);
	
	GLuint fb_copy_buffer[viewport_params[2]*viewport_params[3]];
	
	glReadPixels(	viewport_params[0],
			viewport_params[1], 
			viewport_params[3],
			viewport_params[4],
			GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, fb_copy_buffer);

	GLuint width = (GLuint)(viewport_params[2]);
	GLuint height = (GLuint)(viewport_params[3]);
l
	std::ofstream outfile("framebuffer.dat", std::ofstream::binary);
	outfile.write((char *)(&width), sizeof(width));
	outfile.write((char *)(&height), sizeof(height));
	outfile.write((char *)(fb_copy_buffer), sizeof(fb_copy_buffer));
	outfile.close();
    }
}

unfortunatly that does not work: i get in real trouble when i try to include the fstream library..
then the compiler returns an error in the gcc library file basic_string.tcc (i am running torque on a linux
machine using gcc 3.3.5)

Can anybody tell me how to write a file in this case?

#1
06/06/2005 (5:05 am)
It looks like reasonable code. What kind of error is gcc spitting out? Is this at compile or link time?
#2
06/06/2005 (5:47 am)
I would suggest using FileStream instead of ofstream.
#3
06/07/2005 (4:19 am)
I solved the problem by putting the preprocessor-directive #include at the beginning of all the #includes. Now the File-I/O works perfectly.
Thank you anyway for your replies!
#4
10/01/2007 (11:36 am)
Hi.

Sorry for reviving an old post, but I have a similar problem. Doing the same as David (moving the include to the top) I get an error in link time:

Linking...
winMemory.obj : error LNK2005: "void * __cdecl operator new(unsigned int,void *)" (??2@YAPAXIPAX@Z) already defined in geneticAlgorithm.obj
../example/torqueDemo_DEBUG.exe : fatal error LNK1169: one or more multiply defined symbols found

Does anyone know how to work around this? -or is there another way to save binary data in files in Torque?