Files
bluflame/evoke-64k/ev09/picstuff.h
2026-04-18 22:31:51 +02:00

357 lines
7.3 KiB
C

D3DLOCKED_RECT g_d3dlr;
const int iTexSize= 256;
int Pre[ iTexSize * iTexSize ];
int PixelStack[ iTexSize * iTexSize ];
int PixelStackPointer= 0;
DWORD dwColor[ 12 ]=
{
0,
0xff000000,
0xffffffff,
0xc0000000,
0xa0000000,
0x80000000,
0x60000000,
0x40000000,
0x20000000,
0x10000000,
0x00000000,
0x00000000,
};
int GetPre( int x, int y )
{
if( x < 0 || x >= iTexSize || y < 0 || y >= iTexSize )
{
return -1;
}
return Pre[ y * iTexSize + x ];
}
void FillAndAdd( int x, int y )
{
if( Pre[ y * iTexSize + x ] == 1 || Pre[ y * iTexSize + x ] == 0 )
{
return;
}
int iOffset= y * iTexSize + x;
Pre[ iOffset ]= 0;
PixelStack[ PixelStackPointer ]= iOffset;
PixelStackPointer++;
}
void ClearAlpha( int x, int y )
{
FillAndAdd( x, y );
while( PixelStackPointer > 0 )
{
PixelStackPointer--;
x= PixelStack[ PixelStackPointer ] % iTexSize;
y= PixelStack[ PixelStackPointer ] / iTexSize;
if( x > 0 )
{
FillAndAdd( x - 1, y );
}
if( x < iTexSize - 1 )
{
FillAndAdd( x + 1, y );
}
if( y > 0 )
{
FillAndAdd( x, y - 1 );
}
if( y < iTexSize - 1 )
{
FillAndAdd( x, y + 1 );
}
}
}
void FindAndExpandBorder()
{
PixelStackPointer= 0;
for( int y= 1; y < iTexSize - 1; y++ )
{
for( int x= 1; x < iTexSize - 1; x++ )
{
bool bBorder= false;
bool bCenter= false;
for( int dy= -1; dy <= 1; dy++ )
{
for( int dx= -1; dx <= 1; dx++ )
{
int Val= Pre[ ( y + dy ) * iTexSize + x + dx ];
if( dx ==0 && dy == 0 )
{
bCenter= Val > 0;
}
else if( !bBorder )
{
bBorder= Val < 1;
}
}
}
if( bBorder && bCenter )
{
int iOffset= y * iTexSize + x;
PixelStack[ PixelStackPointer ]= iOffset;
PixelStackPointer++;
}
}
}
while( PixelStackPointer > 0 )
{
PixelStackPointer--;
int x= PixelStack[ PixelStackPointer ] % iTexSize;
int y= PixelStack[ PixelStackPointer ] / iTexSize;
for( int dy= -16; dy <= 16; dy++ )
{
for( int dx= -16; dx <= 16; dx++ )
{
if( dx * dx + dy * dy <= 16 * 16 + 16 )
{
int Offset= ( y + dy ) * iTexSize + x + dx;
if( Pre[ Offset ] < 1 )
{
Pre[ Offset ]= 2;
}
}
}
}
}
}
void DropShadow( int dx, int dy )
{
for( int y= 0; y < iTexSize; y++ )
{
for( int x= 0; x < iTexSize; x++ )
{
int iOffset= y * iTexSize + x;
if( GetPre( x + dx, y + dy ) == 2 && Pre[ iOffset ] < 1 )
{
Pre[ iOffset ]= 2 + abs( dx );
}
}
}
}
void CreatePicTexture( int iPic, const unsigned char* ucData )
{
for( int i= 0; i < iTexSize * iTexSize; ++i )
{
Pre[ i ]= -1;
}
int iPos= 0;
int iWidth= ucData[ iPos++ ];
int iHeight= ucData[ iPos++ ];
int iStartX= ( iTexSize - iWidth ) / 2;
int iStartY= iTexSize - iHeight - 22;
int iMask= 128;
for( int y= 0; y < iHeight; y++ )
{
for( int x=0; x < iWidth; x++ )
{
Pre[ ( y + iStartY ) * iTexSize + x + iStartX ]=
( iMask & ucData[ iPos ] ) ? 1 : 2;
iMask/= 2;
if( iMask == 0 )
{
iMask= 128;
iPos++;
}
}
}
ClearAlpha( iTexSize / 2, 0 );
FindAndExpandBorder();
DropShadow( 1, 2 );
DropShadow( -2, -2 );
DropShadow( 2, -2 );
DropShadow( 2, 4 );
DropShadow( -3, 4 );
DropShadow( 3, 6 );
DropShadow( 4, 8 );
DropShadow( 5, 10 );
g_d3d_device->CreateTexture(
iTexSize,
iTexSize,
1,
0,
D3DFMT_A8R8G8B8,
D3DPOOL_MANAGED,
&g_pPictures[ iPic ],
NULL );
g_pPictures[ iPic ]->LockRect( 0, &g_d3dlr, 0, 0 );
DWORD* pDst = (DWORD*)g_d3dlr.pBits;
for( int i= 0; i < iTexSize * iTexSize; ++i )
{
pDst[ i ]= dwColor[ Pre[ i ] ];
}
g_pPictures[ iPic ]->UnlockRect( 0 );
}
#include "marcel.h"
#include "tggc.h"
#include "hannibal.h"
#include "puetz.h"
#include "garfield.h"
#include "timba.h"
#include "spock.h"
#include "seekuh.h"
#include "seagull.h"
#include "oldgyver.h"
#include "data.h"
#include "bruce.h"
#include "dm.h"
#include "wolverine.h"
#include "sau.h"
#include "norris.h"
void RenderLoading( int iPercent );
void CreatePictures()
{
int iAdd= 2;
int i= 0;
CreatePicTexture( 0, g_puetz);
RenderLoading( i ); i+= iAdd;
CreatePicTexture( 1, g_marcel );
RenderLoading( i ); i+= iAdd;
CreatePicTexture( 2, g_tggc );
RenderLoading( i ); i+= iAdd;
CreatePicTexture( 3, g_timba);
RenderLoading( i ); i+= iAdd;
CreatePicTexture( 4, g_spock);
RenderLoading( i ); i+= iAdd;
CreatePicTexture( 5, g_seekuh);
RenderLoading( i ); i+= iAdd;
CreatePicTexture( 6, g_seagull);
RenderLoading( i ); i+= iAdd;
CreatePicTexture( 7, g_oldgyver);
RenderLoading( i ); i+= iAdd;
CreatePicTexture( 8, g_data);
RenderLoading( i ); i+= iAdd;
CreatePicTexture( 9, g_bruce);
RenderLoading( i ); i+= iAdd;
CreatePicTexture( 10, g_hannibal );
RenderLoading( i ); i+= iAdd;
CreatePicTexture( 11, g_garfield );
RenderLoading( i ); i+= iAdd;
CreatePicTexture( 12, g_dm );
RenderLoading( i ); i+= iAdd;
CreatePicTexture( 13, g_wolverine );
RenderLoading( i ); i+= iAdd;
CreatePicTexture( 14, g_norris );
RenderLoading( i ); i+= iAdd;
CreatePicTexture( 15, g_sau );
RenderLoading( i ); i+= iAdd;
}
struct SVertexPic
{
FLOAT x, y, z;
FLOAT tx, ty;
};
const DWORD c_dwFVFPic= D3DFVF_XYZ|D3DFVF_TEX1;
SVertexPic g_VertPic[]=
{
{ -1.0f, -1.0f, 5.0f, 0.01f, 0.01f },
{ -1.0f, 1.0f, 5.0f, 0.01f, 0.99f },
{ 1.0f, -1.0f, 5.0f, 0.99f, 0.01f },
{ 1.0f, 1.0f,5.0f, 0.99f, 0.99f },
};
void RenderPic( int iIndex, float fMidX, float fMidY, float fSize )
{
g_d3d_device->SetRenderState( D3DRS_LIGHTING, FALSE );
g_d3d_device->SetRenderState( D3DRS_ZENABLE, FALSE );
g_d3d_device->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
g_d3d_device->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
g_d3d_device->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
g_d3d_device->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
g_d3d_device->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATER );
g_d3d_device->SetRenderState( D3DRS_ALPHAREF, 0x20 );
g_d3d_device->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
g_d3d_device->SetSamplerState(0,D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
g_d3d_device->SetSamplerState(0,D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
g_d3d_device->SetSamplerState(0,D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
g_d3d_device->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_d3d_device->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
g_d3d_device->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TEXTURE );
g_d3d_device->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
g_d3d_device->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
D3DXMATRIX mat;
D3DXMatrixOrthoLH(
&mat,
1024.0f,
-576.0f * (float)c_iScreenSizeY / (float)c_iRealScreenY,
1.0f,
8.0f );
g_d3d_device->SetTransform( D3DTS_PROJECTION, &mat );
D3DXMatrixIdentity( &mat );
g_d3d_device->SetTransform( D3DTS_VIEW, &mat );
g_d3d_device->SetTransform( D3DTS_WORLD, &mat );
{
g_VertPic[ 0 ].x= fMidX - fSize;
g_VertPic[ 0 ].y= fMidY - fSize;
g_VertPic[ 1 ].x= fMidX - fSize;
g_VertPic[ 1 ].y= fMidY + fSize;
g_VertPic[ 2 ].x= fMidX + fSize;
g_VertPic[ 2 ].y= fMidY - fSize;
g_VertPic[ 3 ].x= fMidX + fSize;
g_VertPic[ 3 ].y= fMidY + fSize;
g_d3d_device->SetTexture( 0, g_pPictures[ iIndex ] );
g_d3d_device->SetFVF( c_dwFVFPic );
g_d3d_device->DrawPrimitiveUP(
D3DPT_TRIANGLESTRIP,
2,
g_VertPic,
sizeof( SVertexPic )
);
}
}