home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ST-Computer Leser 2002 January
/
STC_CD_01_2002.iso
/
JAGUAR
/
JAG_SRC
/
SOURCE
/
VIDEO.C
< prev
Wrap
C/C++ Source or Header
|
2001-08-17
|
11KB
|
282 lines
////////////////////////////////////////////////////////////////////////////////
// Jagulator: Atari Jaguar Console Emulation Project (video.c)
// -----------------------------------------------------------------------------
// Jagulator is the Copyright (c) RealityMan 1998-2001 and is provided "as is"
// without any expressed or implied warranty. I have no Trademarks, Legal or
// otherwise. Atari, Jaguar and the Atari Logo are copyright Hasbro Inc. All
// other Copyrights and Trademarks are acknowledged. This project is in no way
// linked to Atari/Hasbro or other associated Atari companies.
//
// 07-07-2001 GH: New Source, Rewritten for Release 1.5.0
// 00-00-0000 GH: All Previous Source Considered as Development Code Only
#include "core.h"
////////////////////////////////////////////////////////////////////////////////
// Globals
HGLRC hRCMain; // Permanent Rendering Context
HDC hDCMain; // Private GDI Device Context
PAINTSTRUCT psMain; // Paint Structure
////////////////////////////////////////////////////////////////////////////////
// Get OpenGL Information
void v_getglinfo( void )
{
FILE *glinfo; // OpenGL Information File Pointer
char *extensions = NULL; // OpenGL Extension Pointer
int nPixelFormat; // Returned Pixel Format
static char buf[MAX_PATH]; // Temporary Buffer
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1, // Version of this Structure
PFD_DRAW_TO_WINDOW | // Draw to Window (Not Bitmap)
PFD_SUPPORT_OPENGL | // Support OpenGL Calls
PFD_DOUBLEBUFFER | // Double Buffered Mode
PFD_GENERIC_ACCELERATED |
PFD_TYPE_RGBA, // RGBA Color Mode
32, // Want 'cdepth' Color
0, 0, 0, 0, 0, 0, // Not Used to Select Mode
0, 0, // Not Used to Select Mode
0, 0, 0, 0, 0, // Not Used to Select Mode
32, // 'cdepth' Depth Buffer
0, // Not Used to Select Mode
0, // Not Used to Select Mode
PFD_MAIN_PLANE, // Draw in Main Plane
0, // Not Used to Select Mode
0, 0, 0 // Not Used to Select Mode
};
extern HWND hwndMain;
hDCMain = GetDC( hwndMain ); // Store the Device Context
// Choose a Pixel Format that Best Matches Above
nPixelFormat = ChoosePixelFormat( hDCMain, &pfd );
// Set the Pixel Format for the Device Context
SetPixelFormat( hDCMain, nPixelFormat, &pfd );
// Create the Rendering Context and Make it Current
hRCMain = wglCreateContext( hDCMain );
wglMakeCurrent( hDCMain, hRCMain );
// Setup Temporary File
GetTempPath( MAX_PATH, buf );
strcat( buf, "oglinfo" );
glinfo = fopen( buf, "w" );
// Get the OpenGL Vendor
extensions = (char *)glGetString( GL_VENDOR );
fwrite( extensions, strlen(extensions) + 1, 1, glinfo );
// Get the OpenGL Renderer
extensions = (char *)glGetString( GL_RENDERER );
fwrite( extensions, strlen(extensions) + 1, 1, glinfo );
// Get the OpenGL Version
extensions = (char *)glGetString( GL_VERSION );
fwrite( extensions, strlen(extensions) + 1, 1, glinfo );
// Get the OpenGL Extension List
extensions = (char *)glGetString( GL_EXTENSIONS );
fwrite( extensions, strlen(extensions) + 1, 1, glinfo );
fclose( glinfo );
// Deselect the Current Rendering Context and Delete it
wglMakeCurrent( hDCMain, NULL );
wglDeleteContext( hRCMain );
}
////////////////////////////////////////////////////////////////////////////////
// Initialise OpenGL
int v_init( int width, int height )
{
int nPixelFormat; // Returned Pixel Format
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1, // Version of this Structure
PFD_DRAW_TO_WINDOW | // Draw to Window (Not Bitmap)
PFD_SUPPORT_OPENGL | // Support OpenGL Calls
PFD_DOUBLEBUFFER | // Double Buffered Mode
PFD_GENERIC_ACCELERATED |
PFD_TYPE_RGBA, // RGBA Color Mode
32, // Want 32-Bit Color
0, 0, 0, 0, 0, 0, // Not Used to Select Mode
0, 0, // Not Used to Select Mode
0, 0, 0, 0, 0, // Not Used to Select Mode
32, // Size of Depth Buffer
0, // Not Used to Select Mode
0, // Not Used to Select Mode
PFD_MAIN_PLANE, // Draw in Main Plane
0, // Not Used to Select Mode
0, 0, 0 // Not Used to Select Mode
};
// Resize window so that the desired resolution is completely shown.
// (Width + 9, Height + 75)
MoveWindow( hwndMain, 20, 20, width + 9, height + 46, TRUE );
//ShowWindow( hwndStatus, SW_HIDE ); // Hide Status Bar
hDCMain = GetDC( hwndMain ); // Store the Device Context
// Choose a Pixel Format that Best Matches Above
nPixelFormat = ChoosePixelFormat( hDCMain, &pfd );
if( !nPixelFormat )
{
MessageBox( NULL, "ChoosePixelFormat() Failed.", "OpenGL",
MB_ICONEXCLAMATION | MB_OK );
return( 1 );
}
// Set the Pixel Format for the Device Context
SetPixelFormat( hDCMain, nPixelFormat, &pfd );
// Create the Rendering Context and Make it Current
hRCMain = wglCreateContext( hDCMain );
wglMakeCurrent( hDCMain, hRCMain );
return( 0 );
}
////////////////////////////////////////////////////////////////////////////////
// Uninitialise OpenGL
void v_deinit( void )
{
hDCMain = BeginPaint( hwndMain, &psMain );
wglMakeCurrent( hDCMain, hRCMain );
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f);
glClearDepth( 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
SwapBuffers( hDCMain ); glClearColor( 0.0f, 0.0f, 0.0f, 1.0f);
wglMakeCurrent( NULL, NULL );
EndPaint( hwndMain, &psMain );
// Deselect the Current Rendering Context and Delete it
wglMakeCurrent( hDCMain, NULL );
wglDeleteContext( hRCMain );
}
////////////////////////////////////////////////////////////////////////////////
// Start Frame
static void v_startframe( void )
{
hDCMain = BeginPaint( hwndMain, &psMain );
wglMakeCurrent( hDCMain, hRCMain );
}
////////////////////////////////////////////////////////////////////////////////
// End Frame
void v_endframe( void )
{
wglMakeCurrent( NULL, NULL );
EndPaint( hwndMain, &psMain );
}
////////////////////////////////////////////////////////////////////////////////
// Define Draw Mode
static void v_realdrawmode( void )
{
glViewport(0, 0, cfg.hres, cfg.vres);
/*
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, (GLfloat)cfg.hres, 0.0, (GLfloat)cfg.vres, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
*/
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, (GLfloat)cfg.hres, (GLfloat)cfg.vres, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
////////////////////////////////////////////////////////////////////////////////
// Clear Frame Buffer
static void v_clear( int color )
{
//glClearColor( (GLclampf)(0.03 * color), (GLclampf)(0.03 * color),
// (GLclampf)(0.03 * color), (GLclampf)(1.0f) );
//glClearColor( 0.0f, 0.0f, 0.0f, 1.0f);
glClearColor( st.br, st.bg, st.bb, 1.0f);
glClearDepth( 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
}
////////////////////////////////////////////////////////////////////////////////
// Swap Front and Back Buffers
static void v_swap( void )
{
SwapBuffers( hDCMain );
glViewport( 0, 0, cfg.hres, cfg.vres );
v_clear( 0 );
v_realdrawmode();
}
////////////////////////////////////////////////////////////////////////////////
// Open Display
static void v_opendisplay( void )
{
#ifdef DEBUG
print( CYAN"Graphics Initialized: [%i x %i]\n", cfg.hres, cfg.vres );
#endif
//v_init( cfg.hres, cfg.vres );
v_swap();
}
////////////////////////////////////////////////////////////////////////////////
// Public Video Routines //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Open Display
void obj_opendisplay( void )
{
if( st.opened ) return; // Return if Already Opened
st.opened = 1; // Set 'Opened' Flag
#ifdef DEBUG
print( CYAN"Open Display\n" );
#endif
v_opendisplay(); // Open the Graphics Display
}
////////////////////////////////////////////////////////////////////////////////
// Start of Frame
void obj_framestart( void )
{
if( st.frameopen ) return; // Return if Frame Already Opened
st.frameopen = 1; // Set 'Opened' Flag
v_startframe();
obj_opendisplay(); // Open Graphics Display
}
////////////////////////////////////////////////////////////////////////////////
// End of Frame
void obj_frameend( void )
{
if( !st.frameopen ) return; // Return if Frame Already Ended
st.frameopen = 0; // Unset 'Opened' Flag
v_swap(); // Show Buffer on Screen
v_endframe();
}