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]); }
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);
// 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);
static TEXTURE mapGenerateMapTexture (const hexPos centre, unsigned char span, float facing, const char * dataVal) { TEXTURE texture; VECTOR3 mapCoords, rot; SUBHEX centreLevel = hexPos_platter (centre, span), hex; VECTOR3 borders[4]; int l = 0, final, x, y, texWidth = 512, texHeight = 512, * scale; signed int data = 0, max = 0, min = 0, range = 0; unsigned char mapSpan, color[4] = {0xff, 0xff, 0xff, 0xff}; textureSetBackgroundColor (0x00, 0x00, 0x00, 0x00); texture = textureGenBlank (texWidth, texHeight, 4); borders[0] = vectorCreate (0, 0, 0); borders[1] = vectorCreate (texWidth - 1, 0, 0); borders[2] = vectorCreate (texWidth - 1, texHeight - 1, 0); borders[3] = vectorCreate (0, texHeight - 1, 0); if (centreLevel == NULL) { ERROR ("Can't construct map texture for span level %d", span); return NULL; } //printf ("have base %p @ span %d\n", centreLevel, subhexSpanLevel (centreLevel)); mapSpan = mapGetSpan (); if (span == mapSpan) { unsigned int r, k, i, tri; unsigned char pole; hex_xy2rki (centre->x[mapSpan], centre->y[mapSpan], &r, &k, &i); if (i < r / 2.0) tri = (k + 5) % 6; else tri = (k + 1) % 6; // TODO: draw one pole in the XY[k]-th direction and one in the XY[tri]-th direction. the issue is figuring out which pole is which pole = subhexPoleName (centre->platter[mapSpan]); switch (pole) { case 'r': textureSetColor (0xff, 0x00, 0x00, 0xff); break; case 'g': textureSetColor (0x00, 0xff, 0x00, 0xff); break; case 'b': textureSetColor (0x00, 0x00, 0xff, 0xff); break; default: textureSetColor (0xff, 0x00, 0xff, 0xff); break; } mapCoords = vectorCreate (0, 0, 0); textureDrawHex (texture, vectorCreate ((texWidth / 2.0) + mapCoords.x, (texHeight / 2.0) + mapCoords.z, 0.0), 32, -facing); textureSetColor (0x00, 0x00, 0x00, 0xff); textureDrawLine (texture, borders[0], borders[1]); textureDrawLine (texture, borders[1], borders[2]); textureDrawLine (texture, borders[2], borders[3]); textureDrawLine (texture, borders[3], borders[0]); textureBind (texture); return texture; } final = fx (24);