当前位置:网站首页>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编写,运行后单机右键会展开菜单
边栏推荐
- QT charts use (rewrite qchartview to realize some custom functions)
- Several methods of calculating the average value of two numbers
- Image segmentation in opencv
- Explain Huawei's application market in detail, and gradually reduce 32-bit package applications and strategies in 2022
- go mod module declares its path as: gtihub. com/xxx-xx but was required as:xx-xx
- Nanjing commercial housing sales enabled electronic contracts, and Junzi sign assisted in the online signing and filing of housing transactions
- 指针进阶,字符串函数
- 【MySQL】数据库进阶之触发器内容详解
- Routing information protocol rip
- 【微信小程序:缓存操作】
猜你喜欢
Oracle makes it clear at one time that a field with multiple separators will be split into multiple rows, and then multiple rows and columns. Multiple separators will be split into multiple rows, and
All about PDF crack, a complete solution to meet all your PDF needs
NCS Chengdu New Electric interview Experience
Recommended by Alibaba P8, the test coverage tool - Jacobo is very practical
【MySQL】数据库进阶之触发器内容详解
FPGA knowledge accumulation [6]
如何在快应用中实现滑动操作组件
PPT模板、素材下载网站(纯干货,建议收藏)
登山小分队(dfs)
Why choose cloud native database
随机推荐
年薪50w阿裏P8親自下場,教你如何從測試進階
How to integrate app linking services in harmonyos applications
Rapid integration of authentication services - harmonyos platform
Analysis of abnormal channel number information before and after AGC re signature service
cmake命令行使用
Why choose cloud native database
IP地址的类别
Other 7 features of TCP [sliding window mechanism ▲]
JS operation
Quick sorting (detailed illustration of single way, double way, three way)
[南京大学]-[软件分析]课程学习笔记(一)-introduction
[Yugong series] February 2022 U3D full stack class 008 - build a galaxy scene
平台化,强链补链的一个支点
如何在快应用中实现滑动操作组件
[Yugong series] February 2022 U3D full stack class 006 unity toolbar
LeetCode 736. LISP syntax parsing
Greenplum 6.x build_ Environment configuration
实现自定义内存分配器
systemd
Redis fault handling "can't save in background: fork: cannot allocate memory“