void Renderer::DrawPrimitive(Primitive *primitive) { rend_primitive_ = RendPrimitive(primitive->size, primitive->material); for (int i = 0; i < rend_primitive_.size; ++i) { rend_primitive_.position[i].SetVector3(primitive->position[i]); rend_primitive_.position[i].w = 1.0f; rend_primitive_.normals[i].SetVector3(primitive->normals[i]); rend_primitive_.normals[i].w = 0.0f; rend_primitive_.colors[i] = primitive->colors[i]; } ModelViewTransform(); // Lighting(); Projection(); Clipping(Vector3(-1, -1, 0), Vector3(1, 1, 1.0f)); Rasterization(); }
EXPORT_C void CHuiLayout::Draw(CHuiGc& aGc) const { if (Flags() & EHuiVisualFlagDrawOnlyAsExternalContent) { // This is used only as external content visual. Return now if we are not currently drawing // external content. if (!Display() || !Display()->RosterImpl().IsDrawingExternalContent()) { return; } } if(iOpacity.Now() <= EPSILON && (Effect() && !Effect()->IsSemitransparent())) { // This will not be visible due to being completely transparent. return; } if (( IsDelayedEffectSource()||Freezed() ) && StoredRenderBuffer()) { DrawStoredBitmap(aGc); return; } if (!HasActiveChilderen() && !Brushes() && !Effect()) { // No children, no brushes just return. return; } /** @todo Wouldn't it be possible to just extend CHuiVisual::Draw() instead of redefining the entire method? */ THuiRealRect area = DisplayRect(); // Apply local transformation. EnterLocalProjection(aGc, ETrue, 0.f, &area); Transform(aGc, ETrue, &area); DrawBrushes(aGc, EHuiBrushLayerBackground); if(Clipping()) { // @todo Clipping not going to work if there is a transformation? // Layout clipping is not affected by transformation. aGc.Enable(CHuiGc::EFeatureClipping); aGc.PushClip(); aGc.Clip(area); } // Can we draw effect TBool canUseEffectDrawing = Effect() && !LoadingEffect(); // Flag to know what we did TBool didDrawEffect = EFalse; if (canUseEffectDrawing) { // Note that EHuiVisualFlagOpaqueHint improves performance a lot in cached effect drawing TBool transparent = !(Flags() & EHuiVisualFlagOpaqueHint) && iOpacity.Now() < 1.0f; TBool refreshCache = Changed(); didDrawEffect = Effect()->CachedDraw(aGc, area, refreshCache, !transparent); } if ( !didDrawEffect ) { // huilayout does not draw itself, only children. } else { // Effect was drawn, OpenGLES/OpenVG may be in different state than what Gc thinks so we restore it. aGc.RestoreState(); } if ( !didDrawEffect || (didDrawEffect && !EffectIsAppliedToChildren())) { // The layout itself is invisible. Only its children can be seen. TBool afterOthers = EFalse; const TInt count = Count(); for(TInt i = 0; i < count; ++i) { CHuiVisual* visual = iHuiLayoutPrivateData->iChildren[i]; //Ignore inactive child visuals if ( visual->Flags()& EHuiVisualFlagInactive ) { continue; } if(visual->Flags() & EHuiVisualFlagDrawAfterOthers) { afterOthers = ETrue; continue; } // @todo No need to draw children that won't be visible. visual->Draw(aGc); } if(afterOthers) { for(TInt i = 0; i < count; ++i) { if(iHuiLayoutPrivateData->iChildren[i]->Flags() & EHuiVisualFlagDrawAfterOthers) { iHuiLayoutPrivateData->iChildren[i]->Draw(aGc); } } } } if(Clipping()) { // Restore original clipping rectangle. aGc.PopClip(); } DrawBrushes(aGc, EHuiBrushLayerForeground); // Restore original transformation. Transform(aGc, EFalse); EnterLocalProjection(aGc, EFalse); }
//updates the world one tick void UpdateGame(void) { int numbigasteroids = 0, nummedasteroids = 0; LIST * cur; LIST * next; static unsigned int fpsframes = 0; static unsigned int last_fps_time = 0; unsigned int t; char hiscore_name[HS_NAME_LENGTH]; if(g_paused) return; UpdateStarfield(&g_starfield); for(cur = g_asteroid_list; cur; cur = cur->next) { if(((ASTEROID *)cur->d)->scale == 4.0f) numbigasteroids++; else if(((ASTEROID *)cur->d)->scale == 2.0f) nummedasteroids++; } t = 1500*numbigasteroids + 500*nummedasteroids + (int)(16384.0/pow((double)g_score, 0.3010299956639811952)); if(g_ships && !g_time_to_reset && g_level > 2 && !(rand() % t)) { NewAlien(g_score >= 10000 ? (rand() % 3) : 1); } t = (g_ships + 1) * 1000; if(g_ships && g_ships < 11 && !g_time_to_reset && !(rand() % t)) { NewPowerup(); } for(cur = g_asteroid_list; cur; cur = cur->next) UpdateAsteroid(cur->d); if(g_ships) UpdatePlayer(&g_player, g_keys); for(cur = g_alien_list; cur; cur = next) { next = cur->next; UpdateAlien(cur->d, (g_ships ? &g_player : NULL), g_asteroid_list); if(((ALIEN *)cur->d)->pos.x < 0.0f || ((ALIEN *)cur->d)->pos.x > 40.0f) RemoveNode(cur, &g_alien_list); } for(cur = g_shot_list; cur; cur = next) { next = cur->next; UpdateShot(cur->d); if(!(((SHOT *)cur->d)->life)) RemoveNode(cur, &g_shot_list); } for(cur = g_explosion_list; cur; cur = next) { next = cur->next; UpdateExplosion(cur->d); if(!(((EXPLOSION *)cur->d)->life)) RemoveNode(cur, &g_explosion_list); } for(cur = g_burst_list; cur; cur = next) { next = cur->next; UpdateBurst(cur->d); if(!(((BURST *)cur->d)->life)) RemoveNode(cur, &g_burst_list); } for(cur = g_powerup_list; cur; cur = next) { next = cur->next; UpdatePowerup(cur->d); if(((POWERUP *)cur->d)->pos.x < 0.0f || ((POWERUP *)cur->d)->pos.x > 40.0f) RemoveNode(cur, &g_powerup_list); } Clipping(); g_frame++; //next frame if(g_time_to_reset && !(--g_time_to_reset)) NextLevel(); if(!g_ships && g_hisct_delay && !(--g_hisct_delay) && IsScoreHi(&g_hisct, g_score) && GetHiScoreName(hiscore_name)) AddHiScore(&g_hisct, hiscore_name, g_score, g_level); fpsframes++; t = glutGet(GLUT_ELAPSED_TIME); if(t >= last_fps_time + 1000) { g_fps = (float)fpsframes / (float)(t - last_fps_time) * 1000.0f; fpsframes = 0; last_fps_time = t; } glutPostRedisplay(); }