当前位置:网站首页>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编写,运行后单机右键会展开菜单
边栏推荐
- Greenplum6.x搭建_环境配置
- Greenplum 6.x build_ Environment configuration
- 【踩坑】nacos注册一直连接localhost:8848,no available server
- Rapid integration of authentication services - harmonyos platform
- Recommended by Alibaba P8, the test coverage tool - Jacobo is very practical
- ncs成都新電面試經驗
- let const
- Digital triangle model acwing 1027 Grid access
- Greenplum 6.x monitoring software setup
- Speaking of a software entrepreneurship project, is there anyone willing to invest?
猜你喜欢
Image segmentation in opencv
为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾
let const
Greenplum6.x搭建_安装
数字三角形模型 AcWing 275. 传纸条
Greenplum6.x常用语句
Calling the creation engine interface of Huawei game multimedia service returns error code 1002, error message: the params is error
[Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology
Introduction to data fragmentation
JS的操作
随机推荐
年薪50w阿裏P8親自下場,教你如何從測試進階
Other 7 features of TCP [sliding window mechanism ▲]
let const
Greenplum6.x监控软件搭建
oracle一次性说清楚,多种分隔符的一个字段拆分多行,再多行多列多种分隔符拆多行,最终处理超亿亿。。亿级别数据量
What are the advantages of commas in conditional statements- What is the advantage of commas in a conditional statement?
使用AGC重签名服务前后渠道号信息异常分析
Rapid integration of authentication services - harmonyos platform
如何统计项目代码行数
为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾
模拟卷Leetcode【普通】1609. 奇偶树
How to add a mask of a target in a picture
数据分析方法论与前人经验总结2【笔记干货】
【微信小程序:缓存操作】
[wechat applet: cache operation]
systemd
Enterprise manager cannot connect to the database instance
Quick sorting (detailed illustration of single way, double way, three way)
[Yugong series] February 2022 U3D full stack class 006 unity toolbar
Alibaba P8 teaches you how to realize multithreading in automated testing? Hurry up and stop