void renderMap() { IwGxLightingOff(); CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL(); pMat->SetModulateMode(CIwMaterial::MODULATE_NONE); pMat->SetTexture(mapTexture); IwGxSetMaterial(pMat); IwGxSetScreenSpaceSlot(-1); float zoom = getMapZoom()->getZoom(); int16 hScrW = (double)IwGxGetScreenWidth()*0.5f; int16 hScrH = (double)IwGxGetScreenHeight()*0.5f; int16 x1 = hScrW - hScrW*zoom; int16 x2 = hScrW + hScrW*zoom; int16 y1 = hScrH - hScrH*zoom; int16 y2 = hScrH + hScrH*zoom; mapVertZoom[0].x = x1, mapVertZoom[0].y = y1; mapVertZoom[1].x = x1, mapVertZoom[1].y = y2; mapVertZoom[2].x = x2, mapVertZoom[2].y = y2; mapVertZoom[3].x = x2, mapVertZoom[3].y = y1; IwGxSetUVStream(mapDefaultUvs); IwGxSetVertStreamScreenSpace(mapVertZoom, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); }
void DrawRect(int x, int y, int width, int height, uint8 r, uint8 g, uint8 b) { int right = x + width; int bottom = y + height; if (x < 0) x = 0; if (y < 0) y = 0; if (right > (int32)s3eSurfaceGetInt(S3E_SURFACE_WIDTH)) right = s3eSurfaceGetInt(S3E_SURFACE_WIDTH); if (bottom > (int32)s3eSurfaceGetInt(S3E_SURFACE_HEIGHT)) bottom = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT); // Draw the text IwGxSetScreenSpaceSlot(0); CIwMaterial *fadeMat = IW_GX_ALLOC_MATERIAL(); fadeMat->SetAlphaMode(CIwMaterial::NONE); fadeMat->SetShadeMode(CIwMaterial::SHADE_FLAT); IwGxSetMaterial(fadeMat); CIwColour* cols = IW_GX_ALLOC(CIwColour, 4); for (int i = 0; i < 4; i++) cols[i].Set(r, g, b); CIwSVec2 xy(x, y); CIwSVec2 wh(width, height); IwGxDrawRectScreenSpace(&xy, &wh, cols); }
void myIwGxDoneStars() { IwGxSetScreenSpaceSlot(3); IwGxSetVertStreamScreenSpace( svertices, ssend_vertices ); CIwMaterial *pMat = IW_GX_ALLOC_MATERIAL(); pMat->SetAlphaMode( CIwMaterial::ALPHA_ADD ); pMat->SetTexture( star_texture ); pMat->SetColAmbient( 0xFF, 0xFF, 0xFF, 0xFF ); IwGxSetMaterial( pMat ); IwGxSetUVStream( suvdata ); IwGxSetColStream( scolors, ssend_vertices ); IwGxDrawPrims( IW_GX_QUAD_LIST, NULL, ssend_vertices ); IwGxFlush(); }
void Unit::displayOnScreen(int x, int y){ CIwMaterial *mat = new CIwMaterial(); mat->SetTexture((CIwTexture*)game->getSprites()->GetResHashed(getTextureName(), IW_GX_RESTYPE_TEXTURE)); mat->SetModulateMode(CIwMaterial::MODULATE_NONE); mat->SetAlphaMode(CIwMaterial::ALPHA_DEFAULT); IwGxSetMaterial(mat); CIwSVec2 xy(x-45, y-45); CIwSVec2 duv(IW_FIXED(1.0/numFrames), IW_GEOM_ONE); static CIwSVec2 wh(90, 90); static CIwSVec2 uv(IW_FIXED(0), IW_FIXED(0)); IwGxSetScreenSpaceSlot(1); IwGxDrawRectScreenSpace(&xy, &wh, &uv, &duv); delete mat; }
void renderCamera() { IwGxLightingOff(); // Refresh dynamic texture if (g_CameraTexture != NULL) g_CameraTexture->ChangeTexels((uint8*)g_pCameraTexelsRGB565, CIwImage::RGB_565); CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL(); pMat->SetModulateMode(CIwMaterial::MODULATE_NONE); pMat->SetTexture(g_CameraTexture); IwGxSetMaterial(pMat); IwGxSetScreenSpaceSlot(-1); IwGxSetUVStream(cameraUvs); IwGxSetVertStreamScreenSpace(cameraVert, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); }
void renderGhost() { if (!getGameState()->getPlayer()->isReady()) { return; } IwGxLightingOff(); Ghost *ghost = getGameState()->getGhost(); CIwFVec3 ghostPosition(0, 0, ghost->getDistance()); double ghostRotation = rad(ghost->getRotation()); // Place the markers on the edge of the compass radius // rotated to their correct bearing to current location ghostMatrix->SetRotY(rad(ghost->getBearing())); ghostMatrix->SetTrans(ghostMatrix->RotateVec(ghostPosition)); ghostMatrix->PostRotateY(ghostRotation); IwGxSetModelMatrix(ghostMatrix); if (ghost->pollAnimCaptured()) { ghost_Player->PlayAnim(ghost_Anims[GHOST_ANIM_CAPTURED], 1, 0, BLEND_DURATION); } else if (ghost->pollAnimAgro()) { ghost_Player->PlayAnim(ghost_Anims[GHOST_ANIM_AGRO], 1, 0, BLEND_DURATION); } else if (ghost->pollAnimDodge()) { ghost_Player->PlayAnim(ghost_Anims[GHOST_ANIM_DODGE], 1, 0, BLEND_DURATION); } else if (ghost->pollAnimAttack()) { ghost_Player->PlayAnim(ghost_Anims[GHOST_ANIM_ATTACK], 1, 0, BLEND_DURATION); } IwGxLightingAmbient(true); IwGxSetLightType(0, IW_GX_LIGHT_AMBIENT); int sinceHit = clock() - ghost->getHitTime(); CIwColour colAmbient; if (sinceHit < GHOST_HIT_LENGTH) { int halfAnimation = GHOST_HIT_LENGTH/2; float animState = (float) sinceHit / halfAnimation; if (animState > 1) { animState = 2 - animState; } colAmbient.Set(0xff, 0xff*(1-animState), 0xff*(1-animState), 0xff); } else { // The default state that displays the image as it is colAmbient.Set(0xff, 0xff, 0xff, 0xff); } IwGxSetLightCol(0, &colAmbient); IwGxSetScreenSpaceSlot(1); IwAnimSetSkelContext(ghost_Player->GetSkel()); IwAnimSetSkinContext(ghost_Skin); ghost_Model->Render(); //outline the face under the cursor if (clickX > 0 && clickY > 0) { int32 faceID = ghostCollision->GetFaceUnderCursor(clickX, clickY); if (faceID != -1) { getGameState()->getGhost()->tapped(); clickX = clickY = -1; } else { clickX = clickY = -1; } } // Tidier to reset these IwAnimSetSkelContext(NULL); IwAnimSetSkinContext(NULL); if (ghost->isFound() && !ghost->isDead()) { ghostCollision->RenderEctoplasmaBar((float)ghost->getEctoplasm() / GHOST_MAX_ECTOPLASM, ghostRotation); } }
void doMain() { if(s3ePointerGetInt(S3E_POINTER_MULTI_TOUCH_AVAILABLE)){ s3ePointerRegister(S3E_POINTER_TOUCH_EVENT, (s3eCallback)MultiTouchButtonCB, NULL); s3ePointerRegister(S3E_POINTER_TOUCH_MOTION_EVENT, (s3eCallback)MultiTouchMotionCB, NULL); } else { s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, (s3eCallback)SingleTouchButtonCB, NULL); s3ePointerRegister(S3E_POINTER_MOTION_EVENT, (s3eCallback)SingleTouchMotionCB, NULL); } IwGetResManager()->LoadGroup("resource_groups/palate.group"); palateGroup = IwGetResManager()->GetGroupNamed("Palate"); std::vector<int> ui_texture_hashes; uint background_hash = IwHashString("background_clean"); CIwResList* resources = palateGroup->GetListHashed(IwHashString("CIwTexture")); for(CIwManaged** itr = resources->m_Resources.GetBegin(); itr != resources->m_Resources.GetEnd(); ++itr) { if(background_hash != (*itr)->m_Hash) { ui_texture_hashes.push_back((*itr)->m_Hash); } } CIwMaterial* background = new CIwMaterial(); background->SetTexture((CIwTexture*)palateGroup->GetResNamed("background_clean", IW_GX_RESTYPE_TEXTURE)); background->SetModulateMode(CIwMaterial::MODULATE_NONE); background->SetAlphaMode(CIwMaterial::ALPHA_DEFAULT); unit_ui = new CIwMaterial(); unit_ui->SetModulateMode(CIwMaterial::MODULATE_NONE); unit_ui->SetAlphaMode(CIwMaterial::ALPHA_DEFAULT); unit_ui->SetTexture((CIwTexture*)palateGroup->GetResNamed("TAKE2", IW_GX_RESTYPE_TEXTURE)); CIwSVec2 bg_wh(320, 480); CIwSVec2 ui_wh(80, 480); CIwSVec2 ui_offset(240, 0); CIwSVec2 uv(0, 0); CIwSVec2 duv(IW_GEOM_ONE, IW_GEOM_ONE); init(); IwGxLightingOff(); IwGxSetColClear(255, 255, 255, 255); float worldScrollMultiplier = 0.75; if(s3eDeviceGetInt(S3E_DEVICE_OS) == S3E_OS_ID_IPHONE) { worldScrollMultiplier = 0.925; } while (1) { int64 start = s3eTimerGetMs(); s3eDeviceYield(0); s3eKeyboardUpdate(); s3ePointerUpdate(); if ((s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_DOWN) || (s3eKeyboardGetState(s3eKeyAbsBSK) & S3E_KEY_STATE_DOWN) || (s3eDeviceCheckQuitRequest())) { break; } switch(currentState) { case MAIN_MENU: if(s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED) { currentState = IN_GAME; } if(frameCount % FRAMES_PER_UPDATE == 0) { mainMenu->tick(); } mainMenu->render(); break; case IN_GAME: IwGxSetMaterial(background); IwGxSetScreenSpaceSlot(-1); IwGxDrawRectScreenSpace(&CIwSVec2::g_Zero, &bg_wh, &uv, &duv); IwGxSetMaterial(unit_ui); IwGxSetScreenSpaceSlot(1); IwGxDrawRectScreenSpace(&ui_offset, &ui_wh, &uv, &duv); if (worldScrollSpeed > .0005 || worldScrollSpeed < -.0005) { game->rotate(worldScrollSpeed); worldScrollSpeed *= worldScrollMultiplier; } if(frameCount % FRAMES_PER_UPDATE == 0) { game->tick(); } game->render(); if(!renderTouches()) { break; } break; } IwGxFlush(); IwGxSwapBuffers(); // Attempt frame rate while ((s3eTimerGetMs() - start) < MS_PER_FRAME){ int32 yield = (MS_PER_FRAME - (s3eTimerGetMs() - start)); if (yield < 0) { break; } s3eDeviceYield(yield); } frameCount++; IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F); } delete game; delete mainMenu; delete localPlayer; delete opponentPlayer; delete background; delete unit_ui; palateGroup->Finalise(); for(int i = 0; i < MAX_TOUCHES; ++i) if(touches[i].unit) delete touches[i].unit; }
extern "C" void RenderButtons() { ExButtons* pbutton = g_ButtonsHead; if(g_ButtonsHead) { pbutton = g_ButtonsHead; while(pbutton != NULL) { // Check the key and pointer states. pbutton->key_state = s3eKeyboardGetState(pbutton->key); if( s3eKeyboardGetState(pbutton->key) & S3E_KEY_STATE_DOWN ) { if(pbutton->handler) pbutton->handler(); } if (!(s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_UP)) { int pointerx = s3ePointerGetX(); int pointery = s3ePointerGetY(); if (pointerx >= pbutton->x && pointerx <= pbutton->x+pbutton->w && pointery >=pbutton->y && pointery <= pbutton->y+pbutton->h) { if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN) { pbutton->key_state = S3E_KEY_STATE_DOWN; } if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED) { pbutton->key_state = S3E_KEY_STATE_PRESSED; } if(pbutton->handler) pbutton->handler(); } } // Draw the text IwGxSetScreenSpaceSlot(0); if(s3ePointerGetInt(S3E_POINTER_AVAILABLE)) { CIwMaterial *fadeMat = IW_GX_ALLOC_MATERIAL(); fadeMat->SetAlphaMode(CIwMaterial::SUB); IwGxSetMaterial(fadeMat); CIwColour* cols = IW_GX_ALLOC(CIwColour, 4); if(pbutton->key_state == S3E_KEY_STATE_DOWN) memset(cols, 15, sizeof(CIwColour)*4); else memset(cols, 50, sizeof(CIwColour)*4); // Draw button area CIwSVec2 XY(pbutton->x, pbutton->y-2), dXY(pbutton->w, pbutton->h); IwGxDrawRectScreenSpace(&XY, &dXY, cols); } IwGxPrintString(pbutton->x + 2, pbutton->y + ((pbutton->h - 10)/2), pbutton->name, false); pbutton = pbutton->next; } } }
void GhostCollision::RenderEctoplasmaBar(float ectoPercent, double ghostRotation) { CIwFMat ectoMatrix = CIwFMat(); ectoMatrix.CopyRot(*modelMatrix); ectoMatrix.CopyTrans(*modelMatrix); ectoMatrix.PostRotateY(PI-ghostRotation); IwGxSetModelMatrix(&ectoMatrix); IwGxSetScreenSpaceSlot(1); if (ghostW < 0 || ghostX < 0 || ghostY < 0) ResolveLocation(); const int16 w = 180; const int16 border_x1 = ghostX+ghostW/2 - (float)w*ectobarScale; const int16 border_x2 = ghostX+ghostW/2 + (float)w*ectobarScale; const float border_y1 = ghostY+0x20; const float border_y2 = ghostY+0x20 + (float)0x10*ectobarScale; const int16 z = 0x6; { CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL(); pMat->SetModulateMode(CIwMaterial::MODULATE_RGB); pMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND); pMat->SetTexture(borderTexture); int16 x1 = border_x1, x2 = border_x2; float y1 = border_y1, y2 = border_y2; border_Verts[0] = CIwFVec3(x1, y2, -z); border_Verts[1] = CIwFVec3(x2, y2, -z); border_Verts[2] = CIwFVec3(x2, y1, -z); border_Verts[3] = CIwFVec3(x1, y1, -z); border_Verts[4] = CIwFVec3(x1, y2, z); border_Verts[5] = CIwFVec3(x2, y2, z); border_Verts[6] = CIwFVec3(x2, y1, z); border_Verts[7] = CIwFVec3(x1, y1, z); IwGxSetMaterial(pMat); IwGxSetVertStream(border_Verts, 8); //IwGxSetColStream(s_Cols, 8); IwGxSetUVStream(s_UVs); IwGxDrawPrims(IW_GX_QUAD_STRIP, s_QuadStrip, 4); } float start_y1 = border_y1 + fabs((float)(border_y2 - border_y1)*0.200); float start_y2 = start_y1 + fabs((float)(border_y2 - border_y1)*0.720); float startWhScale = (float)((double)startTexture->GetWidth() / startTexture->GetHeight()); int16 startW = (start_y2 - start_y1) * startWhScale; int16 start_x1 = border_x1 + abs((float)(border_x2 - border_x1)*0.0097); int16 start_x2 = start_x1 + startW; { CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL(); pMat->SetModulateMode(CIwMaterial::MODULATE_RGB); pMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND); pMat->SetTexture(startTexture); int16 x1 = start_x1, x2 = start_x2; float y1 = start_y1, y2 = start_y2; start_Verts[0] = CIwFVec3(x1, y2, -z); start_Verts[1] = CIwFVec3(x2, y2, -z); start_Verts[2] = CIwFVec3(x2, y1, -z); start_Verts[3] = CIwFVec3(x1, y1, -z); start_Verts[4] = CIwFVec3(x1, y2, z); start_Verts[5] = CIwFVec3(x2, y2, z); start_Verts[6] = CIwFVec3(x2, y1, z); start_Verts[7] = CIwFVec3(x1, y1, z); IwGxSetMaterial(pMat); IwGxSetVertStream(start_Verts, 8); //IwGxSetColStream(s_Cols, 8); IwGxSetUVStream(s_UVs); IwGxDrawPrims(IW_GX_QUAD_STRIP, s_QuadStrip, 4); } float end_y1 = start_y1; float end_y2 = start_y2; float endWhScale = (float)((double)endTexture->GetWidth() / endTexture->GetHeight()); int16 endW = (end_y2 - end_y1) * endWhScale; int endMaxX = border_x2 - abs((float)(border_x2 - border_x1)*0.0097) - endW; int endMinX = start_x2; int16 end_x1 = (double)(endMaxX - endMinX)*ectoPercent + endMinX; int16 end_x2 = end_x1 + endW; { CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL(); pMat->SetModulateMode(CIwMaterial::MODULATE_RGB); pMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND); pMat->SetTexture(endTexture); int16 x1 = end_x1, x2 = end_x2; float y1 = end_y1, y2 = end_y2; end_Verts[0] = CIwFVec3(x1, y2, -z); end_Verts[1] = CIwFVec3(x2, y2, -z); end_Verts[2] = CIwFVec3(x2, y1, -z); end_Verts[3] = CIwFVec3(x1, y1, -z); end_Verts[4] = CIwFVec3(x1, y2, z); end_Verts[5] = CIwFVec3(x2, y2, z); end_Verts[6] = CIwFVec3(x2, y1, z); end_Verts[7] = CIwFVec3(x1, y1, z); IwGxSetMaterial(pMat); IwGxSetVertStream(end_Verts, 8); //IwGxSetColStream(s_Cols, 8); IwGxSetUVStream(s_UVs); IwGxDrawPrims(IW_GX_QUAD_STRIP, s_QuadStrip, 4); } float center_y1 = start_y1; float center_y2 = start_y2; int16 center_x1 = start_x2 - 1; int16 center_x2 = end_x1 + 1; { CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL(); pMat->SetModulateMode(CIwMaterial::MODULATE_RGB); pMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND); pMat->SetTexture(centerTexture); int16 x1 = center_x1, x2 = center_x2; float y1 = center_y1, y2 = center_y2; center_Verts[0] = CIwFVec3(x1, y2, -z); center_Verts[1] = CIwFVec3(x2, y2, -z); center_Verts[2] = CIwFVec3(x2, y1, -z); center_Verts[3] = CIwFVec3(x1, y1, -z); center_Verts[4] = CIwFVec3(x1, y2, z); center_Verts[5] = CIwFVec3(x2, y2, z); center_Verts[6] = CIwFVec3(x2, y1, z); center_Verts[7] = CIwFVec3(x1, y1, z); IwGxSetMaterial(pMat); IwGxSetVertStream(center_Verts, 8); //IwGxSetColStream(s_Cols, 8); IwGxSetUVStream(s_UVs); IwGxDrawPrims(IW_GX_QUAD_STRIP, s_QuadStrip, 4); } }