opengl绘制正弦曲线

利用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;
}

 曲线如图:

 

态度决定高度,细节决定成败,
原文地址:https://www.cnblogs.com/lxk2010012997/p/3583450.html