使用OpenGL(GLUT)显示一个时钟

这篇博客展示了如何利用OpenGL和GLUT库在窗口中央创建一个可交互的时钟。点击右键时钟开始运行,通过拖动鼠标左键可以调整时间。详细源代码在文章中给出。
摘要由CSDN通过智能技术生成

效果

在窗口中央显示一个时钟,单击鼠标右键时钟开始走时;按住鼠标左键上下移动可以调节时刻。
初始效果

源代码

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

#define HOURHAND (handtype)0
#define MINUTEHAND (handtype)1
#define SECONDHAND (handtype)2
typedef unsigned handtype;

const double Pi = 3.1415926535;
bool leftmousedown = false;
bool clockloop = false; //时钟开始走
int winwidth = 800;
int winheight = 800;
const int CLOCKRADIUS = 120;
const int HOURWIDTH = 5;
const int HOURLENGTH = 55;
const int MINUTEWIDTH = 3;
const int MINUTELENGTH = 80;
const int SECONDWIDTH = 2;
const int SECONDLENGTH = 105;
double hourdegree = 0.0;
double minutedegree = 0.0;
double seconddegree = 0.0;
int xlast = 0, ylast = 0;

void Timer(int);
void Mouse(int, int, int, int);
void Motion(int, int y);
void DrawCircle(int, int x = round(winwidth / 2), int y = round(winheight / 2));
void DrawHand(handtype, int x = round(winwidth / 2), int y = round(winheight / 2));
void Display();
void ChangeSize(int, int);

void Display() {
   
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0, winwidth, 0,<
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值