当前位置:网站首页>Draw a circle and a square on the screen. The square is in front and the circle is behind. You can move the square through the keyboard. In the following cases, the square can only move within the cir
Draw a circle and a square on the screen. The square is in front and the circle is behind. You can move the square through the keyboard. In the following cases, the square can only move within the cir
2022-07-24 05:32:00 【Mo xiaodai ^o^】
/* Draw a square on the screen , use ice.bmp Texture map the square ; Draw a yellow teapot behind the square , Suppose the square is transparent , Draw the mixing effect of teapot and square ; adopt A,D,W and K Press the key to adjust the teapot in X Axis and Y Position of the shaft , As follows :[1] A:x Value reduction on axis ;
[2] D:x The value on the axis increases ;[3] W:y The value on the axis increases ; [4] K:y Value reduction on axis . Add a template cache to the program so that the teapot can only move in a square area .
*/
#define GLUT_DISABLE_ATEXIT_HACK
#include "windows.h"
#include <gl/glut.h>
#include "math.h"
float alpha = 0.5;
float p1=0.0;
float p2=0.0;
// initialization OpenGL
void init(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);// Set the background color
glClearStencil(1);
glClearDepth(1.0f);
}
// The main drawing process
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Clear color cache
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 0x01, 0xFFFFFFFF);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);//
// Draw a teapot
glLoadIdentity();
glPushMatrix();
glTranslatef(0.0, 0.0, -6.0);
glColor3f(1, 1, 0);
//glBlendFunc(GL_ZERO, GL_ONE);
glutSolidSphere(2, 36, 36);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glPopMatrix();
glStencilFunc(GL_NOTEQUAL, 0x00, 0xFFFFFFFF);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
// Draw irregular quadrilateral
glPushMatrix();
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glTranslatef(-1+p1, -1+p2, -4.0);
glShadeModel(GL_FLAT);
//glEnable(GL_TEXTURE_2D);
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_QUADS);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
glVertex3f(1.0, 1.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glEnd();
glPopMatrix();
glFlush();
glutSwapBuffers();
}
// 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(90, (float)w / h, 4, 10.0);// Set the orthographic projection body
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}
// Dealing with keyboards
void keyboard(unsigned char key, int x, int y) {
switch (key) {
// [1] A:x Value reduction on axis ;[2] D:x The value on the axis increases ;[3] W:y The value on the axis increases ; [4] K:y Value reduction on axis .
case 27://esc Key to exit
exit(0);
break;
case 'a':
case 'A':
p1=p1-1;
glutPostRedisplay();
break;
case 'd':
case 'D':
p1=p1+1;
glutPostRedisplay();
break;
case 'w':
case 'W':
p2=p2+1;
glutPostRedisplay();
break;
case 'k':
case 'K':
p2=p2-1;
glutPostRedisplay();
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
glutMainLoop();// Enter the main loop
}
边栏推荐
- special effects - 星空宇宙背景特效
- 再次聊聊浏览器缓存
- C语言从入门到入土(三)
- OPENGL在屏幕上绘制2个点,右边一个蓝色的点,采用反走样技术,左边一个红色的点,不采用反走样技术。比较两个点的区别。
- 一文node安装下载和配置
- canvas - 圆形
- Hurry in!! Take you to understand what is multi file, and easily master the usage of extern and static C language keywords!!!
- vscode配置autoprefixer
- 构造函数_Date构造函数
- visibility:hidden 和 display:none
猜你喜欢

Geoserver自动化上传Shapefile

A collation of the basic usage of numpy

深度剖析数据在内存中的存储

AttributeError: ‘NoneType‘ object has no attribute ‘shape‘

canvas - 填充

Ain 0722 sign in

canvas - 圆形

node连接mysql,使用navicat可视化

Hurry in!! Take you to understand what is multi file, and easily master the usage of extern and static C language keywords!!!
![JS:为什么 [] == ![] 返回 true ?](/img/36/94839bf4ce6bd06d2cbe989828c791.png)
JS:为什么 [] == ![] 返回 true ?
随机推荐
useRef 创建动态引用
C语言从入门到入土——操作符超详细总结
自定义MVC 2.0
special effects - 鼠标点击,自定义 DOM 跟随移动
special effects - 鼠标点击,出现随机颜色的爱心
This is the first article
c语言中的变量与常量
模板数据的二次加工
Scope and scope chain
T 6-10
Text summary acl2021
Keywords_ 02break and continue
String_ Method_ 01match method
special effects - 鼠标点击,出现烟花炸裂效果
Sorting out some common server instructions and some binding instructions in csgo
聊聊强缓存与协商缓存
Geoserver REST API功能解析
详解浏览器和Node的事件循环机制及区别
es10小计flat和flatMap
Opengl模拟现实生活中,球掉到地面上再弹起来的过程,在屏幕上绘制一个球,球从上往下掉,碰到地面,再弹起来。