OpenGL缩放显示问题
OpenGL新手, 想写一个缩放的程序。我的想法是drawSincFunc()用来定义要画的曲线,myDisplay()通过对WorldWindow大小的变化实现缩放。
myInit()是一些初始化,最后是main。
现在的问题是显示出来的画面是白色的。。没有图像,所以把代码贴出来想问问大家这是什么原因。
程序代码:
#include "stdafx.h" #include "glut.h" #include <math.h> void drawSincFunc() { glBegin(GL_LINE_STRIP); for (GLfloat x = -4.0; x<4.0; x += 0.1) { GLfloat y = sin(3.14159*x) / (3.14159*x); glVertex2f(x, y); } glEnd(); glFlush(); } void myDisplay(void) { float cx = 0.0, cy = 0.3; //center of the window float H, W = 5.0, aspect = 7.143; int NumFrames = 200; glClear(GL_COLOR_BUFFER_BIT); //clear the screen glViewport(0, 640, 0, 480); //set the viewport for (int frame = 0; frame < NumFrames; frame++) { glClear(GL_COLOR_BUFFER_BIT); W *= 0.995; H = W / aspect; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(cx - W, cx + W, cy - H, cy + H); drawSincFunc(); } } void myInit(void) { glClearColor(1.0, 1.0, 1.0, 0.0); glColor3f(1.0f, 0.0f, 0.0f); glPointSize(4.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, 640.0, 0.0, 480.0); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(640, 480); glutInitWindowPosition(100, 150); glutCreateWindow(argv[0]); myInit(); glutDisplayFunc(myDisplay); glutMainLoop(); return 0; }