opengl 绘制正弦曲线,用流水线技术描述绘制过程,在线等,代码如下

[复制链接]
查看11 | 回复1 | 2011-5-10 13:49:15 | 显示全部楼层 |阅读模式
#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

}

回复

使用道具 举报

千问 | 2011-5-10 13:49:15 | 显示全部楼层
建议去看一下《OPENGL编程指南》或者网上有名的电子教程《NEHE的教程》,可以有个系统的了解,不难。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行