利用opengl绘制正弦曲线 ,见代码:
#include <windows.h>
//#include <GLUT/glut.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
const GLfloat factor=0.1f; void MyDisplay()
{
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(100,100);
glutInitWindowSize(400,400);
glutCreateWindow("opengl程序");
glutDisplayFunc(&MyDisplay);
glutMainLoop();
return 0;
}
曲线如图: