OpenGL画图

来源:百度知道 编辑:UC知道 时间:2024/06/25 01:32:58
程序:void CMyWaveView::DrawWave(void)
{

glNewList (listName, GL_COMPILE_AND_EXECUTE); GLfloat x;
glBegin(GL_LINE_STRIP);
glColor3f(0.0,0.0,0.0);
for(x=-1.0f; x<=-0.875f; x+=0.001f)
{
glVertex2f(x,/* random()**/0.5*sin(8.0*Pi*x));
}
glEnd();

glBegin(GL_LINES);
glVertex2f(-0.875f,0.2*sin(4*Pi*(-0.75f)));
glVertex2f(-0.70,0.1f/*0.4*sin((double)4*Pi*(-0.75f))*/);
glEnd();

glBegin(GL_LINES);
glVertex2f(-0.70f,0.1f/*0.5*sin((double)4*Pi*(-0.75f))*/);
glVertex2f(-0.65f,0.2*sin(4*Pi*(-0.75f)));
glEnd();

glBegin(GL_LINES);
glVertex2f(-0.65f,0.2*sin(4*Pi*(-0.75f)));
glVertex2f(-0.60,0.1f/*0.4*sin((double)4*Pi*(-0.75f))*/);
glEnd();

glBegin(GL_LINES);
glVertex2f(-0.60f,0.1f/*0.5*sin((double)4*Pi*(-0.75f))*/);
glVertex2f(-0.55f,

这是我自己环境下的代码

#include "stdafx.h"

#include<windows.h> 

#include"glut.h" 

#include <math.h>

#define Pi 3.1415926

void myInit(void) 

 glClearColor(1.0, 1.0, 1.0, 1.0); 

void DrawWave() 

 glClear(GL_COLOR_BUFFER_BIT);

 GLuint listName; 

 listName = glGenLists(1); 

 glNewList (listName, GL_COMPILE_AND_EXECUTE); 

 GLfloat x; 

 glBegin(GL_LINE_STRIP); 

 glColor3f(1.0,0.0,0.0); 

 for(x=-1.0f; x<=-0.875f; x+=0.001f) 

 { 

  glVertex2f(x,/* random()**/0.5*sin(8.0*Pi*x)); 

 } 

 glEnd(); 

 glBegin(GL_LINES); 

 glVertex2f(-0.875f,0.2*sin(4