当前位置:文档之家› 计算机图形学实验报告,DOC

计算机图形学实验报告,DOC

{
glClearColor(1.0f,1.0f,1.0f,0.0f);
glLineWidth(12.0f);
glColor4f(0.0,0.6,1.0,1.0);
lineList=glGenLists(1);//获得一个显示列表标识
glNewList(lineList,GL_COMPILE);//定义显示列表
glVertex2f(x,y);
if(d<0)d+=2*x+3;
else{
d+=2*(x-y)+5;
y--;
}
x++;
}
glEnd();
}
voiddisplay()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
glClear(GL_COLOR_BUFFER_BIT);
winWidth=newWidth;
winHeight=newHeight;
}
intmain(intargc,char*argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glBegin(GL_POINTS);
glVertex2i(int(x+0.5),(int)(y+0.5));
glEnd();
x+=xIncre;
y+=yIncre;
}
}
voidDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
DDALine(100,,200,180);
gluOrtho2D(0.0,200.0,0.0,150.0);
}
voidDDALine(intx0,inty0,intx1,inty1)
{
glColor3f(1.0,0.0,0.0);
intdx,dy,epsl,k;
floatx,y,xIncre,yIncre;
dx=x1-x0;dy=y1-y0;
glEnd();
}
}
voidinit(void)
{
glClearColor(1.0,1.0,1.0,1.0);
glShadeModel(GL_FLAT);
}
voiddisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
lineBres(10,10,400,300);
glFlush();
}
voidwinReshapeFcn(GLintnewWidth,GLintnewHeight)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,GLdouble(newWidth),0.0,GLdouble(newHeight));
glutReshapeFunc(reshape);
glutMainLoop();
return0;
}
实验三反走样及五环的绘制
一、【实验目的】
1.了解走样和反走样的内容,熟练掌握用opengl实现图形的反走样。?
2.学会用反走样消除走样现象。
3.学会五环的绘制方法。
二、【实验内容】
1.通过学习反走样相关课程,用opengl实现光栅图形的反走样。
实验一直线的DDA算法
一、【实验目的】
1.掌握DDA算法的基本原理。
2.掌握DDA直线扫描转换算法。
3.深入了解直线扫描转换的编程思想。
二、【实验内容】
1.利用DDA的算法原理,编程实现对直线的扫描转换。
2.加强对DDA算法的理解和掌握。
三、

#include<stdlib.h>
#include<math.h>
glutInitWindowPosition(10,10);
glutInitWindowSize(winWidth,winHeight);
glutCreateWindow("lineBres");
init();
glutDisplayFunc(display);
glutReshapeFunc(winReshapeFcn);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(400,400);
glutInitWindowPosition(100,100);
glutCreateWindow("扫描转换圆");
glutDisplayFunc(display);
glMatrixMode(GL_MODELVIEW);//指定设置模型视图变换参数
glLoadIdentity();
}
voidDisplayt(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glCallList(lineList);//调用显示列表
glFlush();
}
voidDisplayw(void){
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_LINE_SMOOTH);//使用反走样
glEnable(GL_BLEND);//启用混合函数
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);//指定混合函数
glCallList(lineList);//调用显示列表
glutReshapeFunc(ChangeSize);
#include<GL/glut.h>
#include<stdio.h>
GLsizeiwinWidth=500;
GLsizeiwinHeight=500;
voidInitial(void)
{
glClearColor(1.0f,1.0f,1.0f,1.0f);
glMatrixMode(GL_PROJECTION);
glBegin(GL_LINE_LOOP);
glVertex2f(1.0f,1.0f);
glVertex2f(4.0f,2.0f);
glVertex2f(2.0f,5.0f);
glEnd();
glEndList();
}
voidChangeSize(GLsizeiw,GLsizeih)
{
if(h==0)h=1;
glutInitWindowSize(400,300);
glutInitWindowPosition(100,120);
glutCreateWindow("line");
Initial();
glutDisplayFunc(Display);
glutReshapeFunc(winReshapeFcn);
MidBresenhamCircle(8);
glRotated(45,0,0,1);
MidBresenhamCircle(8);
glRotated(45,0,0,1);
MidBresenhamCircle(8);
glRotated(45,0,0,1);
MidBresenhamCircle(8);
glutSwapBuffers();
glFlush();
}
voidmain(void)
{
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(300,300);
glutCreateWindow("原始图形");
glutDisplayFunc(Displayt);
glutReshapeFunc(ChangeSize);
}
voidreshape(intw,inth)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-10,10,-10,10);
}
intmain(intargc,char**argv)
{
glutInit(&argc,argv);
glClear(GL_COLOR_BUFFER_BIT);
winWidth=newWidth;
winHeight=newHeight;
}
voidmain(intargc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
#include<math.h>
#include<GL/glut.h>
#include<stdio.h>
GLsizeiwinWidth=500;
GLsizeiwinHeight=500;
voidlineBres(intx0,inty0,intxEnd,intyEnd)
{
glColor3f(0.0,0.0,1.0);
MidBresenhamCircle(8);
glRotated(45,0,0,1);
MidBresenhamCircle(8);
glRotated(45,0,0,1);
MidBresenhamCircle(8);
相关主题