当前位置:网站首页>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
边栏推荐
- Greenplum 6.x build_ install
- Count sort (diagram)
- Frequently Asked Coding Problems
- idea里使用module项目的一个bug
- Sign and authenticate API interface or H5 interface
- Greenplum 6.x monitoring software setup
- Mountaineering team (DFS)
- Nanjing commercial housing sales enabled electronic contracts, and Junzi sign assisted in the online signing and filing of housing transactions
- MySQL主从延迟的解决方案
- Digital triangle model acwing 1027 Grid access
猜你喜欢
idea里使用module项目的一个bug
C language for calculating the product of two matrices
Category of IP address
About using CDN based on Kangle and EP panel
LED模拟与数字调光
Novice entry SCM must understand those things
Pointer advanced, string function
Greenplum6.x-版本变化记录-常用手册
[Yugong series] February 2022 U3D full stack class 006 unity toolbar
面试题:高速PCB一般布局、布线原则
随机推荐
Find the original code, inverse code and complement of signed numbers [C language]
ESP32-ULP协处理器低功耗模式RTC GPIO中断唤醒
[step on the pit] Nacos registration has been connected to localhost:8848, no available server
idea里使用module项目的一个bug
Greenplum6.x重新初始化
Introduction to data fragmentation
Calculation s=1+12+123+1234+12345 C language
let const
【MySQL】数据库进阶之触发器内容详解
[MySQL] detailed explanation of trigger content of database advanced
[Yugong series] February 2022 U3D full stack class 005 unity engine view
数据库存储---表分区
How to realize sliding operation component in fast application
Markdown编辑器Editor.md插件的使用
Problems encountered in the use of go micro
IP地址的类别
指针进阶,字符串函数
Required String parameter ‘XXX‘ is not present
路由信息协议——RIP
[Yugong series] February 2022 U3D full stack class 008 - build a galaxy scene