当前位置:网站首页>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
}
边栏推荐
- Getting started with redis
- lambda表达式对list对象进行多字段排序
- sojson jsjiami.com. V6 crawler JS reverse
- Create WPF project
- [learning notes] see the difference between a+++a and a+a++ from the compilation
- [lvgl (3)]
- Introduction to kubernetes (kubernetes benefits)
- 安装snownlp包过程出现Requirement already satisfied:及Read timed out.问题解决方法
- It can be written in 10 minutes -- 25~30k foreign enterprise recruitment interview questions, isn't it easy~
- owasp top10 渗透测试
猜你喜欢
随机推荐
Redis distributed cache learning notes
10分钟就能写出来的——25~30K的国外企业招聘面试考题,这不是轻轻松松吗~
不运动也能增肌???打一针冬眠黑熊的血清就行
Detailed analysis of the process (life cycle) of class loading
Practice of online problem feedback module (12): realize image deletion function
Use the root user to create a new user and set the password for
chm文件打开时提示乱码
【学习笔记】url输入到页面展现中发生了什么?
2022-07-22 mysql/stonedb并行hashJoin内存占用分析
Can you increase muscle without exercise??? Just get an injection of hibernating black bear serum
不去和谁比较,只需做好自己
Redis special data type Geo
Redis基本类型-哈希Hash
oss授权单个bucket权限
一日一书:机器学习及实践——从零开始通往kaggle竞赛之路
Random forest, lgbm parameter adjustment based on Bayesian Optimization
[lvgl] API functions for setting, changing and deleting styles of components
postgresql 日期处理函数用法
Sparksql core usage, 220724,
一个AI玩41个游戏,谷歌最新多游戏决策Transformer综合表现分是DQN的两倍




![[lvgl] [stage summary 1]](/img/39/c6e96ae7971a2350769ef5b5950f8f.png)




