计算机图形学实验报告Word文档下载推荐.docx
- 文档编号:16027872
- 上传时间:2022-11-17
- 格式:DOCX
- 页数:32
- 大小:133.89KB
计算机图形学实验报告Word文档下载推荐.docx
《计算机图形学实验报告Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《计算机图形学实验报告Word文档下载推荐.docx(32页珍藏版)》请在冰豆网上搜索。
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(10.0f,0.0f,0.0f);
glEnd();
点的属性(大小)
voidglPointSize(GLfloatsize);
直线的绘制模式
GL_LINES
GL_LINE_STRIP
GL_LINE_LOOP
直线的属性
线宽
voidglLineWidth(GLfloatwidth)
线型
glEnable(GL_LINE_STIPPLE);
glLineStipple(GLintfactor,GLushortpattern);
三角形面的绘制
GL_TRIANGLES
GL_TRIANGLE_STRIP
GL_TRIANGLE_FAN
四边形面的绘制
GL_QUADS
GL_QUADS_STRIP
多边形面的绘制(GL_POLYGON)
多边形面的绘制规则
所有多边形都必须是平面的。
多边形的边缘决不能相交,而且多边形必须是凸的。
解决:
对于非凸多边形,可以把它分割成几个凸多边形(通常是三角形),再将它绘制出来。
3.实验代码与实验结果
(1)画矩形
#include<
gl/glut.h>
voidInitial(void){
glClearColor(1.0f,1.0f,1.0f,1.0f);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0,200.0,0.0,150.0);
}
voidDisplay(void){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f,0.0f,0.0f);
glRectf(50.0f,100.0f,150.0f,50.0f);
glFlush();
intmain(intargc,char*argv[]){
glutInit(&
argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(400,300);
glutInitWindowPosition(100,120);
glutCreateWindow("
矩形"
);
glutDisplayFunc(Display);
Initial();
glutMainLoop();
return0;
(2)画点
glPointSize(3);
glBegin(GL_POINTS);
glColor3f(1.0f,0.0f,0.0f);
glVertex2i(10,140);
glVertex2i(100,75);
glVertex2i(190,10);
glEnd();
(3)画直线
glBegin(GL_LINE_LOOP);
glVertex2i(20,10);
glVertex2i(60,50);
glVertex2i(20,50);
glVertex2i(60,10);
glVertex2i(40,70);
(4)画等边三角形
glBegin(GL_TRIANGLES);
glVertex2i(60,10);
glVertex2f(40.0,44.64);
实验二直线绘制实验
1.实验目的和实验内容
(1)掌握数值微分算法编程绘制直线
(2)掌握中点画线算法编程绘制直线
(3)掌握Bresenham算法编程绘制直线
2.实验代码和实验结果
math.h>
glPointSize(3);
intdx,dy,epsl,k;
floatx,y,xIncre,yIncre;
intx0=10;
inty0=10;
intx1=20;
inty1=80;
dx=x1-x0;
dy=y1-y0;
x=x0;
y=y0;
if(abs(dx)>
abs(dy))
epsl=abs(dx);
else
epsl=abs(dy);
xIncre=(float)dx/(float)epsl;
yIncre=(float)dy/(float)epsl;
for(k=0;
k<
=epsl;
k++){
glBegin(GL_POINTS);
glVertex2i(int(x+0.5),(int)(y+0.5));
glEnd();
x+=xIncre;
y+=yIncre;
}
intdx,dy,d,UpIncre,DownIncre,x,y;
intx1=80;
inty1=20;
if(x0>
x1){
x=x1;
x1=x0;
x0=x;
y=y1;
y1=y0;
y0=y;
y=y0;
dy=y1-y0;
d=dx-2*dy;
UpIncre=2*dx-2*dy;
DownIncre=-2*dy;
while(x<
=x1){
glVertex2f(x,y);
x++;
if(d<
0){
y++;
d+=UpIncre;
}
else
d+=DownIncre;
intx,y,dx,dy,e;
e=-dx;
x=x0;
e=e+2*dy;
if(e>
e=e-2*dx;
实验三圆绘制实验
(1)实现八分法画圆程序
(2)实现Bresenham算法绘制圆
(3)实现中点Bresenham算法绘制椭圆
2.实验代码实验结果
voidputpixel(intx,inty){
x+=20;
y+=20;
glVertex2i(x,y);
voidCirclePoint(intx,inty){
putpixel(x,y);
putpixel(y,x);
putpixel(-y,x);
putpixel(-x,y);
putpixel(-x,-y);
putpixel(-y,-x);
putpixel(y,-x);
putpixel(x,-y);
CirclePoint(5,2);
gluOrtho2D(0.0,200.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 图形学 实验 报告
![提示](https://static.bdocx.com/images/bang_tan.gif)