Skip to content

Commit

Permalink
Show the cockpit (just the begining of this)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Jan 11, 2017
1 parent 9db87ab commit c2c49ae
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 3 deletions.
Binary file added Bitmap/cockpit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions Car.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -714,3 +714,73 @@ void DrawCar (IDirect3DDevice9 *pd3dDevice)
pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, numCarVertices/3 ); // 3 points per triangle
}

struct TRANSFORMEDTEXVERTEX
{
FLOAT x, y, z, rhw; // The transformed position for the vertex.
FLOAT u, v; // Texture
};
#define D3DFVF_TRANSFORMEDTEXVERTEX (D3DFVF_XYZRHW|D3DFVF_TEX1)

static IDirect3DVertexBuffer9 *pCockpitVB = NULL;

extern IDirect3DTexture9 *g_pCockpit;

HRESULT CreateCockpitVertexBuffer (IDirect3DDevice9 *pd3dDevice)
{
if (pCockpitVB == NULL)
{
if( FAILED( pd3dDevice->CreateVertexBuffer( 4*sizeof(TRANSFORMEDTEXVERTEX),
D3DUSAGE_WRITEONLY, D3DFVF_TRANSFORMEDTEXVERTEX, D3DPOOL_DEFAULT, &pCockpitVB, NULL ) ) )
return E_FAIL;
}

TRANSFORMEDTEXVERTEX *pVertices;
if( FAILED( pCockpitVB->Lock( 0, 0, (void**)&pVertices, 0 ) ) )
return E_FAIL;
pVertices[0].x = 0.0f; pVertices[0].y = 0.0f; pVertices[0].z = 0.9f; pVertices[0].rhw = 1.0f;
pVertices[1].x = 640.0f; pVertices[1].y = 0.0f; pVertices[1].z = 0.9f; pVertices[1].rhw = 1.0f;
pVertices[2].x = 640.0f; pVertices[2].y = 480.0f; pVertices[2].z = 0.9f; pVertices[2].rhw = 1.0f;
pVertices[3].x = 0.0f; pVertices[3].y = 480.0f; pVertices[3].z = 0.9f; pVertices[3].rhw = 1.0f;
#ifdef linux
pVertices[0].u = 0.0f; pVertices[0].v = 1.0f;
pVertices[1].u = 1.0f; pVertices[1].v = 1.0f;
pVertices[2].u = 1.0f; pVertices[2].v = 0.0f;
pVertices[3].u = 0.0f; pVertices[3].v = 0.0f;
#else
pVertices[0].u = 0.0f; pVertices[0].v = 0.0f;
pVertices[1].u = 1.0f; pVertices[1].v = 0.0f;
pVertices[2].u = 1.0f; pVertices[2].v = 1.0f;
pVertices[3].u = 0.0f; pVertices[3].v = 1.0f;
#endif
pCockpitVB->Unlock();
return S_OK;
}


void FreeCockpitVertexBuffer (void)
{
if (pCockpitVB) pCockpitVB->Release(), pCockpitVB = NULL;
}


void DrawCockpit (IDirect3DDevice9 *pd3dDevice)
{
pd3dDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );

pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );

pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );

pd3dDevice->SetTexture( 0, g_pCockpit );

pd3dDevice->SetStreamSource( 0, pCockpitVB, 0, sizeof(TRANSFORMEDTEXVERTEX) );

pd3dDevice->SetFVF( D3DFVF_TRANSFORMEDTEXVERTEX );
pd3dDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 2 ); // 3 points per triangle

pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_DISABLE );
}
6 changes: 6 additions & 0 deletions Car.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ extern void FreeCarVertexBuffer (void);

extern void DrawCar (IDirect3DDevice9 *pd3dDevice);

extern HRESULT CreateCockpitVertexBuffer (IDirect3DDevice9 *pd3dDevice);

extern void FreeCockpitVertexBuffer (void);

extern void DrawCockpit (IDirect3DDevice9 *pd3dDevice);

#endif /* _CAR */
20 changes: 20 additions & 0 deletions StuntCarRacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define FURTHEST_Z (131072.0f)

#define NUM_ROAD_TEXTURES (6)
#define NUM_WHEEL_TEXTURES (3)

GameModeType GameMode = TRACK_MENU;

Expand All @@ -55,6 +56,9 @@ IDirectSoundBuffer8 *OffRoadSoundBuffer = NULL;
IDirectSoundBuffer8 *EngineSoundBuffers[8] = {NULL};

IDirect3DTexture9 *g_pRoadTexture[NUM_ROAD_TEXTURES] = {NULL};
IDirect3DTexture9 *g_pCockpit = NULL;
IDirect3DTexture9 *g_pLeftwheel[NUM_WHEEL_TEXTURES] = {NULL};
IDirect3DTexture9 *g_pRightwheel[NUM_WHEEL_TEXTURES] = {NULL};


static long frameGap = DEFAULT_FRAME_GAP;
Expand Down Expand Up @@ -551,6 +555,8 @@ HRESULT CALLBACK OnResetDevice( IDirect3DDevice9 *pd3dDevice,
return E_FAIL;
if (CreateCarVertexBuffer(pd3dDevice) != S_OK)
return E_FAIL;
if (CreateCockpitVertexBuffer(pd3dDevice) != S_OK)
return E_FAIL;

// Load road textures
/*
Expand Down Expand Up @@ -579,6 +585,8 @@ HRESULT CALLBACK OnResetDevice( IDirect3DDevice9 *pd3dDevice,
return E_FAIL;
if ( FAILED( D3DXCreateTextureFromResource( pd3dDevice, NULL, L"RoadWhite", &g_pRoadTexture[5] ) ) )
return E_FAIL;
if ( FAILED( D3DXCreateTextureFromResource( pd3dDevice, NULL, L"Cockpit", &g_pCockpit ) ) )
return E_FAIL;

// Set the projection transform (view and world are updated per frame)
D3DXMATRIX matProj;
Expand Down Expand Up @@ -617,12 +625,14 @@ void CreateFonts()
void LoadTextures()
{
for (int i=0; i<6; i++) if (!g_pRoadTexture[i]) g_pRoadTexture[i] = new IDirect3DTexture9();
if (!g_pCockpit) g_pCockpit = new IDirect3DTexture9();
g_pRoadTexture[0]->LoadTexture("RoadYellowDark");
g_pRoadTexture[1]->LoadTexture("RoadYellowLight");
g_pRoadTexture[2]->LoadTexture("RoadRedDark");
g_pRoadTexture[3]->LoadTexture("RoadRedLight");
g_pRoadTexture[4]->LoadTexture("RoadBlack");
g_pRoadTexture[5]->LoadTexture("RoadWhite");
g_pCockpit->LoadTexture("Cockpit");
printf("Texture loaded\n");
}
void CreateBuffers(IDirect3DDevice9 *pd3dDevice)
Expand All @@ -635,6 +645,8 @@ void CreateBuffers(IDirect3DDevice9 *pd3dDevice)
printf("Error creating ShadowVertexBuffer\n");
if (CreateCarVertexBuffer(pd3dDevice) != S_OK)
printf("Error creating CarVertexBuffer\n");
if (CreateCockpitVertexBuffer(pd3dDevice) != S_OK)
printf("Error creating CarVertexBuffer\n");

}
#endif //!linux
Expand Down Expand Up @@ -1477,6 +1489,11 @@ HRESULT hr;
pd3dDevice->SetTransform( D3DTS_WORLD, &matWorldCar );
DrawCar(pd3dDevice);
}
else
{
// draw cockpit...
DrawCockpit(pd3dDevice);
}
break;
}

Expand Down Expand Up @@ -1667,10 +1684,12 @@ void CALLBACK OnLostDevice( void *pUserContext )
FreeTrackVertexBuffer();
FreeShadowVertexBuffer();
FreeCarVertexBuffer();
FreeCockpitVertexBuffer();

// Free textures
for (long i = 0; i < NUM_ROAD_TEXTURES; i++)
if (g_pRoadTexture[i]) g_pRoadTexture[i]->Release(), g_pRoadTexture[i] = NULL;
if (g_pCockpit) g_pCockpit->Release(), g_pCockpit[i] = NULL;
}


Expand All @@ -1688,6 +1707,7 @@ void CALLBACK OnDestroyDevice( void *pUserContext )
FreeTrackVertexBuffer();
FreeShadowVertexBuffer();
FreeCarVertexBuffer();
FreeCockpitVertexBuffer();
}


Expand Down
7 changes: 7 additions & 0 deletions StuntCarRacer.rc
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ RoadRedDark BITMAP "Bitmap\\RoadRedDark.bmp"
RoadRedLight BITMAP "Bitmap\\RoadRedLight.bmp"
RoadBlack BITMAP "Bitmap\\RoadBlack.bmp"
RoadWhite BITMAP "Bitmap\\RoadWhite.bmp"
Cockpit BITMAP "Bitmap\\cockpit.png"
LeftWheel1 BITMAP "Bitmap\\leftwheel1.png"
LeftWheel2 BITMAP "Bitmap\\leftwheel2.png"
LeftWheel3 BITMAP "Bitmap\\leftwheel3.png"
RightWheel1 BITMAP "Bitmap\\rightwheel1.png"
RightWheel2 BITMAP "Bitmap\\rightwheel2.png"
RightWheel3 BITMAP "Bitmap\\rightwheel3.png"
#endif // English (U.K.) resources
/////////////////////////////////////////////////////////////////////////////

Expand Down
17 changes: 15 additions & 2 deletions dx_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@

const char* BitMapRessourceName(const char* name)
{
static const char* resname[] = {"RoadYellowDark", "RoadYellowLight", "RoadRedDark", "RoadRedLight", "RoadBlack", "RoadWhite", 0};
static const char* filename[] = {"Bitmap/RoadYellowDark.bmp", "Bitmap/RoadYellowLight.bmp", "Bitmap/RoadRedDark.bmp", "Bitmap/RoadRedLight.bmp", "Bitmap/RoadBlack.bmp", "Bitmap/RoadWhite.bmp", 0};
static const char* resname[] = {
"RoadYellowDark", "RoadYellowLight", "RoadRedDark",
"RoadRedLight", "RoadBlack", "RoadWhite",
"Cockpit", "LeftWheel1", "LeftWheel2", "LeftWheel3",
"RightWheel1", "RightWheel2", "RightWheel3",
0};
static const char* filename[] = {
"Bitmap/RoadYellowDark.bmp", "Bitmap/RoadYellowLight.bmp", "Bitmap/RoadRedDark.bmp",
"Bitmap/RoadRedLight.bmp", "Bitmap/RoadBlack.bmp", "Bitmap/RoadWhite.bmp",
"Bitmap/cockpit.png", "Bitmap/leftwheel1.png", "Bitmap/leftwheel2.png", "Bitmap/leftwheel3.png",
"Bitmap/rightwheel1.png", "Bitmap/rightwheel2.png", "Bitmap/rightwheel3.png",
0};

int i = 0;
while(resname[i] && strcmp(resname[i], name)) i++;
return filename[i];
Expand Down Expand Up @@ -631,9 +642,11 @@ HRESULT IDirect3DDevice9::DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType,UINT Star
if (colorop[0] <= D3DTOP_DISABLE) {
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_BLEND);
} else {
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_BLEND);
}
} else {
glDisable(GL_TEXTURE_2D);
Expand Down
2 changes: 1 addition & 1 deletion dx_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ typedef struct D3DRECT {

#define D3DUSAGE_WRITEONLY 1

#define D3DFVF_DIFFUSE (1<<0)
#define D3DFVF_DIFFUSE (1 )
#define D3DFVF_NORMAL (1<<1)
#define D3DFVF_XYZ (1<<2)
#define D3DFVF_XYZRHW (1<<3)
Expand Down

0 comments on commit c2c49ae

Please sign in to comment.