1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#define NUM_BG_STARS 20
void InitBGStars(BGStar Stars[], int NumStars)
{
BGStar* pCurrentStar = Stars;
for(int StarIndex = 0; StarIndex < NumStars; ++StarIndex)
{
pCurrentStar->Position[0] = ((float)rand() / (float)RAND_MAX);
pCurrentStar->Position[1] = ((float)rand() / (float)RAND_MAX);
pCurrentStar->Size = 0.001f + (0.001f * ((float)rand() / (float)RAND_MAX));
++pCurrentStar;
}
}
void UpdateBGStars(BGStar Stars[], int NumStars, float DeltaTime)
{
BGStar* pCurrentStar = Stars;
for(int StarIndex = 0; StarIndex <= NumStars; ++StarIndex)
{
UpdateBGStar(pCurrentStar, DeltaTime);
++pCurrentStar;
}
}
void DrawBGStars(BGStar Stars[], int NumStars)
{
// Draw the stars
glBegin(GL_QUADS);
BGStar* pCurrentStar = Stars;
for(int StarIndex = 0; StarIndex < NumStars; ++StarIndex)
{
glColor3f(1.0f, 1.0f, 1.0f);
glVertex3f(pCurrentStar->Position[0] - pCurrentStar->Size, pCurrentStar->Position[1] - pCurrentStar->Size, 0.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glVertex3f(pCurrentStar->Position[0] + pCurrentStar->Size, pCurrentStar->Position[1] - pCurrentStar->Size, 0.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glVertex3f(pCurrentStar->Position[0] + pCurrentStar->Size, pCurrentStar->Position[1] + pCurrentStar->Size, 0.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glVertex3f(pCurrentStar->Position[0] - pCurrentStar->Size, pCurrentStar->Position[1] + pCurrentStar->Size, 0.0f);
++pCurrentStar;
}
// Finish drawing
glEnd();
}
|