0001:
0002:
0003:
0004:
0005:
0006:
0007:
0008:
0009: #define STRICT
0010:
0011: #include <windows.h>
0012: #include "main.h"
0013: #include "draw.h"
0014:
0015: #include "Cg/cgD3D.h"
0016:
0017:
0018: cgDirect3D cg;
0019: cgContextContainer * pContextContainer = 0;
0020:
0021: cgProgramContainer *pVertexProgramContainer = 0;
0022: cgBindIter * vertex_mat_iter = 0;
0023:
0024: cgProgramContainer *pPixelProgramContainer = 0;
0025: cgBindIter * tex0_iter = 0;
0026:
0027:
0028:
0029:
0030:
0031:
0032:
0033:
0034: void InitBg(LPDIRECT3DDEVICE8 lpD3DDev);
0035: void DrawBg(LPDIRECT3DDEVICE8 lpD3DDev, D3DXMATRIX &mVP);
0036: void CleanBg(LPDIRECT3DDEVICE8 lpD3DDev);
0037:
0038:
0039:
0040:
0041:
0042:
0043: HRESULT InitRender(LPDIRECT3DDEVICE8 lpD3DDev)
0044: {
0045:
0046: InitBg(lpD3DDev);
0047:
0048:
0049: cg.AddFilePath("..");
0050: pContextContainer = cg.CreateContextContainer(lpD3DDev);
0051:
0052:
0053:
0054:
0055: cgVertexAttribute vertex_attributes[] = {
0056: {4, "position", 0},
0057: {2, "texcoord0", 0},
0058: {0, 0, 0}
0059: };
0060:
0061: pVertexProgramContainer = pContextContainer->LoadCGProgramFromFile(
0062: "vs.cg", "Vertex Shader", cgDX8VertexProfile, vertex_attributes);
0063:
0064: if (pVertexProgramContainer == NULL) {
0065:
0066: const char * listing = pContextContainer->GetLastListing();
0067: if (listing == 0) listing = "Could not find cgc.exe.";
0068: cg.NotePad("頂点シェーダープログラムの生成に失敗しました\n\n", listing);
0069:
0070: exit(1);
0071: }
0072:
0073: vertex_mat_iter = pVertexProgramContainer->GetParameterBindByName("worldviewproj_matrix");
0074:
0075:
0076:
0077:
0078:
0079:
0080:
0081:
0082:
0083:
0084:
0085:
0086:
0087: pPixelProgramContainer = pContextContainer->LoadCGProgramFromFile(
0088: "ps.cg", "test", cgDX8PixelProfile);
0089:
0090: if (NULL == pPixelProgramContainer) {
0091:
0092: const char * error_text = pContextContainer->GetLastListing();
0093: cg.NotePad("ピクセルシェーダープログラムの生成に失敗しました\n\n\n", error_text);
0094:
0095: exit(1);
0096: }
0097:
0098:
0099:
0100:
0101:
0102: tex0_iter = pPixelProgramContainer->GetTextureBindByName("tex0");
0103: int t0 = pPixelProgramContainer->GetTexturePosition(tex0_iter);
0104:
0105:
0106:
0107: lpD3DDev->SetRenderState( D3DRS_ZENABLE, TRUE );
0108: lpD3DDev->SetRenderState( D3DRS_LIGHTING, FALSE );
0109: lpD3DDev->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE);
0110:
0111: return S_OK;
0112: }
0113:
0114:
0115:
0116:
0117:
0118: VOID Render(LPDIRECT3DDEVICE8 lpD3DDev)
0119: {
0120: D3DXMATRIX mWorld, mView, mProj, m;
0121:
0122:
0123: D3DXVECTOR3 eye = D3DXVECTOR3(0.0f, 2.0f, 4.0f);
0124: D3DXVECTOR3 lookAt = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
0125: D3DXVECTOR3 up = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
0126:
0127: D3DXMatrixLookAtLH(&mView, &eye, &lookAt, &up);
0128: D3DXMatrixPerspectiveFovLH(&mProj
0129: ,60.0f*PI/180.0f
0130: ,(float)WIDTH/(float)HEIGHT
0131: ,0.01f,100.0f
0132: );
0133: D3DXMATRIX mat = mView * mProj;
0134:
0135:
0136:
0137:
0138:
0139:
0140: pVertexProgramContainer->SetShaderActive();
0141: pPixelProgramContainer->SetShaderActive();
0142:
0143: DrawBg(lpD3DDev, mat);
0144: }
0145:
0146:
0147:
0148:
0149: void CleanRender(LPDIRECT3DDEVICE8 lpD3DDev)
0150: {
0151: CleanBg(lpD3DDev);
0152: }
0153: