Problem with GlTranslate / doesn't draw if its in another function
I have a problem with glTranslate. If i draw a normal line using two functions function like this everything is okay: // void drawline(double x,double y,double z,double x2,double y2,double z2){ glBegin(GL_LINES); glVertex3f(x,y,z); glVertex3f(x2,y2,z2); glEnd(); } scene(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0,0.0,-5.0); drawline(-1.0,-1.0,0.0,1.0,1.0,0.0); } // It draws the line and everything - perfect. But if I do something like this it does not work: // void drawcircle(double increaseangle,double radius) { const double PI = 3.14159265; for (double i;i<360.0;){ glBegin(GL_LINES); glVertex3f(cos(i*PI/180)*radius,sin(i*PI/180)*radius,00.0); glVertex3f(cos((i+increaseangle)*PI/180)*radius,sin((i+increaseangle)*PI/180)*radius,00.0); glEnd(); i=i+increaseangle; } } scene(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0,0.0,-5.0); drawcircle(2.0,1.0);} // This only works if i move the glTranslatef(0.0,0.0,-5.0); from the scene function into the drawcircle function, right before const double PI = 3.14159265;. Afterwards it works. This is kind of illogical to me, because I don't really change anthing exept the function in which translate is called. There's nothing "inbetween". I've been bashing my head on the table for hours trying to locate the problem but to no avail. My gratitude to all willing to help.
Did you intentionally put:
instead of:
?
for (double i;i<360.0;){
instead of:
for (double i=0;i<360.0;){
?
For my compiler it doesn't matter. It considers
double i;
like
double i=0;
so thats not the problem.
double i;
like
double i=0;
so thats not the problem.
I just tried out your code, and it worked fine for me. There must be some problem in your init code... can you post that?
Quote:
Original post by DemonBuster
For my compiler it doesn't matter. It considers
double i;
like
double i=0;
so thats not the problem.
Are you sure? If moving the code around fixes the problem it's usually because the stack has been changed. I don't know of any compiler that intentionally does what you say yours does.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement