图形学实验代码

#include<GL/glut.h>
void myDisplay(void)
{
	glClearColor(0.0,0.0,0.0,0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	glColor3f(1.0f,1.0f,1.0f);
	glRectf(-0.5f,-0.5f,0.5f,0.5f);

	glBegin (GL_TRIANGLES);				//画三角形
	glColor3f(1.0f,0.0f,0.0f);	glVertex2f(0.0f,1.0f);
	glColor3f(0.0f,1.0f,0.0f);	glVertex2f(0.8f,-0.5f);
	glColor3f(0.0f,0.0f,1.0f);	glVertex2f(-0.8f,-0.5f);
	glEnd();

	glPointSize(3);										
	glBegin(GL_POINTS);
	glColor3f(1.0f,0.0f,0.0f);	glVertex2f(-0.4f,-0.4f);
	glColor3f(0.0f,1.0f,0.0f);	glVertex2f(0.0f,0.0f);
	glColor3f(0.0f,0.0f,1.0f);	glVertex2f(0.4f,0.4f);
	glEnd();

	glFlush();
}
int main(int argc,char *argv[])
{
	glutInit (&argc,argv);
	glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);
	glutInitWindowPosition(100,100);
	glutInitWindowSize(400, 400);
	glutCreateWindow("Hello world!");
	glutDisplayFunc(&myDisplay);
	glutMainLoop();
	return 0;
}


#include<GL/glut.h>
void myDisplay(void)
{
	glClearColor(0.0,0.0,0.0,0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	glColor3f(1.0f,1.0f,1.0f);
	glRectf(-0.5f,-0.5f,0.5f,0.5f);

	glBegin (GL_TRIANGLES);
	glColor3f(1.0f,0.0f,0.0f);	glVertex2f(0.0f,1.0f);
	glColor3f(0.0f,1.0f,0.0f);	glVertex2f(0.8f,-0.5f);
	glColor3f(0.0f,0.0f,1.0f);	glVertex2f(-0.8f,-0.5f);
	glEnd();

	glPointSize(3);
	glBegin(GL_POINTS);
	glColor3f(1.0f,0.0f,0.0f);	glVertex2f(-0.4f,-0.4f);
	glColor3f(0.0f,1.0f,0.0f);	glVertex2f(0.0f,0.0f);
	glColor3f(0.0f,0.0f,1.0f);	glVertex2f(0.4f,0.4f);
	glEnd();

	glFlush();
}
int main(int argc,char *argv[])
{
	glutInit (&argc,argv);
	glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);
	glutInitWindowPosition(100,100);
	glutInitWindowSize(400, 400);
	glutCreateWindow("Hello world!");
	glutDisplayFunc(&myDisplay);
	glutMainLoop();
	return 0;
}
void LineDDA(int x0,int y0,int x1,int y1/*,int color */)
{
	int x,dy,dx,y;
	float m;
	dx=x1-x0;
	dy=y1-y0;
	m=dy/dx;
	y=y0;

	glColor3f(1.0f,1.0f,0.0f);
	glPointSize(1);
	for(x=x0;x<=x1;x++)
	{
		glBegin(GL_POINTS);
		glVertex2i(x,(int)(y+0.5));
		glEnd();
		y+=m;
	}
}
void myDisplay(void)
{
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0f,0.0f,0.0f);
	glRectf(25.0,25.0,75.0,75.0);

	glPointSize(5);
	glBegin(GL_POINTS);
	glColor3f(0.0f,1.0f,0.0f); glVertex2f(0.0f,0.0f);
	glEnd();

	LineDDA(0, 0, 200, 300);


		glPointSize(13);
		glBegin(GL_POINTS);
			glColor3f(1.0f,1.0f,0.0f);
			glVertex2i(100,100);
			glEnd();

	glBegin(GL_LINES);
	glColor3f(1.0f,1.0f,0.0f);glVertex2f(100.0f,0.0f);
	glColor3f(0.0f,1.0f,0.0f);glVertex2f(180.0f,240.0f);
	glEnd();
	glFlush();
}
void Init()
{
	glClearColor(0.0,0.0,0.0,0.0);
	glShadeModel(GL_FLAT);
}
void Reshape(int w,int h)
{
	glViewport(0,0,(GLsizei) w,(GLsizei) h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0,(GLdouble) w,0.0,(GLdouble) h);
}
int main(int argc,char *argv[])
{
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
	glutInitWindowPosition(100,100);
	glutInitWindowSize(400,400);
	glutCreateWindow("Hellow World!");
	Init();
	glutDisplayFunc(myDisplay);
	glutReshapeFunc(Reshape);
	glutMainLoop();
	return 0;
}

#include<GL/glut.h>
void LineDDA(int x0,int y0,int x1,int y1/*,int color */)
{
	int x,dy,dx,y;
	float m;
	dx=x1-x0;
	dy=y1-y0;
	m=dy/dx;
	y=y0;

	glColor3f(1.0f,1.0f,0.0f);
	glPointSize(1);
	for(x=x0;x<=x1;x++)
	{
		glBegin(GL_POINTS);
		glVertex2i(x,(int)(y+0.5));
		glEnd();
		y+=m;
	}
}
void myDisplay(void)
{
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0f,0.0f,0.0f);
	glRectf(25.0,25.0,75.0,75.0);

	glPointSize(5);
	glBegin(GL_POINTS);
	glColor3f(0.0f,1.0f,0.0f); glVertex2f(0.0f,0.0f);
	glEnd();

	LineDDA(0, 0, 200, 300);
		glPointSize(13);
		glBegin(GL_POINTS);
			glColor3f(1.0f,1.0f,0.0f);
			glVertex2i(100,100);
			glEnd();

	glBegin(GL_LINES);
	glColor3f(1.0f,1.0f,0.0f);glVertex2f(100.0f,0.0f);
	glColor3f(0.0f,1.0f,0.0f);glVertex2f(180.0f,240.0f);
	glEnd();
	glFlush();
}

void Init()
{
	glClearColor(0.0,0.0,0.0,0.0);
	glShadeModel(GL_FLAT);
}

void Reshape(int w,int h)
{
	glViewport(0,0,(GLsizei) w,(GLsizei) h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0,(GLdouble) w,0.0,(GLdouble) h);
}

int main(int argc,char *argv[])
{
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
	glutInitWindowPosition(100,100);
	glutInitWindowSize(400,400);
	glutCreateWindow("Hellow World!");
	Init();
	glutDisplayFunc(myDisplay);
	glutReshapeFunc(Reshape);
	glutMainLoop();
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值