当前位置:网站首页>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
边栏推荐
- xray的简单使用
- 【微信小程序:缓存操作】
- About using CDN based on Kangle and EP panel
- 使用Typora编辑markdown上传CSDN时图片大小调整麻烦问题
- 模拟卷Leetcode【普通】1609. 奇偶树
- MySQL partition explanation and operation statement
- Greenplum6.x重新初始化
- selenium自动化集成,八年测试经验软测工程师,一篇文章带你学懂
- Image segmentation in opencv
- 【Istio Network CRD VirtualService、Envoyfilter】
猜你喜欢
随机推荐
Category of IP address
Rapid integration of authentication services - harmonyos platform
[step on the pit] Nacos registration has been connected to localhost:8848, no available server
Speaking of a software entrepreneurship project, is there anyone willing to invest?
Compilation and linking of programs
Required String parameter ‘XXX‘ is not present
C language for calculating the product of two matrices
MySQL主从延迟的解决方案
Sign and authenticate API interface or H5 interface
JS operation
Upload an e-office V9 arbitrary file [vulnerability recurrence practice]
[Yugong series] February 2022 U3D full stack class 007 - production and setting skybox resources
Greenplum 6.x build_ install
Opencv converts 16 bit image data to 8 bits and 8 to 16
Enterprise manager cannot connect to the database instance
Output all composite numbers between 6 and 1000
如何统计项目代码行数
Problems encountered in the use of go micro
Three series of BOM elements
数据分片介绍