OpenGL 旋转的小旗

// lab-basis.cpp : 定义应用程序的入口点。

#include "stdafx.h"
#include "labtwo-basis.h"

#define PI 3.14159

int n = 6, R = 10;

float cx = 0, cy = 0; // 平移量

float theta = 0.0;    // 旋转角度

void Display(void);						// 回显函数
void Reshape(int w, int h);				// 窗口改变函数
void myidle();						    // 闲时函数



int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

	char* argv[] = {"hello ", " "};
	int argc = 2;
	glutInit(&argc,argv);
	glutInitWindowSize(600,600);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutCreateWindow("A Rotating Square");
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutIdleFunc(myidle);
	glutMainLoop();

	return 0;
}

void Display()
{
	glClear(GL_COLOR_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glTranslatef(cx,cy,0);    // 平移
	glRotatef(theta,0,0,1);   // 旋转
	glTranslatef(-cx,-cy,0);  // 平移
	glColor3f(1,1,1);
        // 画线
	glBegin(GL_LINES);
	glVertex2f(0,0);
	glVertex2f(0,10);
	glEnd();
        // 画三角形
	glColor3f(1,0,0);
	glBegin(GL_POLYGON);
	glVertex2f(0,5);
	glVertex2f(0,10);
	glVertex2f(5,10);
	glEnd();
	glutSwapBuffers();
}

void myidle()
{
	theta += 0.2;
	if(theta >= 360) theta -= 360;
	glutPostRedisplay();
}

void Reshape(int w,int h)
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(-1.5*R*w/h,1.5*R*w/h,-1.5*R,1.5*R);
	glViewport(0,0,w,h);
	glMatrixMode(GL_MODELVIEW);
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值