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 CRenderer::DrawBatch() { if ( GetVBSize() > 0 ) { IwGxLightingOff(); IwGxSetMaterial( mCurrMtl ); IwGxSetUVStream( mUVB ); IwGxSetColStream(mCB, mCBSize); IwGxSetVertStreamScreenSpaceSubPixel( mVB, mVBSize ); if ( mIBSize == 0 ) { IwGxDrawPrims(mBuffType, NULL, mVBSize); } else { IwGxDrawPrims(mBuffType, mIB, mIBSize); } mCurrMtl = NULL; //DefaultMaterial(); IwGxFlush(); IwGxSetColStream(NULL); //IwGxSetUVStream( NULL ); ResetBuffers(); } }
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) void ImGui_Marmalade_RenderDrawLists(ImDrawData* draw_data) { // Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays) ImGuiIO& io = ImGui::GetIO(); draw_data->ScaleClipRects(io.DisplayFramebufferScale); // Render command lists for(int n = 0; n < draw_data->CmdListsCount; n++) { const ImDrawList* cmd_list = draw_data->CmdLists[n]; const unsigned char* vtx_buffer = (const unsigned char*)&cmd_list->VtxBuffer.front(); const ImDrawIdx* idx_buffer = &cmd_list->IdxBuffer.front(); int nVert = cmd_list->VtxBuffer.size(); CIwFVec2* pVertStream = IW_GX_ALLOC(CIwFVec2, nVert); CIwFVec2* pUVStream = IW_GX_ALLOC(CIwFVec2, nVert); CIwColour* pColStream = IW_GX_ALLOC(CIwColour, nVert); for( int i=0; i < nVert; i++ ) { // TODO: optimize multiplication on gpu using vertex shader pVertStream[i].x = cmd_list->VtxBuffer[i].pos.x * g_scale.x; pVertStream[i].y = cmd_list->VtxBuffer[i].pos.y * g_scale.y; pUVStream[i].x = cmd_list->VtxBuffer[i].uv.x; pUVStream[i].y = cmd_list->VtxBuffer[i].uv.y; pColStream[i] = cmd_list->VtxBuffer[i].col; } IwGxSetVertStreamScreenSpace(pVertStream, nVert); IwGxSetUVStream(pUVStream); IwGxSetColStream(pColStream, nVert); IwGxSetNormStream(0); for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.size(); cmd_i++) { const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; if (pcmd->UserCallback) { pcmd->UserCallback(cmd_list,pcmd); } else { CIwMaterial* pCurrentMaterial = IW_GX_ALLOC_MATERIAL(); pCurrentMaterial->SetShadeMode(CIwMaterial::SHADE_FLAT); pCurrentMaterial->SetCullMode(CIwMaterial::CULL_NONE); pCurrentMaterial->SetFiltering(false); pCurrentMaterial->SetAlphaMode(CIwMaterial::ALPHA_BLEND); pCurrentMaterial->SetDepthWriteMode(CIwMaterial::DEPTH_WRITE_NORMAL); pCurrentMaterial->SetAlphaTestMode(CIwMaterial::ALPHATEST_DISABLED); pCurrentMaterial->SetTexture((CIwTexture*)pcmd->TextureId); IwGxSetMaterial(pCurrentMaterial); IwGxDrawPrims(IW_GX_TRI_LIST, (uint16*)idx_buffer, pcmd->ElemCount); } idx_buffer += pcmd->ElemCount; } IwGxFlush(); } // TODO: restore modified state (i.e. mvp matrix) }
void CRenderer::DefaultMaterial() { CIwMaterial * currMat = IwGxGetMaterial(); if (currMat == NULL || currMat != mDefaultMaterial) { IwGxSetMaterial(mDefaultMaterial); } }
void CzPlatformRender::DrawPrimitives(CzRenderPrim3* prims, CzRenderMaterial* materials, int num_prims, bool single_material) { while (num_prims-- > 0) { CIwMaterial::AlphaMode am = (CIwMaterial::AlphaMode)materials->AlphaMode; // TODO Add proper method to map Marmalade Alpha mode to Marmalade int vc = prims->VertCount; // Set up vertex streams if (prims->UVs != NULL) IwGxSetUVStream((CIwFVec2*)prims->UVs, 0); else IwGxSetUVStream(NULL); if (prims->ModelSpace) IwGxSetVertStreamModelSpace((CIwFVec3*)prims->Verts, vc); else IwGxSetVertStreamViewSpace((CIwFVec3*)prims->Verts, vc); IwGxSetColStream((CIwColour*)prims->Colours); IwGxSetNormStream((CIwFVec3*)prims->Normals); CzTexture texture = materials->Image->getTexture(); CIwTexture* mt = static_cast<CIwTexture*>(texture); bool filter; if (materials->Image->isFilterSet()) filter = mt->GetFiltering(); else filter = materials->Filter; // Only create new render material if something important has changed if (texture != CurrentTexture || CurrentAlphaMode != materials->AlphaMode || CurrentFilter != filter || CurrentTexture == NULL || CurrentTiled != materials->Tiled) { CIwMaterial* mat = IW_GX_ALLOC_MATERIAL(); mat->SetTexture(mt); mat->SetDepthWriteMode(CIwMaterial::DEPTH_WRITE_DISABLED); mat->SetClamping(!materials->Tiled); mat->SetFiltering(filter); mat->SetAlphaMode(am); mat->SetCullMode(CIwMaterial::CULL_BACK); // mat->SetCullMode(CIwMaterial::CULL_NONE); IwGxSetMaterial(mat); CurrentTexture = texture; CurrentAlphaMode = materials->AlphaMode; CurrentTiled = materials->Tiled; CurrentFilter = filter; } else { RedundantTextureCalls++; } // Render the primitive IwGxDrawPrims(CzToIwGxPrimType[prims->Type], prims->Indices, prims->IndicesCount); // Move to next primitive prims++; if (!single_material) materials++; } }
void CEndGameState::Render() { IW_CALLSTACK("CEndGameState::Render"); IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F); GetWorld().Render(); IwGxLightingOff(); IwGxSetScreenSpaceOrg( &CIwSVec2::g_Zero ); CIwColour* cols = IW_GX_ALLOC(CIwColour, 4); memset(cols, 255, sizeof(CIwColour) * 4 ); if (GetWorld().GetUICar()->GetPosition() == 1 ) { CIwMaterial* mat = (CIwMaterial *)IwGetResManager()->GetGroupNamed("ui")->GetResNamed("youwin", IW_GX_RESTYPE_MATERIAL); IwGxSetMaterial(mat); } else { CIwMaterial* mat = (CIwMaterial *)IwGetResManager()->GetGroupNamed("ui")->GetResNamed("youlose", IW_GX_RESTYPE_MATERIAL); IwGxSetMaterial(mat); } const uint32 imageWidth = 128; const uint32 imageHeight = 32; CIwSVec2 XY( (int16)((IwGxGetScreenWidth()/2) - (imageWidth/2)), (int16)(IwGxGetScreenHeight()/4) ), dXY( (int16)imageWidth, (int16)imageHeight ); IwGxDrawRectScreenSpace(&XY, &dXY, cols); IwGxLightingOn(); IwGxFlush(); IwGxSwapBuffers(); #ifdef IW_DEBUG // Reset metrics for next frame IwGxMetricsReset(); #endif }
static void SoftkeyRender(const char* text, s3eDeviceSoftKeyPosition pos, void(*handler)()) { // TODO: Hardocoded font width and height (boo!) int width = 7; int height = 30; width *= strlen(text) * 2; int x = 0; int y = 0; switch (pos) { case S3E_DEVICE_SOFTKEY_BOTTOM_LEFT: y = IwGxGetScreenHeight() - height; x = 0; break; case S3E_DEVICE_SOFTKEY_BOTTOM_RIGHT: y = IwGxGetScreenHeight() - height; x = IwGxGetScreenWidth() - width; break; case S3E_DEVICE_SOFTKEY_TOP_RIGHT: y = 0; x = IwGxGetScreenWidth() - width; break; case S3E_DEVICE_SOFTKEY_TOP_LEFT: x = 0; y = 0; break; } CIwMaterial *fadeMat = IW_GX_ALLOC_MATERIAL(); fadeMat->SetAlphaMode(CIwMaterial::SUB); IwGxSetMaterial(fadeMat); IwGxPrintString(x + 10, y+10, text, false); CIwColour* cols = IW_GX_ALLOC(CIwColour, 4); memset(cols, 50, sizeof(CIwColour)*4); if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED) { int pointerx = s3ePointerGetX(); int pointery = s3ePointerGetY(); if (pointerx >= x && pointerx <= x+width && pointery >=y && pointery <= y+height) { memset(cols, 15, sizeof(CIwColour)*4); handler(); } } // Draw button area CIwSVec2 XY(x, y-2), dXY(width, height); IwGxDrawRectScreenSpace(&XY, &dXY, cols); }
void CRenderer::DrawDirect( IwGxPrimType type, CIwSVec2 * vertex, CIwSVec2 * uv, uint16* indexStream, CIwColour * colour, int32 vertexCount, CIwMaterial * mat ) { IwGxLightingOff(); IwGxSetMaterial( mat ); IwGxSetUVStream( uv ); IwGxSetColStream(colour, vertexCount); IwGxSetVertStreamScreenSpaceSubPixel( vertex, vertexCount ); IwGxDrawPrims(type, indexStream, vertexCount); IwGxFlush(); IwGxSetColStream(NULL); }
void ResourceManager::paint(const char* res, int x, int y, int w, int h, int* lm, int* tm, int* rm, int* bm) { int width, height; if (res == NULL) return; CIwMaterial* t = load(res, &width, &height); if (t == NULL) return; if (vertC + 4 >= MAX_VERTS) return; if (width != 0) { if (lm != 0) { *lm = (*lm * w) / width; x -= *lm; w += *lm; } if (rm != 0) { *rm = (*rm * w) / width; w += *rm; } } if (height != 0) { if (tm != 0) { *tm = (*tm * h) / height; y -= *tm; h += *tm; } if (bm != NULL) { *bm = (*bm * h) / height; h += *bm; } } int offset = vertC; xy3[vertC].x = x, xy3[vertC].y = y; vertC++; xy3[vertC].x = x, xy3[vertC].y = y + h; vertC++; xy3[vertC].x = x + w, xy3[vertC].y = y + h; vertC++; xy3[vertC].x = x + w, xy3[vertC].y = y; vertC++; IwGxSetVertStreamScreenSpace(xy3 + offset, 4); IwGxSetMaterial(t); static CIwFVec2 uvs[4] = { CIwFVec2(0, 0), CIwFVec2(0, 1), CIwFVec2(1, 1), CIwFVec2(1, 0), }; /* static CIwSVec2 uvs[4] = { CIwSVec2(0, 0), CIwSVec2(0, IW_GEOM_ONE), CIwSVec2(IW_GEOM_ONE, IW_GEOM_ONE), CIwSVec2(IW_GEOM_ONE, 0), };*/ IwGxSetUVStream(uvs); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); }
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 Block::draw(int16 x, int16 y, int16 w, int16 h) { if (!enabled) return; xy4[0].x = x, xy4[0].y = y; xy4[1].x = x, xy4[1].y = y+h; xy4[2].x = x+w, xy4[2].y = y+h; xy4[3].x = x+w, xy4[3].y = y; IwGxSetVertStreamScreenSpace(xy4, 4); IwGxSetMaterial(IW_GX_ALLOC_MATERIAL()); IwGxSetColStream(color, 4); // Draw single triangle IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); }
void ExampleRender() { //IW_PROFILE_NEWFRAME(); CIwProfileIteratorDerived pProfileIterator(CIwProfileManager::Get().GetRoot()); pProfileIterator.First(); int iy = 30; while (!pProfileIterator.IsDone()) { PrintfProperty(10, iy, pProfileIterator.GetCurrentName(), pProfileIterator.GetCurrentLastTime()); pProfileIterator.Next(); iy += 10; } PrintfProperty(10, 90, "points: ", (float)m_pAnimator->GetCurrentSpline()->GetPointCount()); IW_PROFILE_START("render"); CIwMaterial* pMat; // Clear the screen IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F); //// Allocate and initialise material from the IwGx global cache pMat = IW_GX_ALLOC_MATERIAL(); //// Set this as the active material IwGxSetMaterial(pMat); m_pSplinePoly2Tri->Render(); //IwGxSetColStream(s_Cols, 8); m_pBall->Render(); IwGxSetColStream(NULL); // End drawing IwGxFlush(); IW_PROFILE_STOP(); // Swap buffers IwGxSwapBuffers(); }
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 CursorRender() { if (!s3ePointerGetInt(S3E_POINTER_AVAILABLE)) return; if (!g_CursorMaterial) { g_CursorMaterial = new CIwMaterial(); g_CursorMaterial->SetColAmbient(0, 0, 255, 255); } IwGxSetMaterial(g_CursorMaterial); int pointerx = s3ePointerGetX(); int pointery = s3ePointerGetY(); int cursor_size = 10; CIwSVec2 wh(cursor_size*2, 1); CIwSVec2 wh2(1, cursor_size*2); CIwSVec2 pos = CIwSVec2((int16)pointerx-cursor_size, (int16)pointery); CIwSVec2 pos2 = CIwSVec2((int16)pointerx, (int16)pointery-cursor_size); IwGxDrawRectScreenSpace(&pos, &wh); IwGxDrawRectScreenSpace(&pos2, &wh2); }
void Transitions2D::Fade(uint8 transitionSpeed, bool skipFirstAndLastFrame) { IwGxSetColClear(0, 0, 0, 0); if (mStartTexture == NULL || mEndTexture == NULL) return; if (transitionSpeed == 0) transitionSpeed = 1; IwGxScreenOrient orient = IwGxGetScreenOrient(); if (isUsingPrivateTextures) IwGxSetScreenOrient(IW_GX_ORIENT_NONE); int alpha = 0; if (skipFirstAndLastFrame) alpha += transitionSpeed; CIwMaterial* startMat; CIwMaterial* endMat; while (alpha <= 255) { IwGxClear(); startMat = IW_GX_ALLOC_MATERIAL(); startMat->SetTexture(mStartTexture); IwGxSetMaterial(startMat); IwGxDrawRectScreenSpace(&CIwSVec2(0, 0), &CIwSVec2(mStartTexture->GetWidth(), mStartTexture->GetHeight())); endMat = IW_GX_ALLOC_MATERIAL(); endMat->SetTexture(mEndTexture); endMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND); endMat->SetColAmbient(255, 255, 255, alpha); IwGxSetMaterial(endMat); IwGxDrawRectScreenSpace(&CIwSVec2(0, 0), &CIwSVec2(mEndTexture->GetWidth(), mEndTexture->GetHeight())); IwGxFlush(); IwGxSwapBuffers(); s3eDeviceYield(40); alpha += transitionSpeed; } if (!skipFirstAndLastFrame) { IwGxClear(); endMat = IW_GX_ALLOC_MATERIAL(); endMat->SetTexture(mEndTexture); IwGxSetMaterial(endMat); IwGxDrawRectScreenSpace(&CIwSVec2(0, 0), &CIwSVec2(mEndTexture->GetWidth(), mEndTexture->GetHeight())); IwGxFlush(); IwGxSwapBuffers(); } if (isUsingPrivateTextures) { delete mStartTexture; delete mEndTexture; mStartTexture = NULL; mEndTexture = NULL; } IwGxSetScreenOrient(orient); }
void MapBackground::DownloadTiles() { CIwTexture* tx = (CIwTexture*)IwGetResManager()->GetResNamed("logo", IW_GX_RESTYPE_TEXTURE); uint32 w1 = tx->GetWidth(); uint32 h1 = tx->GetHeight(); //static CIwSVec2 uvs[4] = //{ // CIwSVec2(0 << 12, 0 << 12), // CIwSVec2(0 << 12, 1 << 12), // CIwSVec2(1 << 12, 1 << 12), // CIwSVec2(1 << 12, 0 << 12), //}; static CIwSVec2 uvs[4] = { CIwSVec2((0 << 12) + 10, (0 << 12) + 10), CIwSVec2((0 << 12) + 10, (1 << 12) - 10), CIwSVec2((1 << 12) - 10, (1 << 12) - 10), CIwSVec2((1 << 12) - 10, (0 << 12) + 10), }; int w = w1/2; int h = h1/2; int counter = 0; while (true) { IwGetHTTPQueue()->Update(); IwGetNotificationHandler()->Update(); IwGetMultiplayerHandler()->Update(); IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F); CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL(); pMat->SetModulateMode(CIwMaterial::MODULATE_NONE); pMat->SetTexture(tx); IwGxSetMaterial(pMat); CIwMat rotMat; rotMat.SetIdentity(); double perCentAngle = (counter / 80.0); iwangle degAng = (iwangle)(IW_GEOM_ONE * perCentAngle); rotMat.SetRotZ(degAng); rotMat.t.z = -0x200; IwGxSetViewMatrix(&rotMat); CIwSVec3* pWSCoords= IW_GX_ALLOC(CIwSVec3, 4); pWSCoords[0].x = -w; pWSCoords[0].y = -h; pWSCoords[1].x = -w; pWSCoords[1].y = h; pWSCoords[2].x = w; pWSCoords[2].y = h; pWSCoords[3].x = w; pWSCoords[3].y = -h; pWSCoords[0].z = pWSCoords[1].z = pWSCoords[2].z = pWSCoords[3].z = 0; if (!g_bInProgress) { MapTile* pNextDownload = GetNextDownload(NULL); if (pNextDownload) { IwGetNotificationHandler()->PushNotification((int)this, pNextDownload->szImageUrl, 10*1000); g_bInProgress = true; LoadMapTileImage(pNextDownload); } else { IwGetNotificationHandler()->ClearNotification((int)this); break; } } IwGxSetVertStreamWorldSpace(pWSCoords, 4); IwGxSetUVStream(uvs); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); IwGetNotificationHandler()->Render(); IwGxFlush(); IwGxSwapBuffers(); s3eDeviceYield(50); counter++; } }
void MapBackground::RenderBackgroundOnSurface(CIw2DSurface* pSurface) { std::list<MapTile*>::iterator iter = gVectorImageUrls.begin(); // Set up a view matrix to rotate what we are viewing about the z-axis // This normalizes the center of the screen to (0,0), so we need to offset // our coordinates. // We also need to scale in our X and Y directions. CIwColour colClear; colClear = IwGxGetColClear(); if (g_dAlpha < 0xFF) { IwGxSetColClear(0, 0, 0, 0); } CIwColour* cols = IW_GX_ALLOC(CIwColour, 4); for (int i = 0; i < 4; ++i) { cols[i].r = cols[i].g = cols[i].b = 0xff; cols[i].a = (uint8)g_dAlpha; } //static CIwSVec2 uvs[4] = //{ // CIwSVec2(0 << 12, 0 << 12), // CIwSVec2(0 << 12, 1 << 12), // CIwSVec2(1 << 12, 1 << 12), // CIwSVec2(1 << 12, 0 << 12), //}; static CIwSVec2 uvs[4] = { CIwSVec2((0 << 12) + 1, (0 << 12) + 1), CIwSVec2((0 << 12) + 1, (1 << 12) - 1), CIwSVec2((1 << 12) - 1, (1 << 12) - 1), CIwSVec2((1 << 12) - 1, (0 << 12) + 1), }; static CIwSVec2 uvsRot[4] = { CIwSVec2((0 << 12) + 20, (0 << 12) + 20), CIwSVec2((0 << 12) + 20, (1 << 12) - 20), CIwSVec2((1 << 12) - 20, (1 << 12) - 20), CIwSVec2((1 << 12) - 20, (0 << 12) + 20), }; while (iter != gVectorImageUrls.end()) { MapTile* pTile = *iter; CIwTexture* pTexture = pTile->pTexture; if (pTexture) { //Calculate the top left of the map image CIwSVec2 topLeft = pTile->location; CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL(); pMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND); pMat->SetModulateMode(CIwMaterial::MODULATE_RGB); // Use Texture on Material pMat->SetTexture(pTexture); IwGxSetMaterial(pMat); int xOffset = IwGxGetScreenWidth() / 2; int yOffset = IwGxGetScreenHeight() / 2; CIwSVec3* pWSCoords= IW_GX_ALLOC(CIwSVec3, 4); pWSCoords[0].x = topLeft.x; pWSCoords[0].y = topLeft.y; pWSCoords[1].x = topLeft.x; pWSCoords[1].y = topLeft.y + 256; pWSCoords[2].x = topLeft.x + 256; pWSCoords[2].y = topLeft.y + 256; pWSCoords[3].x = topLeft.x + 256; pWSCoords[3].y = topLeft.y; pWSCoords[0].z = pWSCoords[1].z = pWSCoords[2].z = pWSCoords[3].z = 0; // Scale the coordinates by offsetting, scaling and rendering for (int i = 0; i < 4; ++i) { pWSCoords[i].x -= xOffset; pWSCoords[i].y -= yOffset; } IwGxSetVertStreamWorldSpace(pWSCoords, 4); if (g_bScaledMode) { IwGxSetUVStream(uvsRot); } else { IwGxSetUVStream(uvs); } IwGxSetColStream(cols); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); } iter++; } IwGxSetColStream(NULL); //IwGxSetColClear(colClear.r, colClear.g, colClear.b, colClear.a); }
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; } } }
extern "C" void RenderCursorskeys() { int height = 20; int width = 45; int lefty = IwGxGetScreenHeight() - (height * 2); int leftx = (IwGxGetScreenWidth() - 220) / 2; int upy = IwGxGetScreenHeight() - (height * 3); int upx = leftx+width + (width/2); int downy = IwGxGetScreenHeight() - height; int downx = upx; int righty = IwGxGetScreenHeight() - (height * 2); int rightx = downx + width + (width/2); CIwMaterial *fadeMat = IW_GX_ALLOC_MATERIAL(); fadeMat->SetAlphaMode(CIwMaterial::SUB); IwGxSetMaterial(fadeMat); g_Cursorkey = EXCURSOR_NONE; if ( (s3eKeyboardGetState(s3eKeyLeft) & S3E_KEY_STATE_DOWN) ) g_Cursorkey = EXCURSOR_LEFT; if ( (s3eKeyboardGetState(s3eKeyRight) & S3E_KEY_STATE_DOWN) ) g_Cursorkey = EXCURSOR_RIGHT; if ( (s3eKeyboardGetState(s3eKeyUp) & S3E_KEY_STATE_DOWN) ) g_Cursorkey = EXCURSOR_UP; if ( (s3eKeyboardGetState(s3eKeyDown) & S3E_KEY_STATE_DOWN) ) g_Cursorkey = EXCURSOR_DOWN; if(s3ePointerGetInt(S3E_POINTER_AVAILABLE)) { if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN) { int pointerx = s3ePointerGetX(); int pointery = s3ePointerGetY(); // Check left if (pointerx >= leftx && pointerx <= leftx+width && pointery >=lefty && pointery <= lefty+height) g_Cursorkey = EXCURSOR_LEFT; // Check right if (pointerx >= rightx && pointerx <= rightx+width && pointery >=righty && pointery <= righty+height) g_Cursorkey = EXCURSOR_RIGHT; // Check up if (pointerx >= upx && pointerx <= upx+width && pointery >=upy && pointery <= upy+height) g_Cursorkey = EXCURSOR_UP; // Check down if (pointerx >= downx && pointerx <= downx+width && pointery >=downy && pointery <= downy+height) g_Cursorkey = EXCURSOR_DOWN; } CIwColour* cols = IW_GX_ALLOC(CIwColour, 4); if((s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN) && (g_Cursorkey != EXCURSOR_NONE)) memset(cols, 10, sizeof(CIwColour)*4); else memset(cols, 50, sizeof(CIwColour)*4); // draw black rect covering screen CIwSVec2 rectdim(width, height); CIwSVec2 uXY(upx, upy-2); IwGxDrawRectScreenSpace(&uXY, &rectdim, cols); IwGxPrintString(upx + 10, upy + 5, "Up", false); CIwSVec2 dXY(downx, downy-2); IwGxDrawRectScreenSpace(&dXY, &rectdim, cols); IwGxPrintString(downx + 10, downy + 5, "Down", false); CIwSVec2 lXY(leftx, lefty-2); IwGxDrawRectScreenSpace(&lXY, &rectdim, cols); IwGxPrintString(leftx + 10, lefty + 5, "Left", false); CIwSVec2 rXY(rightx, righty-2); IwGxDrawRectScreenSpace(&rXY, &rectdim, cols); IwGxPrintString(rightx + 10, righty + 5, "Right", false); } }
void CameraDefend::Render() { if (defended) { IwGxLightingOff(); animMatSuccess->SetModulateMode(CIwMaterial::MODULATE_NONE); animMatSuccess->SetAlphaMode(CIwMaterial::ALPHA_BLEND); IwGxSetMaterial(animMatSuccess); IwGxSetUVStream(anim_uvs_success); IwGxSetVertStreamScreenSpace(animVertsLeftSuccess, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); IwGxSetVertStreamScreenSpace(animVertsRightSuccess, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); if (animMatSuccess->GetAnimCelID() == animMatSuccess->GetAnimCelNum() - 1) { defended = false; } } else { animMatSuccess->SetAnimCelID(0); } if (!isActive()) return; { Ghost* ghost = getGameState()->getGhost(); GhostAttack* attack = (ghost != NULL) ? ghost->getAttack() : NULL; if (attack != NULL && ((attack->getInterval() < 750 && attack->getInterval() > 600) || (attack->getInterval() < 400 && attack->getInterval() > 250))) { dotTexture = dotTextureRed; } else { dotTexture = dotTextureGreen; } } Iw2DSetAlphaMode(IW_2D_ALPHA_NONE); Iw2DSetTransformMatrix(CIwFMat2D::g_Identity); CIwFMat2D rot; rot.SetRot(rad(dotAngle), CIwFVec2( dotVertsTopLeftLeft.x + dotVertsSizeLeft.x/2, dotVertsTopLeftLeft.y + dotVertsSizeLeft.y/2)); Iw2DSetTransformMatrix(rot); Iw2DDrawImage(dotTexture, dotVertsTopLeftLeft, dotVertsSizeLeft); rot.SetRot(rad(dotAngle), CIwFVec2( dotVertsTopLeftRight.x + dotVertsSizeRight.x/2, dotVertsTopLeftRight.y + dotVertsSizeRight.y/2)); Iw2DSetTransformMatrix(rot); Iw2DDrawImage(dotTexture, dotVertsTopLeftRight, dotVertsSizeRight); bool isDrwaing = true; for (int i = 0; i < DEFEND_TOUCHES_MAX; i++) { // Is any touch drawing? if (touch[i]->drawing) break; if (i == DEFEND_TOUCHES_MAX - 1) { isDrwaing = false; animMat->SetAnimCelID(0); } } if (isDrwaing) { IwGxLightingOff(); animMat->SetModulateMode(CIwMaterial::MODULATE_NONE); animMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND); IwGxSetMaterial(animMat); IwGxSetUVStream(anim_uvs); IwGxSetVertStreamScreenSpace(animVertsLeft, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); IwGxSetVertStreamScreenSpace(animVertsRight, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); } }
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; }
// BatchDrawPrims - Currently only supports batching of Quad lists void CzPlatformRender::BatchDrawPrims(bool filter) { if (NextMaterial == 0) return; // Allocate memory from data cache for verts, UV's and colours for (int t = 0; t < NextMaterial; t++) { int prim_count = MaterialUsedCounts[t] * 4; BatchVerts[t] = IW_GX_ALLOC(CzVec2, prim_count); BatchUVs[t] = IW_GX_ALLOC(CzVec2, prim_count); BatchColours[t] = IW_GX_ALLOC(CzColour, prim_count); BatchIndices[t] = IW_GX_ALLOC(uint16, prim_count); } // Populate the data cache CzRenderPrim** prims = Primitives; for (int t = 0; t < NextPrimitive; t++) { CzRenderPrim *prim = *prims; int mat_id = prim->MaterialID; int idx = MaterialIndices[mat_id]; CzVec2* v = BatchVerts[mat_id] + idx; CzVec2* uv = BatchUVs[mat_id] + idx; CzColour* c = BatchColours[mat_id] + idx; uint16* i = BatchIndices[mat_id] + idx; for (int t2 = 0; t2 < 4; t2++) { v->x = (prim->Verts + t2)->x; v->y = (prim->Verts + t2)->y; uv->x = (prim->UVs + t2)->x; uv->y = (prim->UVs + t2)->y; c->set(*(prim->Colours + t2)); v++; uv++; c++; } // TODO: ERROR - Does not work with batched ngon *i++ = idx; *i++ = idx + 3; *i++ = idx + 2; *i++ = idx + 1; MaterialIndices[mat_id] += 4; prims++; } // Render batched streams CzRenderMaterial** mats = Materials; for (int t = 0; t < NextMaterial; t++) { int count = MaterialUsedCounts[t] * 4; IwGxSetUVStream((CIwFVec2*)BatchUVs[t], 0); IwGxSetVertStreamScreenSpace((CIwFVec2*)BatchVerts[t], count); IwGxSetColStream((CIwColour*)(BatchColours[t]), count); IwGxSetNormStream(NULL); CIwMaterial* mat = IW_GX_ALLOC_MATERIAL(); CIwTexture* texture = static_cast<CIwTexture*>((*mats)->Image->getTexture()); mat->SetTexture(texture); mat->SetDepthWriteMode(CIwMaterial::DEPTH_WRITE_DISABLED); mat->SetClamping(false); mat->SetFiltering(filter); mat->SetAlphaMode(CIwMaterial::ALPHA_BLEND); mat->SetCullMode(CIwMaterial::CULL_BACK); // mat->SetCullMode(CIwMaterial::CULL_NONE); IwGxSetMaterial(mat); IwGxDrawPrims(IW_GX_QUAD_LIST, BatchIndices[t], count); mats++; } // Reset batch pointers for (int t = 0; t < NextMaterial; t++) MaterialUsedCounts[t] = 0; for (int t = 0; t < NextMaterial; t++) MaterialIndices[t] = 0; NextPrimitive = 0; NextMaterial = 0; }
void CzPlatformRender::DrawText(CzFontPreparedText prepared_text, CzFont* font, CzMatrix3* transform, const CzColour& colour, CzVec4& skew, bool filter, eCzAlphaMode alpha_mode) { CIwMaterial::AlphaMode am = (CIwMaterial::AlphaMode)alpha_mode; // TODO Add proper method map Marmalade Alpha mode to Marmalade // Cache the transform float m00 = transform->m[0][0]; float m01 = transform->m[0][1]; float m10 = transform->m[1][0]; float m11 = transform->m[1][1]; float tx = transform->getX(); float ty = transform->getY(); float sx1 = (float)skew.x; float sx2 = (float)skew.y; float sy1 = (float)skew.z; float sy2 = (float)skew.w; /* CzIRect clip = ScreenClipRect; clip.x <<= 3; clip.y <<= 3; clip.w = clip.x + (clip.w << 3); clip.h = clip.y + (clip.h << 3);*/ IwGxLightingOn(); IwGxSetColStream(NULL); IwGxSetNormStream(NULL); CIwGxFont* mfont = static_cast<CIwGxFont*>(font->getFontHandle()); CIwGxFontPreparedData* prep_text = static_cast<CIwGxFontPreparedData*>(prepared_text); // A font can consist of multiple materials so we need to process all of them for (int t = 0; t < mfont->GetNumberMaterials(); t++) { // Set UV stream uint32* char_ids; int num_chars = IwGxFontSetUVs(*prep_text, -1, t, &char_ids); // Generate transformed vertices from glyphs int nv = num_chars << 2; CzVec2* pVerts = IW_GX_ALLOC(CzVec2, nv); CzVec2* pVert = pVerts; if (m01 == 0 && m10 == 0) { // No rotation optimisation for (int t2 = 0; t2 < num_chars; t2++) { CIwRect rc = prep_text->GetCharacterArea(char_ids[t2]); float x1 = (float)rc.x; float y1 = (float)rc.y; float x2 = x1 + (float)rc.w; float y2 = y1 + (float)rc.h; float ax = (m00 * x1) + tx; float ay = (m11 * y1) + ty; float bx = (m00 * x2) + tx; float by = (m11 * y2) + ty; // if ((ax < clip.w && bx >= clip.x) && (ay < clip.h && by >= clip.y)) // { pVert->x = ax + sx1; pVert->y = ay + sy1; pVert++; pVert->x = ax - sx1; pVert->y = by + sy2; pVert++; pVert->x = bx - sx2; pVert->y = by - sy2; pVert++; pVert->x = bx + sx2; pVert->y = ay - sy1; pVert++; // } } } else { for (int t2 = 0; t2 < num_chars; t2++) { CIwRect rc = prep_text->GetCharacterArea(char_ids[t2]); float x1 = (float)rc.x; float y1 = (float)rc.y; float x2 = x1 + (float)rc.w; float y2 = y1 + (float)rc.h; pVert->x = (m00 * x1 + m10 * y1 + tx + sx1); pVert->y = (m01 * x1 + m11 * y1 + ty + sy1); pVert++; pVert->x = (m00 * x1 + m10 * y2 + tx - sx1); pVert->y = (m01 * x1 + m11 * y2 + ty + sy2); pVert++; pVert->x = (m00 * x2 + m10 * y2 + tx - sx2); pVert->y = (m01 * x2 + m11 * y2 + ty - sy2); pVert++; pVert->x = (m00 * x2 + m10 * y1 + tx + sx2); pVert->y = (m01 * x2 + m11 * y1 + ty - sy1); pVert++; } } if (nv > 0) { // Set vertex stream IwGxSetVertStreamScreenSpace((CIwFVec2*)pVerts, nv); // Create a material CIwMaterial* mat = IW_GX_ALLOC_MATERIAL(); mat->Copy(*IwGxFontGetFont()->GetMaterial(t)); mat->SetDepthWriteMode(CIwMaterial::DEPTH_WRITE_DISABLED); mat->SetColEmissive(colour.get()); mat->SetClamping(true); mat->SetFiltering(filter); mat->SetAlphaMode(am); mat->SetCullMode(CIwMaterial::CULL_BACK); // mat->SetCullMode(CIwMaterial::CULL_NONE); IwGxSetMaterial(mat); // Finally draw the glyphs IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, nv); CurrentAlphaMode = alpha_mode; } } IwGxLightingOff(); CurrentTexture = NULL; }
void Transitions2D::Slide(DIR d, uint8 transitionSpeed, bool skipFirstAndLastFrame) { IwGxSetColClear(0, 0, 0, 0); if (mStartTexture == NULL || mEndTexture == NULL) return; if (transitionSpeed == 0) transitionSpeed = 1; IwGxScreenOrient orient = IwGxGetScreenOrient(); if (isUsingPrivateTextures) IwGxSetScreenOrient(IW_GX_ORIENT_NONE); CIwMaterial* startMat; CIwMaterial* endMat; int w = mStartTexture->GetWidth(); int h = mStartTexture->GetHeight(); int pos = 0; int speed, size; if (d == LEFT || d == RIGHT) { speed = (int)((transitionSpeed * w) / 255.0); size = w; } else { speed = (int)((transitionSpeed * h) / 255.0); size = h; } if (skipFirstAndLastFrame) pos += speed; while (pos < size) { IwGxClear(); if (d == LEFT) { startMat = IW_GX_ALLOC_MATERIAL(); startMat->SetTexture(mStartTexture); IwGxSetMaterial(startMat); IwGxDrawRectScreenSpace(&CIwSVec2(-pos, 0), &CIwSVec2(mStartTexture->GetWidth(), mStartTexture->GetHeight())); endMat = IW_GX_ALLOC_MATERIAL(); endMat->SetTexture(mEndTexture); IwGxSetMaterial(endMat); IwGxDrawRectScreenSpace(&CIwSVec2(-pos + size, 0), &CIwSVec2(mEndTexture->GetWidth(), mEndTexture->GetHeight())); } else if (d == RIGHT) { endMat = IW_GX_ALLOC_MATERIAL(); endMat->SetTexture(mEndTexture); IwGxSetMaterial(endMat); IwGxDrawRectScreenSpace(&CIwSVec2(pos - size, 0), &CIwSVec2(mEndTexture->GetWidth(), mEndTexture->GetHeight())); startMat = IW_GX_ALLOC_MATERIAL(); startMat->SetTexture(mStartTexture); IwGxSetMaterial(startMat); IwGxDrawRectScreenSpace(&CIwSVec2(pos, 0), &CIwSVec2(mStartTexture->GetWidth(), mStartTexture->GetHeight())); } else if (d == UP) { startMat = IW_GX_ALLOC_MATERIAL(); startMat->SetTexture(mStartTexture); IwGxSetMaterial(startMat); IwGxDrawRectScreenSpace(&CIwSVec2(0, -pos), &CIwSVec2(mStartTexture->GetWidth(), mStartTexture->GetHeight())); endMat = IW_GX_ALLOC_MATERIAL(); endMat->SetTexture(mEndTexture); IwGxSetMaterial(endMat); IwGxDrawRectScreenSpace(&CIwSVec2(0, -pos + size), &CIwSVec2(mEndTexture->GetWidth(), mEndTexture->GetHeight())); } else if (d == DOWN) { endMat = IW_GX_ALLOC_MATERIAL(); endMat->SetTexture(mEndTexture); IwGxSetMaterial(endMat); IwGxDrawRectScreenSpace(&CIwSVec2(0, pos - size), &CIwSVec2(mEndTexture->GetWidth(), mEndTexture->GetHeight())); startMat = IW_GX_ALLOC_MATERIAL(); startMat->SetTexture(mStartTexture); IwGxSetMaterial(startMat); IwGxDrawRectScreenSpace(&CIwSVec2(0, pos), &CIwSVec2(mStartTexture->GetWidth(), mStartTexture->GetHeight())); } IwGxFlush(); IwGxSwapBuffers(); s3eDeviceYield(40); pos += speed; } if (!skipFirstAndLastFrame) { IwGxClear(); endMat = IW_GX_ALLOC_MATERIAL(); endMat->SetTexture(mEndTexture); IwGxSetMaterial(endMat); IwGxDrawRectScreenSpace(&CIwSVec2(0, 0), &CIwSVec2(mEndTexture->GetWidth(), mEndTexture->GetHeight())); IwGxFlush(); IwGxSwapBuffers(); } if (isUsingPrivateTextures) { delete mStartTexture; delete mEndTexture; mStartTexture = NULL; mEndTexture = NULL; } IwGxSetScreenOrient(orient); }
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); } }