#include "stdafx.h"
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h> const GLfloat factor = 0.1f;
void myDisplay(void) {
GLfloat x;
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINES);
glVertex2f(-1.0f, 0.0f);
glVertex2f(1.0f, 0.0f);
glVertex2f(0.0f, -1.0f);
glVertex2f(0.0f, 1.0f);
glEnd();
glBegin(GL_LINE_STRIP);
for (x = -1.0f / factor; x<1.0f / factor; x += 0.01f) {
glVertex2f(x*factor, sin(x)*factor);
}
glEnd();
glFlush();
} int main(int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(, );
glutInitWindowSize(, );
glutCreateWindow("OpenGL正弦函数图像程序");
glutDisplayFunc(&myDisplay);
glutMainLoop();
return ;
}
运行结果如下图所示: