OpenGl探索 1.0

#include <gl/glut.h>
#include <math.h>

//#pragma comment(linker,"/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
void WindowInit()//定义绘图窗口,
{
	glutInitDisplayMode(GLUT_SINGLE);//glut初始化 显示模式为显示器单缓存模式
	glutInitWindowPosition(100, 100);//glut初始化  窗口位置在100,100位置
	glutInitWindowSize(600, 600);//glut初始化  窗口像素大小为600,600
	glutCreateWindow("hello world");//设置标题
}

void SetupRc() //背景
{
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);  //清除颜色并且不透明
	glViewport(0, 0, 500, 500);             //左下角坐标是0,0 右上角坐标是500,500
	glOrtho(-1.0, 1.0, -1.0, 1.0, -2.0, 2.0); //空间坐标 左下角是-1,-1,-2 右上角是1,1,2
}

void RenderScene() //图形绘制
{
	glClear(GL_COLOR_BUFFER_BIT);//清除了颜色缓冲区内容
	glColor3f(0.0f, 1.0f, 0.0f);//作为前景也就是墨迹颜色
	glutWireTeapot(0.5);//画图0.5墨迹
	glFlush();   //刷屏显示
}

void teaport(int argc, char** argv)
{

	glutInit(&argc, argv);//初始化glut库 不然就没法用glut
	WindowInit();//窗口初始化 不然没有窗口 1.模式 2.位置 3.大小 4.标题
	SetupRc();//背景 不然没有背景 1.清除颜色 2.坐标 3.空间投影
	glutDisplayFunc(RenderScene);//注册回调函数 (1.清除颜色缓冲区 2.前景 3.茶壶 4.显示)
	glutMainLoop();//窗口循环等待操作

}



void sinxxijie()
{
	float angle_x, sinX;
	for (angle_x = -3.14; angle_x <= 3.14; angle_x += 0.005)
	{
		sinX = sin(angle_x);
		if (angle_x < 0)
			glColor3f(1.0, 0.5, 0.0);
		else
			glColor3f(1.0, 0.0, 1.0);
		glPointSize(2);
		glBegin(GL_POINTS);
		glVertex2f(angle_x, sinX);
		glEnd();
	}

	glFlush();
}



void mathsinX(int argc, char ** argv)
{

	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE);
	glutInitWindowPosition(100, 100);
	glutInitWindowSize(500, 500);
	glutCreateWindow("hello world!!");
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);
	//glColor3f(1.0f, 1.0f, 1.0f);
	glViewport(0, 0, 500, 500);
	gluOrtho2D(-6.28, 6.28, -1.5, 1.5);
	glutDisplayFunc(sinxxijie);


	glutMainLoop();

}
void arctanxx()
{




	float x, y;
	int n = 0;
	for (x = -314; x <= 314; x += 0.01)
	{
		n++;
		y = atan(x);
		if (n % 2 == 1)
			glColor3f(1.0f, 0.0f, 0.0f);
		else
			glColor3f(1.0f, 0.5f, 0.0f);
		glPointSize(2);
		glBegin(GL_POINTS);
		glVertex2f(x, y);
		glEnd();


	}

	glFlush();

}

void arctanX(int aa, char** ab)
{




	glutInit(&aa, ab);
	glutInitDisplayMode(GLUT_SINGLE);
	glutInitWindowPosition(100, 100);
	glutInitWindowSize(500, 500);
	glutCreateWindow("hello world");
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);
	//glColor3f(1.0f, 1.0f, 1.0f);
	glViewport(0, 0, 500, 500);
	gluOrtho2D(-10, 10, -5, 5);
	glutDisplayFunc(arctanxx);


	glutMainLoop();
}


void qunm()
{
	float x;
	float y1;
	float y2;
	float y3 = 3.14 / 2;
	float y4 = -3.14 / 2;
	float y5, y6, y7, y8, y9, y10a, y10b;
	float xx;
	int n = 0;
	for (x = -314; x <= 314; x += atan(x*x) * 0.05 + 0.02)
	{
		//x=x/314/314*0.2 

		n++;
		y1 = atan(x);
		y2 = sin(x / 100);
		if (x != 0) {
			y5 = 1 / x;
		}
		y7 = (0.6 + 0.6 * (x))*cos(x);
		y8 = x * x*x;
		xx = 3 * 1 * x / (1 + x * x * x);
		y9 = 3 * 1 * x*x / (1 + x * x * x);

		if (n % 2 == 1)
			glColor3f(1.0f, 0.0f, 0.0f);
		else
			glColor3f(0.0f, 0.0f, 1.0f);
		glPointSize(2);
		glBegin(GL_POINTS);
		glVertex2f(x, y1);
		glVertex2f(x, y2);
		glColor3f(0.0f, 1.0f, 0.0f);
		glVertex2f(x, y3);
		glVertex2f(x, y4);
		if (x != 0) {
			glColor3f(0.0f, 0.0f, 1.0f);
			glVertex2f(x, y5);
		}
		glColor3f(0.5f, 0.5f, 0.5f);
		glVertex2f((0.6 + 0.6 * (x))*sin(x), y7);

		glColor3f(0.7f, 0, 0);
		glVertex2f(x, y8);

		glColor3f(0, 1, 0);
		glVertex2f(xx, y9);

		if ((x*x / 2 - 1) >= 0) {
			y10a = sqrt(1 * (x*x / 2 - 1));
			y10b = -y10a;
			glColor3f(1, 1, 1);
			glVertex2f(x, y10a);
			glVertex2f(x, y10b);
		}




		glEnd();


	}

	glFlush();



}



void qunmo(int aa, char** ab)
{




	glutInit(&aa, ab);
	glutInitDisplayMode(GLUT_SINGLE);
	glutInitWindowPosition(100, 100);
	glutInitWindowSize(500, 500);
	glutCreateWindow("hello world");
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);
	//glColor3f(1.0f, 1.0f, 1.0f);
	glViewport(0, 0, 500, 500);
	gluOrtho2D(-10, 10, -5, 5);
	glutDisplayFunc(qunm);


	glutMainLoop();
}







int main(int argc, char** argv)
{
	//teaport(argc, argv);
	 //mathsinX(argc, argv);
	//arctanX(argc, argv);
	qunmo(argc, argv);


	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值