当前位置:网站首页>OpenGL三维图形绘制
OpenGL三维图形绘制
2022-07-07 06:18:00 【这辈子秃头是不可能的】
#include "stdafx.h"
#include<GL\glut.h>
#include<gl\glut.h>
#include<GL\glaux.h>
static GLsizei iMode = 1;
static GLfloat xRot = 0;
static GLfloat yRot = 0;
GLUquadricObj *obj;
void Initial(){
glClearColor(1, 1, 1, 1);
glColor3f(0, 0, 0);
obj = gluNewQuadric();
gluQuadricDrawStyle(obj, GLU_LINE);
}
void ChangeSize(int w, int h){
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1.5, 1.5, -1.5, 1.5);
}
void Display(){
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(xRot, 1, 0, 0);
glRotatef(yRot, 0, 1, 0);
switch (iMode){
case 1:
glutWireTetrahedron(); break;
case 2:
glutSolidTetrahedron(); break;
case 3:
glutWireOctahedron(); break;
case 4:
glutSolidOctahedron(); break;
case 5:
glutWireSphere(1, 15, 15); break;
case 6:
glutSolidSphere(1, 15, 15); break;
case 7:
glutWireTeapot(1); break;
case 8:
glutSolidTeapot(1); break;
case 9:
gluSphere(obj, 1, 15, 15); break;
case 10:
gluCylinder(obj, 1, 0, 1, 15, 15); break;
case 11:
gluPartialDisk(obj, 0.3, 0.8, 15, 15, 30, 260); break;
default: break;
}
glFlush();
}
void ProcessMenu(int value){
iMode = value;
glutPostRedisplay();
}
void SpecialKeys(int key, int x, int y){
if (key == GLUT_KEY_UP) xRot -= 5;
if (key == GLUT_KEY_DOWN) xRot += 5;
if (key == GLUT_KEY_LEFT) yRot -= 5;
if (key == GLUT_KEY_RIGHT) yRot += 5;
if (xRot > 356) xRot = 0;
if (xRot < -1) xRot = 355;
if (yRot > 356) yRot = 0;
if (yRot < -1) yRot = 355;
glutPostRedisplay();
}
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(400, 400);
glutInitWindowPosition(100, 100);
glutCreateWindow("Hello");
int nGlutPolyMenu = glutCreateMenu(ProcessMenu);
glutAddMenuEntry("线框正四面体", 1);
glutAddMenuEntry("实体正四面体", 2);
glutAddMenuEntry("线框正八面体", 3);
glutAddMenuEntry("实体正八面体", 4);
int nGlutCurveMenu = glutCreateMenu(ProcessMenu);
glutAddMenuEntry("线框球面", 5);
glutAddMenuEntry("实体球面", 6);
glutAddMenuEntry("线框茶壶", 7);
glutAddMenuEntry("实体茶壶", 8);
int nGluCurveMenu = glutCreateMenu(ProcessMenu);
glutAddMenuEntry("线框球面", 9);
glutAddMenuEntry("线框圆锥面", 10);
glutAddMenuEntry("线框圆环面", 11);
int nMainMenu = glutCreateMenu(ProcessMenu);
glutAddSubMenu("GLUT多面体", nGlutPolyMenu);
glutAddSubMenu("GLUT曲面", nGlutCurveMenu);
glutAddSubMenu("GLU曲面", nGluCurveMenu);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutDisplayFunc(Display);
glutReshapeFunc(ChangeSize);
glutSpecialFunc(SpecialKeys);
Initial();
glutMainLoop();
}
用vs2013编写,运行后单机右键会展开菜单
边栏推荐
- 为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾
- 【踩坑】nacos注册一直连接localhost:8848,no available server
- 求有符号数的原码、反码和补码【C语言】
- redis故障处理 “Can‘t save in background: fork: Cannot allocate memory“
- Esp32-ulp coprocessor low power mode RTC GPIO interrupt wake up
- Qt Charts使用(重写QChartView,实现一些自定义功能)
- Speaking of a software entrepreneurship project, is there anyone willing to invest?
- Markdown editor Use of MD plug-in
- Greenplum 6.x version change record common manual
- Test pits - what test points should be paid attention to when adding fields to existing interfaces (or database tables)?
猜你喜欢

详解华为应用市场2022年逐步减少32位包体上架应用和策略

Greenplum6.x-版本变化记录-常用手册

Category of IP address

Greenplum6.x搭建_环境配置

Platformization, a fulcrum of strong chain complementing chain

Compilation and linking of programs

Three series of BOM elements

oracle一次性说清楚,多种分隔符的一个字段拆分多行,再多行多列多种分隔符拆多行,最终处理超亿亿。。亿级别数据量
![FPGA knowledge accumulation [6]](/img/db/c3721c3e842ddf4c1088a3f54e9f2a.jpg)
FPGA knowledge accumulation [6]

idea里使用module项目的一个bug
随机推荐
JS operation
最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
[step on the pit] Nacos registration has been connected to localhost:8848, no available server
cmake命令行使用
Speaking of a software entrepreneurship project, is there anyone willing to invest?
Novice entry SCM must understand those things
GoLand set goproxy
如何在图片的目标中添加目标的mask
JS的操作
[Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology
PPT模板、素材下载网站(纯干货,建议收藏)
Componentspace2022, assertions, protocols, bindings, and configuration files
Gson converts the entity class to JSON times declare multiple JSON fields named
Find the original code, inverse code and complement of signed numbers [C language]
更改当前文件夹及文件夹下文件日期shell脚本
ESP32-ULP协处理器低功耗模式RTC GPIO中断唤醒
Analysis of abnormal channel number information before and after AGC re signature service
南京商品房买卖启用电子合同,君子签助力房屋交易在线网签备案
Problems encountered in the use of go micro
NCS Chengdu Xindian interview experience