hello,
i write a c program that draws a fractal in a Dev-C++ compiler. it is fully compiled but when executed an illegal operation message pops up. also, the display screen is colorless.
does anyone know what is happening? please let me know.
here is the untested code, i would appreciate any help. thanks!
godach
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <gl\gl.h>
#include <gl\glut.h>
#define PI 3.14159
#define FOR(i,a,b) for(i=a;i<b;i++)
typedef struct{ /A new structure that defines the coordinates of a point./
double x;
double y; /Define z may be useful but not required in this project./
}coordinates;
coordinates pt[8];
coordinates bb[4]={0.,0.,
1.,0.,
1.,1.,
0.,1.}; /Define the coordinates of the base square/
void transform(double ro, /Performs 2-by-2 similitude (a case of affine transformation)./
double sc, /Accepts rotation (ro), scale factor (sc), translation coordinates(tr),/
coordinates tr, /and the coordinates of the point to be transformed (input),/
coordinates input[],/and returns the transformed coordinates to the calling function./
coordinates output[]){
int i;
output[i].x=sc*cos(ro)input[i].x-scsin(ro)input[i].y+tr.x;
output[i].y=scsin(ro)input[i].x+sccos(ro)*input[i].y+tr.y;
}
int even(int num){
int ans;
ans=((num%2)==0);
return(ans);
}
void display (void){
int aa,cc=0;
int po=20;
int pp=1;
int gg=0;
int ii=0;
coordinates tt={0.,1.};
double z[1]={-5.};
double rr=0.;
double ss=1/cos(0.);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.,0.,0.,0.);
glMatrixMode(GL_MODELVIEW);
FOR(aa,0,po){ /*A function is needed to perform population calculation*/
cc+=1;
if(even(cc))
FOR(ii,0,4){
transform(PI-rr,ss,tt,bb,pt);
}
else
FOR(ii,0,4){
transform(rr,ss,tt,bb,pt);
}
if(cc==pp){
cc=0;
gg+=1;
pp=pow(2,gg);
rr+=PI/6;
ss=ss*1/2/cos(rr);
}
FOR(ii,0,4){
glBegin(GL_LINES);
glColor3f((GLfloat)0.,(GLfloat)0.,(GLfloat)1.);
glVertex3f(pt[ii].x,pt[ii].y,z[0]);
glEnd();
}
}
glutSwapBuffers();
}
void init(void)
{
glClearColor(0.0f ,0.0f ,0.0f ,0.0f);
glColor3f(0.0f,0.0f,1.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)250/(GLfloat)250,0.1f,100.0f);
}
void idle(void){glutPostRedisplay();}
int main(int argc, char *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow(“Two Dimensional Fractal Broccoli”);
init();
glutDisplayFunc(display);
glutIdleFunc(idle);
glutMainLoop();
return 0;
}
godach