Skip to main content
GameDev.net gamedev.net
🔒 Locked

Damned Screenshots

Started by black_mage_s May 1, 2002 at 6:58 PM 13 replies 1.5k views
Original Post
black_mage_s
black_mage_s
Alright, i have tried everything i can think of for getting my game to take a screenshot. I added code that exported to a BMP I tried printscreen and pasting into paint BUT NOTHING WORKS! Why? Help!
"Luck is for people without skill."- Robert (I Want My Island)"Real men eat food that felt pain before it died."- Me
Lohrno
Lohrno
I think there are some utilities for creating screenshots that you can use, check tucows, or cnet. Some will work for DirectX, some for OpenGl, and some for both I''d imagine.

-=Lohrno
23yrold3yrold
23yrold3yrold
If you''re using Windows, try pressing the PrintScreen key and checking your clipboard.

Chris Barry (crbarry at mts.net)
My Personal Programming Depot
Jesus saves ... the rest of you take 2d4 fire damage.
black_mage_s
black_mage_s
i did try that, there is something there, but it doesnt paste right, it comes out black
"Luck is for people without skill."- Robert (I Want My Island)"Real men eat food that felt pain before it died."- Me
benjamin bunny
benjamin bunny
Most paint programs have a capture featureI usually use PSP 4.0 to do screenshots of my OpenGL stuff. Writing a BMP exporter shouldn''t be hard though, provided you know the BMP spec. Otherwise, just export it in RAW format and convert it with your paint program.

____________________________________________________________
www.elf-stone.com
Will O
Will O
ok, go to Control Panel, DirectX. Under ddraw, check the enable PrintScreen box. should work, just tested it.
black_mage_s
black_mage_s
1. Im using OpenGL
2. I use GIMP for 2d stuff
"Luck is for people without skill."- Robert (I Want My Island)"Real men eat food that felt pain before it died."- Me
__ALex_J_
__ALex_J_
I just hacked this small glut app to give you a working screenshot fature.

What I added is in the ScreenShot function.

This function takes a screenshot and put it in the file scr_shot.tga.

The tga files contain many 16bit values in (intel) big-endian format.

What I did is just to wirte "unsiged short int" directly to the file. If you use a little-endian processor or a strange system where "unsigned short int" isn't 16bit, you need to change the code.


            
/*
* Code to take screenshots in
* glut by Alexandre Jasmin. Based on...
*/

/*
* A skeleton/template GLUT program
*
* Written by Brian Paul and in the public domain.
*/

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <GL/glut.h>


static GLfloat Xrot = 0, Yrot = 0, Zrot = 0;
static GLboolean Anim = GL_FALSE;

static GLint ViewportWidth, ViewportHeight;


static void ScreenShot( void )
{
int i;
FILE *f;
unsigned short int si;
size_t ImageSize;
unsigned char *Image;

/* Height X Width X 3 bytes per pixel */
ImageSize = ViewportHeight * ViewportWidth * 3;

/* Alocate a memory buffer to store the image */
if (!(Image = malloc(ImageSize)))
{
perror("malloc()");
return;
}

/* Copy the front buffer to our image buffer */
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadBuffer(GL_FRONT);
glReadPixels(0, 0, ViewportWidth, ViewportHeight, GL_RGB, GL_UNSIGNED_BYTE, Image);

/* Create or overwrite scr_shot.tga */
if (!(f = fopen("scr_shot.tga", "wb")))
{
perror("fopen()");
free(Image);
return;
}
/* write tga file header */
fputc('\x00', f); /* ID Length: 0 */
fputc('\x00', f); /* Color Map Type: no color-map */
fputc('\x02', f); /* Image Type: Uncompressed, True-color */
for (i=0; i<5; i++) /* Color Map Specification: no color-map */
fputc('\x00', f);

si = 0; /* X-origin of Image: 0 */
fwrite(&si, sizeof(short int), 1, f);
si = 0; /* Y-origin of Image: 0 */
fwrite(&si, sizeof(short int), 1, f);

si = ViewportWidth; /* Image Width */
fwrite(&si, sizeof(short int), 1, f);
si = ViewportHeight; /* Image Height */
fwrite(&si, sizeof(short int), 1, f);


fputc('\x18', f); /* Pixel Depth: 24 */

fputc('\x00', f); /* Image Descriptor */

/* write the image itself */
fwrite(Image, ImageSize, 1, f);

/* close the file */
if (fclose(f)==EOF)
{
perror("fclose()");
}

/* free memory */
free(Image);
}


static void Idle( void )
{
Xrot += 3.0;
Yrot += 4.0;
Zrot += 2.0;
glutPostRedisplay();
}


static void Display( void )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glPushMatrix();
glRotatef(Xrot, 1, 0, 0);
glRotatef(Yrot, 0, 1, 0);
glRotatef(Zrot, 0, 0, 1);

glutSolidCube(2.0);

glPopMatrix();

glutSwapBuffers();
}


static void Reshape( int width, int height )
{
ViewportWidth = width;
ViewportHeight = height;

glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0, 0.0, -15.0 );
}


static void Key( unsigned char key, int x, int y )
{
const GLfloat step = 3.0;
(void) x;
(void) y;
switch (key) {
case 's':
ScreenShot();
break;
case 'a':
Anim = !Anim;
if (Anim)
glutIdleFunc(Idle);
else
glutIdleFunc(NULL);
break;
case 'z':
Zrot -= step;
break;
case 'Z':
Zrot += step;
break;
case 27:
exit(0);
break;
}
glutPostRedisplay();
}


static void SpecialKey( int key, int x, int y )
{
const GLfloat step = 3.0;
(void) x;
(void) y;
switch (key) {
case GLUT_KEY_UP:
Xrot -= step;
break;
case GLUT_KEY_DOWN:
Xrot += step;
break;
case GLUT_KEY_LEFT:
Yrot -= step;
break;
case GLUT_KEY_RIGHT:
Yrot += step;
break;
}
glutPostRedisplay();
}


static void Init( void )
{
/* setup lighting, etc */

glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}


int main( int argc, char *argv[] )
{
glutInit( &argc, argv );
glutInitWindowPosition( 0, 0 );
glutInitWindowSize( 400, 400 );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow(argv[0]);
glutReshapeFunc( Reshape );
glutKeyboardFunc( Key );
glutSpecialFunc( SpecialKey );
glutDisplayFunc( Display );
Init();
glutMainLoop();
return 0;
}



Does it answer your question?


[edited by - __ALex_J_ on May 3, 2002 11:43:23 AM]
Andrew Nguyen
Andrew Nguyen
Won''t compile and you know why!
---START GEEK CODE BLOCK---GCS/M/S dpu s:+ a---- C++ UL(+) P(++) L+(+) E--- W++ N+ o K w(--) !O !M !V PS- PE+Y+ PGP+ t 5 X-- R tv+ b+ DI+ D G e* h! r-- !x ---END GEEK CODE BLOCK---
__ALex_J_
__ALex_J_
Why?

[edited by - __ALex_J_ on May 3, 2002 1:03:01 AM]
Andrew Nguyen
Andrew Nguyen
Keep at it Alexandar. YOu will see! COME TO THE TROLL siDE! Improper code tags lead to imporper posts. Improper posts lead to ha><()|2|||\|G! Which leads to the Troll side!!!!
---START GEEK CODE BLOCK---GCS/M/S dpu s:+ a---- C++ UL(+) P(++) L+(+) E--- W++ N+ o K w(--) !O !M !V PS- PE+Y+ PGP+ t 5 X-- R tv+ b+ DI+ D G e* h! r-- !x ---END GEEK CODE BLOCK---
__ALex_J_
__ALex_J_
I see that the SOURCE tag cause strange things to my code but why is it improper to use code tags to fromat code? It seams more like a bug than an improper use.

Note:
The code now compile Thank you Oluseyi who told me to to insert an extra newline between the #includes

[edited by - __ALex_J_ on May 3, 2002 1:30:52 AM]
abstractworlds
abstractworlds
If you''re looking for a quick utility rather than a programming solution try HyperSnap-DX at:

www.hyperionics.com

The product info mentions support for DirectX, Direct3D, and 3Dfx Glide applications but it doesn''t mention OpenGL at all. However it successfully captured screens from a full-screen OpenGL application on my PC (GeForce2, Win98 - maybe the GeForce OpenGL driver uses DirectX at a lower lever, DirectDraw).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.