PDA

View Full Version : draw a spriral



D4GGR4
12-01-2011, 01:56 PM
#include <gl\glut.h>
#include <math.h>

void renderer(void){
GLfloat ang, x, y, z = -50;

glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(90,1,0,0);
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_POINTS);
for(ang = 0; ang < 10 * 3.14; ang += .1) {
x = 70 *sin(ang);
y = 70 *cos(ang);
z += .75;
glVertex3f(x,y,z);
}
glEnd();
glPopMatrix();
glFlush();
}
void changeSize(GLsizei w, GLsizei h) {
GLfloat sideRange = 200;

glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-sideRange, sideRange, -sideRange, sideRange, sideRange, -sideRange);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}


void main(void)
{
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutCreateWindow("Spiral");
glutDisplayFunc(renderer);
glutReshapeFunc(changeSize);
glutIdleFunc(renderer);
glutMainLoop();
}

when i execute the program i have a white screen...any soluccion?

mobeen
12-01-2011, 05:52 PM
You are using double buffered rendering hence you need to make a call to
glutSwapBuffers(); at the end of the render function.


void renderer(void){
GLfloat ang, x, y, z = -50;
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(90,1,0,0);
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_POINTS);
for(ang = 0; ang < 10 * 3.14; ang += .1f) {
x = 70 *sin(ang);
y = 70 *cos(ang);
z += .75;
glVertex3f(x,y,z);
}
glEnd();
glPopMatrix();
glFlush();
glutSwapBuffers();
}

See if this helps.