当前位置:网站首页>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
}
边栏推荐
猜你喜欢
随机推荐
Array_ 01return in foreach
Hurry in!! Take you to understand what is multi file, and easily master the usage of extern and static C language keywords!!!
/etc/rc.local 设置UI程序开机自启动
8.使用二次几何体技术,在屏幕上绘制一个上小下大的柱体。
Some thoughts on being a professional
Install pytoch+anaconda+cuda+cudnn
赶紧进来!!轻松掌握C语言“顺序”、“分支”、“循环”三大结构
umi之define属性
在屏幕上绘制一个运动的茶壶,茶壶先慢慢向屏幕里面移动,越变越小,越变越模糊;然后慢慢变大,越变越清晰,一直往返重复。为场景添加光照,材质和雾效果。通过键盘’a’’s’’d’来选择不同的雾效模式
C语言从入门到入土(二)
过渡 效果
JS - 数值处理(取整、四舍五入、随机数等)
C语言入门篇 概述
解决:控制台使用nvm控制node版本时出现exit status 1与exit status 145
grid布局
Opengl在屏幕上绘制一个锥体,该锥体有四个面,每个面都是三角形。为该锥体添加光照和纹理效果
B站视频评论爬取——以鬼灭之刃为例(并将其存储到csv中)
一文node安装下载和配置
Text summary acl2021
String_ Method_ 01match method









