当前位置:网站首页>8. Use the quadratic geometry technology to draw a small column on the screen.
8. Use the quadratic geometry technology to draw a small column on the screen.
2022-07-24 07:01:00 【Mo xiaodai ^o^】
#define GLUT_DISABLE_ATEXIT_HACK
#include "windows.h"
#include <stdio.h>
#include <gl/glut.h>
#include "math.h"
GLUquadricObj* quadratic; /**< Quadratic Geometry */
GLfloat rot = 0.0; /**< Used to rotate objects */
GLboolean light = false; /**< For opening / Turn off the light source */
GLboolean lp = false; /**< Judge L Whether the key is released */
GLboolean sp = false; /**< Determine whether the space bar is released */
struct TextureInfo
{
unsigned int ID;
BYTE* pBytes;
};
TextureInfo TexInfo[4];
/** Draw mode */
GLint renderMode[] = { GLU_FILL,GLU_LINE,GLU_SILHOUETTE };
GLuint mode = 0; /**< Draw schema index */
/** Define the attribute value of the light source */
GLfloat LightAmbient[] = { 0.5f, 0.5f, 0.5f, 1.0f }; /**< Ambient light parameters */
GLfloat LightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f }; /**< Diffuse light parameters */
GLfloat LightSpecular[] = { 1.0f, 1.0f, 1.0f, 1.0f }; /**< Specular light parameters */
GLfloat LightPosition[] = { 0.0f, 0.0f, 5.0f, 1.0f }; /**< Light source location */
// initialization OpenGL
void init(void)
{
/** User defined initialization process */
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glEnable(GL_TEXTURE_2D); /**< Enable texture mapping */
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
/** Set the attribute value of the light */
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); /**< Set up ambient light */
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); /**< Set diffuse light */
glLightfv(GL_LIGHT1, GL_SPECULAR, LightSpecular); /**< Set diffuse light */
glLightfv(GL_LIGHT1, GL_POSITION, LightPosition); /**< Set the light source position */
/** Turn on lighting */
glEnable(GL_LIGHT1);
/**< Create secondary Geometry */
quadratic = gluNewQuadric();
gluQuadricNormals(quadratic, GLU_SMOOTH); /**< Use smooth normals */
gluQuadricTexture(quadratic, GL_TRUE); /**< Use texture */
}
// The main drawing process
void display(void)
{
/** User defined drawing process */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /**< Clear cache */
glLoadIdentity();
/** Drawing process */
glTranslatef(0.0f, 0.0f, -8.0f);
/// Draw a cylinder
glPushMatrix();
glTranslatef(-2.0f, 1.1f, 0.0f);
glRotatef(90, 1.0f, 0.0f, 0.0f);
glRotatef(rot, 1.0f, 0.0f, 1.0f);
gluCylinder(quadratic, 0.8f, 2.0f, 1.8f, 32, 32);
//gluCylinder(sphere,baseRadius,topRadius, height, slices, stacks);
glPopMatrix();
glFlush(); /**< Enforce all OpenGL command */
}
// Call when the window changes size
void reshape(int w, int h) {
glViewport(0, 0, w, h);// Set up the viewport
glMatrixMode(GL_PROJECTION);// Set the current projection transformation mode
glLoadIdentity();// Replace the current transformation matrix with the identity matrix
gluPerspective(45, (float)w / h, 4, 100.0);// Set the orthographic projection body
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void TimerFunction(int value)
{
rot += 10;
if (rot == 360)
rot = 0;
// Redraw the scene with new coordinates
glutPostRedisplay();
glutTimerFunc(500, TimerFunction, 1);
}
// Dealing with keyboards
void keyboard(unsigned char key, int x, int y) {
switch (key) {
case 27://esc Key to exit
exit(0);
break;
case 'a':
case 'A':
lp = TRUE; /**< lp Set to TRUE */
light = !light; /**< Switch the light source's TRUE/FALSE */
if (!light) /**< If there is no light source */
{
glDisable(GL_LIGHTING); /**< Disable lights */
}
else
{
glEnable(GL_LIGHTING); /**< Turn on lighting */
}
break;
case 'd':
case 'D':
sp = TRUE; /**< lp Set to TRUE */
mode += 1;
if (mode > 2)
mode = 0;
gluQuadricDrawStyle(quadratic, renderMode[mode]);
break;
default:
break;
}
}
int main(int argc, char* argv[]) // The main function : The number of arguments & Parameter values
{
glutInit(&argc, argv);
glutInitWindowSize(640, 480);
glutCreateWindow("Basic");// Set the window title
init();// initialization OpenGL
glutDisplayFunc(display);// Set display callback function
glutReshapeFunc(reshape);// Set up reshape Callback function
glutKeyboardFunc(keyboard);// Set the keyboard callback function
glutTimerFunc(500, TimerFunction, 1);
glutMainLoop();// Enter the main loop
}
边栏推荐
- Don't care too much about what others think of you
- reflex
- 别太在意别人的眼光,那会抹杀你的光彩
- Camera Hal OEM module ---- CMR_ grab.c
- It can be written in 10 minutes -- 25~30k foreign enterprise recruitment interview questions, isn't it easy~
- [wechat applet] understand conditional rendering, list rendering and wxss template style
- OWASP TOP10 penetration test
- An AI plays 41 games, and the comprehensive performance score of Google's latest multi game decision transformer is twice that of dqn
- Redis basic type - hash
- (note sorting is not completed) [graph theory: find the shortest path of single source]
猜你喜欢

(静态,动态,文件)三个版本的通讯录
![[lvgl (6)] display Chinese settings and make Chinese font](/img/a4/1b0d0b7a5789ecc8f9a2a8cd93d92e.png)
[lvgl (6)] display Chinese settings and make Chinese font

Create WPF project

Detailed analysis of the process (life cycle) of class loading
![[lvgl (4)] event and event bubble of the object](/img/1e/9fe3d34f5f8d8c7298a106dca8d949.png)
[lvgl (4)] event and event bubble of the object

Metaltc5.0 realizes webrtc version IPC of Junzheng pure C

STM32基于hal库的adc以DMA的多通道采样以及所遇问题解决

GE口:SGMII模式和serdes模式

Jenkins CI CD

在线问题反馈模块实战(十二):实现图片删除功能
随机推荐
[lvgl] API functions for setting, changing and deleting styles of components
Jinan renshe has signed 1w+ electronic labor contract, which greatly helps HR digitalization
[lvgl (4)] event and event bubble of the object
[audio decoding chip] Application of vs1503 audio decoding chip
Three level classification / menu query tree structure
华为专家自述:如何成为优秀的工程师
UE4/5 无法打开文件“xxx.generated.h”(Cannot open file xxx.generated.h)的解决方法总结
tensorflow boolean_mask函数
xavier_ normal_ Initialization test
Mac can't connect to local MySQL server through socket '/tmp/mysql Sock '(2) problem
反射
PostgreSQL date handler usage
STM32 external interrupt (register version)
Ge port: sgmii mode and SerDes mode
【学习笔记】Web页面渲染的流程
Redis special data type hyperloglog
先爱自己,再爱别人。
Camera Hal OEM模块 ---- cmr_grab.c
不运动也能增肌???打一针冬眠黑熊的血清就行
(note sorting is not completed) [graph theory: find the shortest path of single source]