www.xbdev.net
xbdev - software development
Friday May 9, 2025
Home | Contact | Support | OpenXDK The Free, Legal, Open Source XBox Development Kit...
     
 

OpenXDK

The Free, Legal, Open Source XBox Development Kit...

 

ScreenCapture - Save the screen to a tga file



Sometimes it's useful to grab the screen and save it to file. For a number of reasons, it allows you to really sit down and look at the image (debugging), it also allow us to create screenshots so you can show off your demo's...hehehe.

The default location of the save is to the
D
drive on the local xbox harddrive. Once the file has been saved - you can ftp or and copy the file to your computer (or use one of the xbox file access tools).


/*********************************************************************************/
/*                                                                               */
/*  XBOX OpenXDK ScreenCatpure                                                   */
/*                                                                               */
/*  File:   screencapture.c                                                      */
/*  Date:   23-02-04                                                             */
/*  About:  Uncomplicated screen capture function (graps raw pixels) saves to    */
/*          tga file.                                                            */
/*                                                                               */
/*********************************************************************************/
/*                                                                               */
/*  Platform: XBOX - OpenXDK                                                     */
/*                                                                               */
/*********************************************************************************/
 
// tga header structure.
#pragma pack(1)
typedef struct _tgaheader
{
      
uint08 idlength;              // Misc header
      
uint08 colourmap;
      
uint08 imagetype;
      
uint16 colourmap_origin;      // Colour map spec
      
uint16 colourmap_length;
      
uint08 colourmap_type;
      
uint16 xorigin;                     // Image spec
      
uint16 yorigin;
      
uint16 width;
      
uint16 height;
      
uint08 pixelsize;
      
uint08 descriptor;
TGAHeader, *PTGAHeader;
#pragma pack()
 

void ScreenCapture(char *path)
{
      
TGAHeader Header = {0,0,20,0,320,480,640,480,32,0x00000008};
 
      
HANDLE TGAoutput CreateFile(pathGENERIC_WRITE00CREATE_ALWAYS00);
      
WriteFile(TGAoutput, &Headersizeof(Header), 00);
 
      
ScreenInfo ScrStruct vga_get_screen_info();
      
uint32pScr = (uint32*)ScrStruct.ScreenAddress;
      
uint32 *FileBuffer = (uint32*)malloc(640*480*4);
 
      
uint32 ij;
      for (
i=0i<480i++)
      {
            for (
j=0j<640j++)
            {
                  
FileBuffer[j+((479-i)*640)] = *pScr;
                  
pScr++;
            }
// End inner loop
      
}// End outer loop
 
      
WriteFile(TGAoutputFileBuffer640*480*400);
      
CloseHandle(TGAoutput);
 
      
free(FileBuffer);
}
// End ScreenCapture(..)
 
 
/*********************************************************************************/
/*                                                                               */
/*                          Program Entry Point                                  */
/*                                                                               */
/*********************************************************************************/
/*                                                                               */
/*  Few lines of code to test our code, launch different apps etc.               */
/*                                                                               */
/*********************************************************************************/
 
void main()
{
      
Bitmap         *screen;
      
unsigned int   *p;
      
int                xyxx=0;
 
      
//let's init the screen
      
vga_init_mode(MODE_320x240x32);
 
      
vga_vsync();                              // Wait for Vertical Blank
    
vga_flip();                                 // Flip
      
vga_clear();                    // Clear Screen
 
      // So where's the screen? who knows if we're page flipping?
      
screen get_screen_bitmap();
 
      
// Nice pattern on the screen
      
screen->data;
      for (
y=0y<screen->hy++)
      {
            for (
x=0x<screen->wx++)
            {
                        *
p++ = ((x+xx)^y)&0xFF//yay a XOR pattern!!! :D
            
}
      }
      
xx++;
 
      
// Save our data that we've rendered to the screen, before
      // we try and save it to file
      
vga_vsync();                              // Wait for Vertical Blank
    
vga_flip();                                 // Flip
 
 
      
ScreenCapture("D:\\screengrab.tga");
 
}
// End main



 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2025 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.