Skip to content

Commit 453d705

Browse files
authored
HUGE optimization
I just added 2 buffers, and for some reason, that sped things up A LOT. A LOT A LOT. At least 10 times on my shitty laptop
1 parent b6e5176 commit 453d705

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

mandel.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ void key(unsigned char key, int x, int y) {
6060
case '3': {fractal=3;std::cout << "---Tri-corn---\n";glutPostRedisplay();break;}
6161
case '2': {fractal=2;std::cout << "-Burning Ship-\n";glutPostRedisplay();break;}
6262
case '1': {fractal=1;std::cout << "Mandelbrot Set\n";glutPostRedisplay();break;}
63-
case 'r': {reset();break;}
64-
case 'f': {fullscreen = !fullscreen;if(fullscreen){oWIDTH=WIDTH;oHEIGHT=HEIGHT;glutFullScreen();}else{glutReshapeWindow(oWIDTH,oHEIGHT);}break;}
65-
case 'j': {if(julia){julia=false;reset();std::cout << "-Fractal Mode-\n";}else{julia=true;xJul=xPos+mouseX/zoom;yJul=yPos+(HEIGHT-mouseY)/zoom;reset();std::cout << "--Julia Mode--\nReal:" << xJul << "\nImag:" << yJul << "\n--------------\n";}break;}
63+
case 'r': {reset();break;}
64+
case 'f': {fullscreen=!fullscreen;if(fullscreen){oWIDTH=WIDTH;oHEIGHT=HEIGHT;glutFullScreen();}else{glutReshapeWindow(oWIDTH,oHEIGHT);}break;}
65+
case 'j': {if(julia){julia=false;reset();std::cout << "-Fractal Mode-\n";}else{julia=true;xJul=xPos+mouseX/zoom;
66+
yJul=yPos+(HEIGHT-mouseY)/zoom;reset();std::cout << "--Julia Mode--\nReal:" << xJul << "\nImag:" << yJul << "\n--------------\n";}break;}
6667
}
6768
}
6869
long double r0,i0,real,imag,tempreal,io,ro;
@@ -126,9 +127,10 @@ float escapesmooth(long double real, long double imag, int x, int y){
126127
return iter;
127128
}
128129
void display(){
130+
glClear(GL_COLOR_BUFFER_BIT);
129131
if(render){
132+
glBegin(GL_POINTS);
130133
for(int y=HEIGHT;y>0;y--){
131-
glBegin(GL_POINTS);
132134
for(int x=0;x<WIDTH+1;x++){
133135
iterations=escapesmooth(x/zoom+xPos,y/zoom+yPos,xJul,yJul);
134136
glVertex2i(x,y);
@@ -165,10 +167,11 @@ void display(){
165167
}
166168
}
167169
}
168-
glEnd();
169-
glFlush();
170170
}
171+
glEnd();
172+
glFlush();
171173
}
174+
glutSwapBuffers();
172175
}
173176
void reshape(int w, int h) {
174177
glViewport(0, 0, w, h);
@@ -181,7 +184,8 @@ void reshape(int w, int h) {
181184
HEIGHT = h;
182185
render=true;
183186
glutPostRedisplay();
184-
}bool isDragging = false;
187+
}
188+
bool isDragging = false;
185189
int lastX,lastY;
186190

187191
void mouse(int button, int state, int x, int y){
@@ -230,7 +234,6 @@ int main(int argc, char** argv){
230234
glMatrixMode(GL_PROJECTION);
231235
glLoadIdentity();
232236
gluOrtho2D(0, WIDTH, 0, HEIGHT);
233-
glMatrixMode(GL_MODELVIEW);
234237
glLoadIdentity();
235238
glClearColor(0.0,0.0,0.0,1.0);
236239
std::cout << "Maximum iterations: " << maxIter << "\n";

0 commit comments

Comments
 (0)