当前位置:网站首页>OpenGL 3D graphics rendering
OpenGL 3D graphics rendering
2022-07-07 08:54:00 【Baldness is impossible in this life】
#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(" Wire frame tetrahedron ", 1);
glutAddMenuEntry(" Solid tetrahedron ", 2);
glutAddMenuEntry(" Wireframe regular octahedron ", 3);
glutAddMenuEntry(" Solid regular octahedron ", 4);
int nGlutCurveMenu = glutCreateMenu(ProcessMenu);
glutAddMenuEntry(" Wireframe sphere ", 5);
glutAddMenuEntry(" Solid sphere ", 6);
glutAddMenuEntry(" Wireframe teapot ", 7);
glutAddMenuEntry(" Solid teapot ", 8);
int nGluCurveMenu = glutCreateMenu(ProcessMenu);
glutAddMenuEntry(" Wireframe sphere ", 9);
glutAddMenuEntry(" Wireframe cone ", 10);
glutAddMenuEntry(" Wireframe torus ", 11);
int nMainMenu = glutCreateMenu(ProcessMenu);
glutAddSubMenu("GLUT Polyhedron ", nGlutPolyMenu);
glutAddSubMenu("GLUT Surfaces ", nGlutCurveMenu);
glutAddSubMenu("GLU Surfaces ", nGluCurveMenu);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutDisplayFunc(Display);
glutReshapeFunc(ChangeSize);
glutSpecialFunc(SpecialKeys);
Initial();
glutMainLoop();
}
use vs2013 To write , After running, right-click the stand-alone to expand the menu
边栏推荐
- JS operation
- Appeler l'interface du moteur de création du service multimédia de jeu Huawei renvoie le Code d'erreur 1002, le message d'erreur: les paramètres sont l'erreur
- 平台化,强链补链的一个支点
- go mod module declares its path as: gtihub. com/xxx-xx but was required as:xx-xx
- ncs成都新電面試經驗
- 阿里p8推荐,测试覆盖率工具—Jacoco,实用性极佳
- Mock.js用法详解
- 模拟卷Leetcode【普通】1706. 球会落何处
- Greenplum6.x监控软件搭建
- Calf problem
猜你喜欢
Other 7 features of TCP [sliding window mechanism ▲]
PPT模板、素材下载网站(纯干货,建议收藏)
Rapid integration of authentication services - harmonyos platform
The longest ascending subsequence model acwing 1017 Strange thief Kidd's glider
Count sort (diagram)
Digital triangle model acwing 275 Pass a note
IP地址的类别
Category of IP address
Explain Huawei's application market in detail, and gradually reduce 32-bit package applications and strategies in 2022
Output a spiral matrix C language
随机推荐
調用華為遊戲多媒體服務的創建引擎接口返回錯誤碼1002,錯誤信息:the params is error
Redis fault handling "can't save in background: fork: cannot allocate memory“
PPT模板、素材下载网站(纯干货,建议收藏)
对API接口或H5接口做签名认证
模拟卷Leetcode【普通】1567. 乘积为正数的最长子数组长度
Unity Shader入门精要初级篇(一)-- 基础光照笔记
Greenplum 6.x monitoring software setup
Count sort (diagram)
[Yugong series] February 2022 U3D full stack class 008 - build a galaxy scene
Enterprise manager cannot connect to the database instance
Esp32-ulp coprocessor low power mode RTC GPIO interrupt wake up
Gson转换实体类为json时报declares multiple JSON fields named
为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾
阿里p8推荐,测试覆盖率工具—Jacoco,实用性极佳
Greenplum6.x重新初始化
LeetCode 736. LISP syntax parsing
【Istio Network CRD VirtualService、Envoyfilter】
Nanjing commercial housing sales enabled electronic contracts, and Junzi sign assisted in the online signing and filing of housing transactions
[wechat applet: cache operation]
[step on the pit] Nacos registration has been connected to localhost:8848, no available server