当前位置:网站首页>4. Draw a red triangle and a yellow square on the screen. Triangle in the back, small; Square in front, big. Using the fusion technology, the triangle can be seen through the square, and the source an
4. Draw a red triangle and a yellow square on the screen. Triangle in the back, small; Square in front, big. Using the fusion technology, the triangle can be seen through the square, and the source an
2022-07-24 05:32:00 【Mo xiaodai ^o^】
#include "windows.h"
#include <gl/glut.h>
#include "math.h"
GLint mixMode[] = { GL_ZERO,GL_ONE,GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA };
int m=2, n=3;
// initialization OpenGL
void init(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);// Set the background color
glShadeModel(GL_SMOOTH);// Set shading , There are two selection modes :GL_FLAT( No gradients ) and GL_SMOOTH( Gradient transition )
}
// The main drawing process
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Clear color cache
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
// Draw the first quadrilateral
glPushMatrix();
glTranslatef(-1, -1, -6.0);
glShadeModel(GL_FLAT);
glEnable(GL_TEXTURE_2D);
glColor3f(1, 0, 0);
glBegin(GL_TRIANGLES);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(2.0, 0.0, 0.0);
glVertex3f(2.0, 2.0, 0.0);
glEnd();
glPopMatrix();
// Draw the second quadrilateral
glLoadIdentity();
glPushMatrix();
glTranslatef(0.0, 0, -4.0);
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glColor4f(1.0, 1.0, 0.0, 0.5);
glBlendFunc(mixMode[m], mixMode[n]);
glBegin(GL_QUADS);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(2.0, 0.0, 0.0);
glVertex3f(2.0, 2.0, 0.0);
glVertex3f(0.0, 2.0, 0.0);
glEnd();
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
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) {
case 27://esc Key to exit
exit(0);
break;
case 's':
case 'S':
m = 2;
n = 3;
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
}边栏推荐
- 深度剖析数据在内存中的存储
- Programmer tools collection! (Reprinted)
- special effects - 鼠标移动,出现自定义的表情拖尾
- 闲来写博~简单说说let和var和const
- JS - 鼠标键盘配置 及 浏览器禁止操作
- 随意写写 cookie,sessionStorage,localStorage和session
- index为什么不能作为v-for的key?
- JS - 计算直角三角形的边长及角度
- 7. 在屏幕上绘制一条贝塞尔曲线,并用反走样技术对曲线进行平滑处理。
- Detailed explanation of string constant pool and intern() of string
猜你喜欢
随机推荐
Keywords_ 01return
新建 umi 项目,Error: Rendered more hooks 或者 Rendered fewer hooks
解决:控制台使用nvm控制node版本时出现exit status 1与exit status 145
Function_ generalization
Scikit learn notes
[DP] number triangle
select_ Render small phenomena
关键字_01return
Hurry in!! Take you to understand what is multi file, and easily master the usage of extern and static C language keywords!!!
Promise_ Async and await
day(0~6)代表每月第一天起始位置,stop代表每月天数,每天之间空两个空格。输入不同的day和stop,输出每月日历的样子。假设day为2,stop为31,则输出样式为
数组_01forEach中的return
JS输出字符串中出现最多次数的字符
[[[recursion]]]
空杯心态,重新开始
AttributeError: ‘NoneType‘ object has no attribute ‘shape‘
special effects - 鼠标点击,出现烟花炸裂效果
程序员工具合集!(转载)
node连接mysql,使用navicat可视化
C文件读写加链表增删改查









