0
votes


void init(void)
{ 
    glEnable(GL_DEPTH_TEST);
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}

void display(void) { glClearColor(1.0, 1.0, 1.0, 1.0);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glScalef(1.0,1.0,1.0);
glColor3f(0.0,0.0,0.0);
    glBegin(GL_POLYGON);
    glVertex2f(-0.5, -0.5);
    glVertex2f(-0.5, 0.5);
    glVertex2f(0.5, 0.5);
    glVertex2f(0.5, -0.5);
glEnd();
    glutSwapBuffers();

}

void reshape(int w, int h) { int height = h; int width = w; glViewport(0, 0, (GLsizei)w, (GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60, (GLfloat)w / (GLfloat)h, 1.0, 100.0); glMatrixMode(GL_MODELVIEW); }

int main(int argc, char* argv[]) { Complex c(0,0); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(512, 512); glutInitWindowPosition(100, 100); winID = glutCreateWindow("Fractal"); init(); glutDisplayFunc(display); glutIdleFunc(display); glutReshapeFunc(reshape); // Compute the update rate here... glutMainLoop(); return 0; }

I get a square if I put the code in display(), except the glutSwapBuffers() in if condition which checks whether the code has entered display the first time. If I remove the if, I get a white window

1
The question is not worded properly. What's your problem?max
// Compute the update rate here… no it doesn't. That particular line of code is reached exactly one time in course of running the program. If you have a nonterminating loop there, you'll not reach the GLUT main loop, hence preventing events being processed. Also instead of display you should register glutPostRedisplay as idle function if you want continous updates.datenwolf

1 Answers

1
votes

Put an extra glTranslatef(0.0f, 0.0f, -5.0f) in your display function, to push everything 5 units back into the scene, otherwise you wont see what you're drawing at the origin.

Btw, the line glScalef(1.0,1.0,1.0) doesn't do anything, remove it to avoid unnecessary calculations.

EDIT: There is no "eye" in OpenGL. More specifically, it is always fixed at (0,0,0) looking down at the negative z-axis. You have to move the whole scene with the inverse of the eye transformations. You can either move the scene manually so your eye can see it, or use gluLookAt, where you can specify the "eye", but in the background it just transforms the scene so the fixed "eye" can see it.

Further reading: http://www.opengl.org/archives/resources/faq/technical/viewing.htm