1
,我有以下Mandelbrot集用C++編寫代碼與OpenGL的使用,但顏色是不正確的,這是希望的顏色: 壞着色設置與C++和OpenGL的
,但我得到這個:
int vala = 600;
int valb = 600;
//render one frame
void Application::render(void)
{
// Clear the window and the depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//render grid
Image img(vala, valb);
double MinRe = -2.0;
double MaxRe = 1.0;
double MinIm = -1.2;
double MaxIm = MinIm+(MaxRe-MinRe)*vala/valb;
double Re_factor = (MaxRe-MinRe)/(vala-1);
double Im_factor = (MaxIm-MinIm)/(valb-1);
unsigned MaxIterations = 250;
for(unsigned int y = 0; y < img.height; y++){
double c_im = MaxIm - y*Im_factor;
for(unsigned x=0; x< img.width; ++x){
double c_re = MinRe + x*Re_factor;
double Z_re = c_re, Z_im = c_im;
bool isInside = true;
for(unsigned n=0; n<MaxIterations; ++n){
double Z_re2 = Z_re*Z_re, Z_im2 = Z_im*Z_im;
if(Z_re2 + Z_im2 > 4)
{
isInside = false;
break;
}
Z_im = 2*Z_re*Z_im + c_im;
Z_re = Z_re2 - Z_im2 + c_re;
double z = sqrt(Z_re*Z_re + Z_im*Z_im);
int brightness = 256. *log(1.75 + n - log(log(z)));
img.setPixel(x,y, Color(sin(time)*brightness, sin(time/2)*brightness, brightness));
}
}
}
img.scale(this->window_width, this->window_height);
renderImage(&img);
//swap between front buffer and back buffer
SDL_GL_SwapWindow(this->window);
}
任何人都知道爲什麼會發生這種情況,以及如何解決它?
非常感謝。
除了'glClear(...)'這裏沒有一點GL代碼。我懷疑'Image'或'renderImage(...)'的實現是責任,但它們都沒有顯示出來。如果您直接輸出到圖像文件而不是GL,它會改變什麼嗎? –
@ AndonM.Coleman它可能沒有太多的openGL代碼,但程序的其餘部分確實包含許多行代碼,所以程序本身必須支持100%的OpenGL。 Image和renderImage不是問題,我保證它。問題來自方程打印顏色... – Gera
哦,我明白了。我解釋了這個問題,好像上面的圖片也是使用這段代碼生成的,並且錯誤的圖片是試圖在GL中顯示它的結果。 –