mirror of
https://github.com/libretro/libretro-wolfenstein3d.git
synced 2024-11-23 00:19:48 +00:00
Add screenshot capability.
This commit is contained in:
parent
b5c951323e
commit
fc82aa2e40
57
crt.cpp
57
crt.cpp
@ -8,6 +8,14 @@
|
||||
|
||||
#include "crt.h"
|
||||
|
||||
// Win32
|
||||
#ifdef _WIN32
|
||||
#include "SDL.h"
|
||||
#elif __linux__
|
||||
#include "SDL/SDL.h"
|
||||
#else
|
||||
#include "SDL/SDL.h"
|
||||
#endif
|
||||
|
||||
static int width;
|
||||
static int height;
|
||||
@ -66,6 +74,7 @@ void CRT_DAC(void){
|
||||
*pixelPointer++ = curpal[paletteIndex].b;
|
||||
}
|
||||
|
||||
|
||||
//Upload texture
|
||||
glBindTexture(GL_TEXTURE_2D, crtTexture);
|
||||
glTexSubImage2D(GL_TEXTURE_2D,
|
||||
@ -89,4 +98,52 @@ void CRT_DAC(void){
|
||||
|
||||
//Flip buffer
|
||||
SDL_GL_SwapBuffers();
|
||||
|
||||
Uint8 *keystate = SDL_GetKeyState(NULL);
|
||||
static int wasPressed = 0;
|
||||
if ( keystate[SDLK_i] ){
|
||||
if (!wasPressed){
|
||||
wasPressed = 1;
|
||||
CRT_Screenshot();
|
||||
}
|
||||
}
|
||||
else
|
||||
wasPressed = 0;
|
||||
}
|
||||
|
||||
void CRT_Screenshot(void){
|
||||
|
||||
const char* filename = "screenshot.tga" ;
|
||||
|
||||
printf("Screenshot.\n");
|
||||
|
||||
//This prevents the images getting padded
|
||||
// when the width multiplied by 3 is not a multiple of 4
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
|
||||
int nSize = width*height*3;
|
||||
// First let's create our buffer, 3 channels per Pixel
|
||||
char* dataBuffer = (char*)malloc(nSize*sizeof(char));
|
||||
|
||||
if (!dataBuffer) return;
|
||||
|
||||
// Let's fetch them from the backbuffer
|
||||
// We request the pixels in GL_BGR format
|
||||
#define GL_BGR 0x80E0
|
||||
glReadPixels((GLint)0, (GLint)0,(GLint)width, (GLint)height, GL_BGR, GL_UNSIGNED_BYTE, dataBuffer);
|
||||
|
||||
//Now the file creation
|
||||
FILE *filePtr = fopen(filename, "wb");
|
||||
if (!filePtr) return;
|
||||
|
||||
|
||||
unsigned char TGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0};
|
||||
unsigned char header[6] = { width%256,width/256,height%256,height/256,24,0};
|
||||
|
||||
// We write the headers
|
||||
fwrite(TGAheader, sizeof(unsigned char), 12, filePtr);
|
||||
fwrite(header, sizeof(unsigned char), 6, filePtr);
|
||||
// And finally our image data
|
||||
fwrite(dataBuffer, sizeof(GLubyte), nSize, filePtr);
|
||||
fclose(filePtr);
|
||||
}
|
2
crt.h
2
crt.h
@ -34,5 +34,7 @@ void CRT_Init(int width);
|
||||
*/
|
||||
void CRT_DAC(void);
|
||||
|
||||
void CRT_Screenshot(void);
|
||||
|
||||
|
||||
#endif
|
||||
|
44
id_in.cpp
44
id_in.cpp
@ -290,8 +290,13 @@ static void processEvent(SDL_Event *event)
|
||||
if(sym < lengthof(ASCIINames) && ASCIINames[sym])
|
||||
LastASCII = ASCIINames[sym];
|
||||
}
|
||||
if(LastScan<SDLK_LAST)
|
||||
|
||||
if (LastScan<SDLK_i){
|
||||
}
|
||||
|
||||
if(LastScan<SDLK_LAST){
|
||||
Keyboard[LastScan] = 1;
|
||||
}
|
||||
if(LastScan == SDLK_PAUSE)
|
||||
Paused = true;
|
||||
break;
|
||||
@ -318,8 +323,9 @@ static void processEvent(SDL_Event *event)
|
||||
}
|
||||
}
|
||||
|
||||
if(key<SDLK_LAST)
|
||||
if(key<SDLK_LAST){
|
||||
Keyboard[key] = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -477,40 +483,6 @@ IN_ReadControl(int player,ControlInfo *info)
|
||||
info->dir = DirTable[((my + 1) * 3) + (mx + 1)];
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IN_WaitForKey() - Waits for a scan code, then clears LastScan and
|
||||
// returns the scan code
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
ScanCode
|
||||
IN_WaitForKey(void)
|
||||
{
|
||||
ScanCode result;
|
||||
|
||||
while ((result = LastScan)==0)
|
||||
IN_WaitAndProcessEvents();
|
||||
LastScan = 0;
|
||||
return(result);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IN_WaitForASCII() - Waits for an ASCII char, then clears LastASCII and
|
||||
// returns the ASCII value
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
char
|
||||
IN_WaitForASCII(void)
|
||||
{
|
||||
char result;
|
||||
|
||||
while ((result = LastASCII)==0)
|
||||
IN_WaitAndProcessEvents();
|
||||
LastASCII = '\0';
|
||||
return(result);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IN_Ack() - waits for a button or key press. If a button is down, upon
|
||||
|
4
id_in.h
4
id_in.h
@ -136,7 +136,7 @@ typedef struct {
|
||||
joyMultXH,joyMultYH;
|
||||
} JoystickDef;
|
||||
// Global variables
|
||||
extern volatile boolean Keyboard[];
|
||||
extern volatile boolean Keyboard[];;
|
||||
extern boolean MousePresent;
|
||||
extern volatile boolean Paused;
|
||||
extern volatile char LastASCII;
|
||||
@ -160,8 +160,6 @@ extern void IN_SetupJoy(word joy,word minx,word maxx,
|
||||
extern void IN_StopDemo(void),IN_FreeDemoBuffer(void),
|
||||
IN_Ack(void);
|
||||
extern boolean IN_UserInput(longword delay);
|
||||
extern char IN_WaitForASCII(void);
|
||||
extern ScanCode IN_WaitForKey(void);
|
||||
extern word IN_GetJoyButtonsDB(word joy);
|
||||
extern const char *IN_GetScanName(ScanCode);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user