本文作者:StubbornHuang
版权声明:本文为站长原创文章,如果转载请注明原文链接!
原文标题:OpenGL地球与太阳绕转代码
原文链接:https://www.stubbornhuang.com/207/
发布于:2019年11月04日 23:30:43
修改于:2020年01月03日 9:44:43

1 代码示例
#define GLUT_DISABLE_ATEXIT_HACK
#include <stdlib.h>
#include <stdio.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
static int year=0,day=0;
void init(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glPushMatrix();
glutWireSphere(1.0,20,16);
glRotatef((GLfloat)year,0.0,1.0,0.0);
glTranslatef(2.0,0.0,0.0);
glRotatef((GLfloat)day,0.0,1.0,0.0);
glutWireSphere(0.2,10,8);
glPopMatrix();
glutSwapBuffers();
}
void reshape(int w,int h)
{
glViewport(0.0,0.0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0,(GLfloat)w/(GLfloat)h,1.0,20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,0.0,5.0,0.0,0.0,0.0,0.0,1.0,0.0);
}
void keyboard(unsigned char key,int x,int y)
{
switch(key){
case 'd':
day=(day+10)%360;
glutPostRedisplay();
break;
case 'D':
day=(day-10)%360;
glutPostRedisplay();
break;
case 'y':
year=(year+5)%360;
glutPostRedisplay();
break;
case 'Y':
year=(year-5)%360;
glutPostRedisplay();
break;
}
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
2 运行结果
当前分类随机文章推荐
- Modern OpenGL - GLSL着色语言2:GLSL入口函数和GLSL中的变量 阅读2096次,点赞0次
- OpenGL地球与太阳绕转代码 阅读2362次,点赞0次
- Modern OpenGL - GLSL着色语言4:GLSL中的数据存储限制符 阅读1635次,点赞0次
- Modern OpenGL从零开始 - 在Visual Studio中配置OpenGL开发环境 阅读1960次,点赞0次
- Modern OpenGL - GLSL着色语言3:GLSL中的数据类型 阅读1345次,点赞0次
- Modern OpenGL从零开始 - 从茫茫多的OpenGL第三方库讲起 阅读2919次,点赞1次
- Modern OpenGL - 与着色器Shader相关的API函数总结以及如何创建、编译与使用Shader 阅读177次,点赞0次
- Modern OpenGL从零开始 - 多个帧缓存Framebuffer绘制到同一个铺满屏幕四边形Quad上 阅读2147次,点赞1次
- OpenGL画四个三角形组成四面体,并进行旋转 阅读2589次,点赞0次
- Modern OpenGL从零开始 - Fbxsdk::FbxAMatrix转换为glm::mat4 阅读1956次,点赞0次
全站随机文章推荐
- 资源分享 - Unity Shader入门精要 PDF下载 阅读1091次,点赞0次
- 资源分享 - 游戏引擎架构,Game Engine Architecture 中文版PDF下载 阅读1318次,点赞0次
- Pac - OneDriver/OneNote Pac规则 阅读4324次,点赞3次
- 资源分享 - Game Engine Architecture (Third Edition)英文高清PDF下载 阅读4520次,点赞0次
- 资源分享 - WebGL Programming Guide - Interactive 3D Graphics Programming with WebGL 英文高清PDF下载 阅读741次,点赞0次
- Pytorch - torch.nn.Conv1d参数详解与使用 阅读87次,点赞0次
- Mediapipe - 将Mediapipe handtracking封装成动态链接库dll/so,实现在桌面应用中嵌入手势识别功能 阅读5668次,点赞14次
- Pac - 自定义Pac的编写和语法规则 阅读3810次,点赞0次
- Python - glob模块详解以及glob.glob、glob.iglob函数的使用 阅读114次,点赞0次
- 资源分享 - Digital Image Processing , Fourth Edition 英文高清PDF下载 阅读1325次,点赞0次
评论
150