void drawPlayer(player_s* p) { if(!p)return; gsPushMatrix(); camera_s* c=&p->camera; gsTranslate(p->object.position.x,p->object.position.y-4.0f,p->object.position.z); float m[9]; vect3Df_s v1 = moveCameraVector(c, vect3Df(1.0f, 0.0f, 0.0f), false); vect3Df_s v2 = moveCameraVector(c, vect3Df(0.0f, 0.0f, 1.0f), false); m[0]=v1.x;m[3]=v1.y;m[6]=v1.z; m[1]=0.0f;m[4]=1.0f;m[7]=0.0f; m[2]=v2.x;m[5]=v2.y;m[8]=v2.z; gsMultMatrix3(m); gsScale(1.2f,1.2f,1.2f); gsRotateY(M_PI); md2InstanceDraw(&p->ratmanInstance); gsPopMatrix(); }
void drawPlayerGun(player_s* p) { if(!p)return; gsPushMatrix(); useCamera(&p->camera); gsLoadIdentity(); GPU_SetDepthTestAndWriteMask(true, GPU_ALWAYS, GPU_WRITE_DEPTH); gsSwitchRenderMode(-1); GPU_SetAttributeBuffers( 2, // number of attributes (u32*)osConvertVirtToPhys(rectangleBaseAddr), // we use the start of linear heap as base since that's where all our buffers are located GPU_ATTRIBFMT(0, 3, GPU_FLOAT)|GPU_ATTRIBFMT(1, 2, GPU_FLOAT), // we want v0 (vertex position) and v1 (texcoord) 0xFFC, // mask : we want v0 and v1 0x10, // permutation : we use identity 1, // number of buffers : we have one attribute per buffer (u32[]){(u32)rectangleVertexData-rectangleBaseAddr}, // buffer offsets (placeholders) (u64[]){0x10}, // attribute permutations for each buffer (u8[]){2} // number of attributes for each buffer ); gsSetShader(&passthroughProgram); GPU_DrawArray(GPU_TRIANGLES, 6); GPU_SetDepthTestAndWriteMask(true, GPU_ALWAYS, GPU_WRITE_ALL); GPUCMD_AddWrite(GPUREG_ATTRIBBUFFER0_CONFIG0, (u32)crosshairVertexData-rectangleBaseAddr); textureBind(&crosshairTexture, GPU_TEXUNIT0); GPU_DrawArray(GPU_TRIANGLES, 6); GPU_SetDepthTestAndWriteMask(true, GPU_GREATER, GPU_WRITE_ALL); gsSwitchRenderMode(md2GsMode); gsTranslate(1.3, -1.65, -3.1); gsRotateY(p->tempAngle.y); gsRotateX(-p->tempAngle.x); gsRotateX(-0.1); gsRotateZ(M_PI/2); gsRotateY(-M_PI/2); gsRotateX(-M_PI/2); gsScale(3.0f/8, 3.0f/8, 3.0f/8); md2InstanceDraw(&p->gunInstance); gsPopMatrix(); }
void drawEmancipationGrid(emancipationGrid_s* eg) { if(!eg)return; float l=fabs(eg->length); // TODO : animate surface texture gsPushMatrix(); gsSwitchRenderMode(md2GsMode); gsTranslate(eg->position.x, eg->position.y, eg->position.z); if(eg->direction)gsRotateY(-(M_PI/2)); if(eg->length<0)gsRotateY((M_PI/2)*2); md2InstanceDraw(&gridInstance); gsPushMatrix(); gsTranslate(l,0,0); gsRotateY((M_PI/2)*2); md2InstanceDraw(&gridInstance); gsPopMatrix(); gsSwitchRenderMode(-1); GPU_SetAttributeBuffers( 1, // number of attributes (u32*)osConvertVirtToPhys(emancipationBaseAddr), // we use the start of linear heap as base since that's where all our buffers are located GPU_ATTRIBFMT(0, 3, GPU_FLOAT), // we want v0 (vertex position) 0xFFE, // mask : we want v0 0x0, // permutation : we use identity 1, // number of buffers : we have one attribute per buffer (u32[]){(u32)emancipationRectangleVertexData-emancipationBaseAddr}, // buffer offsets (placeholders) (u64[]){0x0}, // attribute permutations for each buffer (u8[]){1} // number of attributes for each buffer ); gsSetShader(&emancipationProgram); gsScale(l, 4.0f, 1.0f); gsUpdateTransformation(); textureBind(&gridSurfaceTexture, GPU_TEXUNIT0); GPU_SetFloatUniform(GPU_VERTEX_SHADER, emancipationUniformTextureDimensions, (u32*)(float[]){0.0f, 0.0f, 0.7f, l/8}, 1);
void drawRoom(room_s* r) { if(!r)return; gsSwitchRenderMode(-1); gsSetShader(&roomProgram); GPU_SetAttributeBuffers( 3, // number of attributes (u32*)osConvertVirtToPhys(roomBaseAddr), // we use the start of linear heap as base since that's where all our buffers are located GPU_ATTRIBFMT(0, 3, GPU_SHORT)|GPU_ATTRIBFMT(1, 2, GPU_SHORT)|GPU_ATTRIBFMT(2, 2, GPU_SHORT), // we want v0, v1 and v2 0xFF8, // mask : we want v0, v1 and v2 0x210, // permutation : we use identity 1, // number of buffers : we have one attribute per buffer (u32[]){(u32)r->vertexBuffer-roomBaseAddr}, // buffer offsets (placeholders) (u64[]){0x210}, // attribute permutations for each buffer (u8[]){3} // number of attributes for each buffer ); GPU_SetTextureEnable(GPU_TEXUNIT0|GPU_TEXUNIT1); GPU_SetTexEnv(0, GPU_TEVSOURCES(GPU_TEXTURE0, GPU_TEXTURE1, GPU_PRIMARY_COLOR), GPU_TEVSOURCES(GPU_TEXTURE0, GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR), GPU_TEVOPERANDS(0,2,0), GPU_TEVOPERANDS(0,0,0), GPU_MODULATE, GPU_MODULATE, 0xFFFFFFFF); gsPushMatrix(); gsScale(TILESIZE_FLOAT*2, HEIGHTUNIT_FLOAT, TILESIZE_FLOAT*2); gsUpdateTransformation(); int i; for(i=0; i<r->numIndexBuffers; i++) { textureBind(r->indexBufferTextures[i], GPU_TEXUNIT0); textureBind(r->lightingData.data.lightMap.texture, GPU_TEXUNIT1); GPU_SetFloatUniform(GPU_VERTEX_SHADER, roomUniformTextureDimensions, (u32*)(float[]){0.0f, 0.0f, 1.0f / r->indexBufferTextures[i]->height, 1.0f / r->indexBufferTextures[i]->width}, 1); GPU_DrawElements(GPU_UNKPRIM, (u32*)((u32)r->indexBuffers[i]-roomBaseAddr), r->numIndices[i]); }
// topscreen void renderMenuFrame(u32* outBuffer, u32* outDepthBuffer) { GPU_SetViewport((u32*)osConvertVirtToPhys((u32)outDepthBuffer),(u32*)osConvertVirtToPhys((u32)outBuffer),0,0,240,400); GPU_DepthMap(-1.0f, 0.0f); GPU_SetFaceCulling(GPU_CULL_FRONT_CCW); GPU_SetStencilTest(false, GPU_ALWAYS, 0x00, 0xFF, 0x00); GPU_SetStencilOp(GPU_STENCIL_KEEP, GPU_STENCIL_KEEP, GPU_STENCIL_KEEP); GPU_SetBlendingColor(0,0,0,0); GPU_SetDepthTestAndWriteMask(true, GPU_GREATER, GPU_WRITE_ALL); GPUCMD_AddMaskedWrite(GPUREG_0062, 0x1, 0); GPUCMD_AddWrite(GPUREG_0118, 0); GPU_SetAlphaBlending(GPU_BLEND_ADD, GPU_BLEND_ADD, GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA); GPU_SetAlphaTest(false, GPU_ALWAYS, 0x00); GPU_SetTextureEnable(GPU_TEXUNIT0); GPU_SetTexEnv(0, GPU_TEVSOURCES(GPU_TEXTURE0, GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR), GPU_TEVSOURCES(GPU_TEXTURE0, GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR), GPU_TEVOPERANDS(0,0,0), GPU_TEVOPERANDS(0,0,0), GPU_MODULATE, GPU_MODULATE, 0xFFFFFFFF); GPU_SetDummyTexEnv(1); GPU_SetDummyTexEnv(2); GPU_SetDummyTexEnv(3); GPU_SetDummyTexEnv(4); GPU_SetDummyTexEnv(5); gsMatrixMode(GS_MODELVIEW); gsPushMatrix(); gsLoadIdentity(); useCamera(&menuCamera); gsSwitchRenderMode(md2GsMode); md2InstanceDraw(&gladosInstance); md2InstanceDraw(&gladosLairInstance); gsPopMatrix(); GPU_SetDepthTestAndWriteMask(true, GPU_ALWAYS, GPU_WRITE_ALL); if(currentCameraState==2) { gsPushMatrix(); gsSwitchRenderMode(-1); GPU_SetAttributeBuffers( 1, // number of attributes (u32*)osConvertVirtToPhys(logoBaseAddr), // we use the start of linear heap as base since that's where all our buffers are located GPU_ATTRIBFMT(0, 3, GPU_FLOAT), // we want v0 (vertex position) 0xFFE, // mask : we want v0 0x0, // permutation : we use identity 1, // number of buffers : we have one attribute per buffer (u32[]){(u32)logoRectangleVertexData-logoBaseAddr}, // buffer offsets (placeholders) (u64[]){0x0}, // attribute permutations for each buffer (u8[]){1} // number of attributes for each buffer ); gsSetShader(&logoProgram); gsMatrixMode(GS_MODELVIEW); gsLoadIdentity(); gsPushMatrix(); gsTranslate(0.15f, 0.325f, 0.0f); gsScale(64.0f * 2.0f / 240.0f, 64.0f * 2.0f / 400.0f, 1.0f); gsTranslate(0.5f, 0.5f, 0.0f); gsRotateZ(logoangle+=0.01f); gsTranslate(-0.5f, -0.5f, 0.0f); gsUpdateTransformation(); textureBind(&rotateLogoTexture, GPU_TEXUNIT0); GPU_SetFloatUniform(GPU_VERTEX_SHADER, logoUniformTextureDimensions, (u32*)(float[]){0.0f, 0.0f, 1.0f, 1.0f}, 1);