-1
私はOpenGL C++で円グラフを描きましたが、初期化すると色が綺麗になりました。しかし、色をrand()するためにボタンを押すと、円グラフは見えなくなります。OpenGLの円グラフの色の変更がエラーで満たされました
HERESに私の円グラフコード
void PieChart1(int x, int y, int radius)
{
//float i;
int triangleAmount = 100; //# of triangles used to draw circle
int startPos = 0;
int Pie1AnglePercentage[7];
GLfloat twicePi = 2.0f * 3.14159;
float TotalPie1Banana = 0;
//TotalZoo1Banana = 0;
//int zoo1Data[7] = { 200, 300, 250, 275, 150, 310, 380 };
//Zoo1PieData
GLfloat colorTable[7][3] = { { Pie12014R, Pie12014G, Pie12014B },
{ Pie12013R, Pie12013G, Pie12013B },
{ Pie12012R, Pie12012G, Pie12012B },
{ Pie12011R, Pie12011G, Pie12011B },
{ Pie12010R, Pie12010G, Pie12010B },
{ Pie12009R, Pie12009G, Pie12009B },
{ Pie12008R, Pie12008G, Pie12008B } };
float Zoo1PieData[7] = { BananaDisplay2014,BananaDisplay2013,BananaDisplay2012,
BananaDisplay2011,BananaDisplay2010,BananaDisplay2009,BananaDisplay2008 };
//PIE 1 ZOO 1 SUM BANANAS TOTAL
for(int i = 0; i < 7; ++i)
TotalPie1Banana += Zoo1PieData[i];
//PIE 1 PERCENTAGE FOR EACH YEAR
for (int i = 0; i < 7; ++i)
Pie1AnglePercentage[i] = (Zoo1PieData[i]/TotalPie1Banana) * 100;
triangleAmount = 0;
for (int i = 0; i < 7; ++i)
triangleAmount += Pie1AnglePercentage[i];
for (int i = 0; i < 7; ++i)
{
glBegin(GL_TRIANGLE_FAN);
glColor3f(colorTable[i][0], colorTable[i][1], colorTable[i][2]);
glVertex3f(x, y, 0);
for (int j = startPos; j <= startPos + Pie1AnglePercentage[i]; ++j)
{
float const t = (twicePi*(float)j/(float)triangleAmount) + 3.141592;
glVertex3f(x - sin(t) * radius, y + cos(t) * radius, 0);
}
startPos += Pie1AnglePercentage[i];
glEnd();
}
は、上記の私の円グラフのコードがあります。
そして、ここでは、私はCキーを押したときに、パイは瞬時に消え、なぜ私は見当がつかない私の場合、キーコード
case 'c':
Pie12014R = rand() % 255;
Pie12014G = rand() % 255;
Pie12014B = rand() % 255;
Pie12013R = rand() % 255;
Pie12013G = rand() % 255;
Pie12013B = rand() % 255;
Pie12012R = rand() % 255;
Pie12012G = rand() % 255;
Pie12012B = rand() % 255;
Pie12011R = rand() % 255;
Pie12011G = rand() % 255;
Pie12011B = rand() % 255;
Pie12010R = rand() % 255;
Pie12010G = rand() % 255;
Pie12010B = rand() % 255;
Pie12009R = rand() % 255;
Pie12009G = rand() % 255;
Pie12009B = rand() % 255;
Pie12008R = rand() % 255;
Pie12008G = rand() % 255;
Pie12008B = rand() % 255;
です。
初期値は何ですか?正確に何が消えるのか? 'glColor3f'の値は[0、1]の範囲でなければならないが、[0、255]から値を生成するので、すべてが白くなると思う。 – BDL