#include
#include
const int screenWidth = 640;
// width of screen window in pixels
const int screenHeight = 480;
// height of screen window in pixels
GLdouble A, B, C, D;// values used for scaling and shifting
//Setup the rendering state
void SetupRC(void)
{
glClearColor(1.0,1.0,1.0,0.0);
// set white background color
glColor3f(1.0f, 0.0f, 0.0f);
// set the drawing color
glPointSize(4.0);
//size of point is 4 by 4 pixels
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 160.0, 0.0, 480.0);
A = screenWidth / 4.0; // set values used for scaling and shifting
B = 0.0;
C = D = screenHeight / 2.0;
}
void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT);
// clear the screen
glBegin(GL_LINE_STRIP);
//glBegin(GL_POINTS);
for(GLdouble x=0.0; x<4.0; x+=0.005)
{
GLdouble func=sin(2*3.14159265*x);
glVertex2d(A * x + B, C * func + D);
}
glEnd();
glFlush();
// send all output to display
}
// Main program entry point
void main(void)
{
//glutInit(&argc, argv);
// initialize the toolkit
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set display mode
glutInitWindowSize(640, 480); // set window size
glutInitWindowPosition(100, 150); // set window position on screen
glutCreateWindow("正弦曲线的绘制方法"); // open the screen window
glutDisplayFunc(RenderScene);
// register redraw function
SetupRC();
glutMainLoop();
// go into a perpetual loop
}
|