当前位置:网站首页>5. Template cache. Drawing a square can only move within the triangle
5. Template cache. Drawing a square can only move within the triangle
2022-07-24 07:01:00 【Mo xiaodai ^o^】
#define GLUT_DISABLE_ATEXIT_HACK
#include "windows.h"
#include <gl/glut.h>
#include "math.h"
float alpha = 0.5;
float qqx1=-0.6;
float qqy1=-0.6;
float qqz1=-4.0;
BYTE* gltReadBMPBits(const char* szFileName, int* nWidth, int* nHeight)
{
HANDLE hFileHandle;
BITMAPINFO* pBitmapInfo = NULL;
unsigned long lInfoSize = 0;
unsigned long lBitSize = 0;
BYTE* pBits = NULL; // Bitmaps bits
BITMAPFILEHEADER bitmapHeader;
DWORD dwBytes;
// Open the Bitmap file
hFileHandle = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
// Check for open failure (most likely file does not exist).
if (hFileHandle == INVALID_HANDLE_VALUE)
return NULL;
// File is Open. Read in bitmap header information
ReadFile(hFileHandle, &bitmapHeader, sizeof(BITMAPFILEHEADER),
&dwBytes, NULL);
// Check for a couple of simple errors
if (dwBytes != sizeof(BITMAPFILEHEADER))
return FALSE;
// Check format of bitmap file
if (bitmapHeader.bfType != 'MB')
return FALSE;
// Read in bitmap information structure
lInfoSize = bitmapHeader.bfOffBits - sizeof(BITMAPFILEHEADER);
pBitmapInfo = (BITMAPINFO*)malloc(sizeof(BYTE) * lInfoSize);
ReadFile(hFileHandle, pBitmapInfo, lInfoSize, &dwBytes, NULL);
if (dwBytes != lInfoSize)
{
free(pBitmapInfo);
CloseHandle(hFileHandle);
return FALSE;
}
// Save the size and dimensions of the bitmap
*nWidth = pBitmapInfo->bmiHeader.biWidth;
*nHeight = pBitmapInfo->bmiHeader.biHeight;
lBitSize = pBitmapInfo->bmiHeader.biSizeImage;
// If the size isn't specified, calculate it anyway
if (pBitmapInfo->bmiHeader.biBitCount != 24)
{
free(pBitmapInfo);
return FALSE;
}
if (lBitSize == 0)
lBitSize = (*nWidth *
pBitmapInfo->bmiHeader.biBitCount + 7) / 8 *
abs(*nHeight);
// Allocate space for the actual bitmap
free(pBitmapInfo);
pBits = (BYTE*)malloc(sizeof(BYTE) * lBitSize);
// Read in the bitmap bits, check for corruption
if (!ReadFile(hFileHandle, pBits, lBitSize, &dwBytes, NULL) ||
dwBytes != (sizeof(BYTE) * lBitSize))
pBits = NULL;
// Close the bitmap file now that we have all the data we need
CloseHandle(hFileHandle);
return pBits;
}
// 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 )
// Get bitmap data
BYTE* pBytes;
int nWidth, nHeight;
pBytes = gltReadBMPBits("D:\\TEST.BMP", &nWidth, &nHeight);
Define a 2D texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, nWidth, nHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, pBytes);
// Control filtering
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// Explain the mapping method
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
// 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,1,0xFFFFFFFF);
glStencilOp(GL_REPLACE,GL_REPLACE,GL_REPLACE);
// Draw triangle
glPushMatrix();
glTranslatef(-2, -2, -5.0);
glScalef(2.0f,2.0f,2.0f);
glShadeModel(GL_FLAT);
glEnable(GL_TEXTURE_2D);
glColor4f(1, 0, 0,1);
glBegin(GL_TRIANGLES);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(2.0, 0.0, 0.0);
glVertex3f(1.0, 2.0, 0.0);
glEnd();
glPopMatrix();
glDisable(GL_TEXTURE_2D);
glStencilFunc(GL_EQUAL,1,0xFFFFFFFF);
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
// Draw a square
//glLoadIdentity();
glPushMatrix();
glTranslatef(qqx1, qqy1, qqz1);
glScalef(0.5f,0.5f,0.5f);
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glColor4f(1.0, 1.0, 0.0, 0.5);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
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();
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 'a':
case 'A':
qqx1 -= 0.1;
glutPostRedisplay();
break;
case 'd':
case 'D':
qqx1 += 0.1;
glutPostRedisplay();
break;
case 'w':
case 'W':
qqy1 += 0.1;
glutPostRedisplay();
break;
case 'S':
case 's':
qqy1 -= 0.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
}
边栏推荐
- Camera Hal OEM module ---- CMR_ grab.c
- OWASP TOP10 penetration test
- [lvgl (important)] style attribute API function and its parameters
- [C language] operator details (in-depth understanding + sorting and classification)
- JSONObject按照key的A——Z顺序排序
- Record the pits encountered in the deserialization of phpserializer tool class
- vs2019配置运行open3d例子
- Random forest, lgbm parameter adjustment based on Bayesian Optimization
- Redis数据类型-列表List
- Can you increase muscle without exercise??? Just get an injection of hibernating black bear serum
猜你喜欢
![[lvgl (4)] event and event bubble of the object](/img/1e/9fe3d34f5f8d8c7298a106dca8d949.png)
[lvgl (4)] event and event bubble of the object

MapReduce(一)
![[audio decoding chip] Application of vs1503 audio decoding chip](/img/ee/0d5f95fba647592cc95f1e9f410bc9.png)
[audio decoding chip] Application of vs1503 audio decoding chip

SparkSQL核心使用,220724,

Redis.conf details

JSONObject按照key的A——Z顺序排序

Getting started with redis

Penetration learning - SQL injection - shooting range - installation and bypass experiment of safety dog (it will be updated later)

Three level classification / menu query tree structure

Prediction of advertising investment and sales based on regression analysis -- K neighborhood, decision tree, random forest, linear regression, ridge regression
随机推荐
vs2019配置运行open3d例子
济南人社已签1W+电子劳动合同,法大大助力HR数字化
Ge port: sgmii mode and SerDes mode
[lvgl] [stage summary 1]
【学习笔记】网页出现白屏可能的原因与优化方法
[audio decoding chip] Application of vs1503 audio decoding chip
HashSet to array
Redis分布式缓存学习笔记
Redis数据类型-列表List
SparkSQL核心使用,220724,
Redis基本类型-有序集合Zset
Sealos packages and deploys kubesphere container platform
(笔记整理未完成)【图论:求单源最短路径】
一个AI玩41个游戏,谷歌最新多游戏决策Transformer综合表现分是DQN的两倍
js和ts学习总结
You don't have to waste your life on others' standards
You are you, and no one can replace you
[lvgl (6)] display Chinese settings and make Chinese font
Redis data type -string (string type)
STM32外部中断(寄存器版本)