当前位置:网站首页>OpenGL super classic learning notes (1) the first triangle "suggestions collection"
OpenGL super classic learning notes (1) the first triangle "suggestions collection"
2022-07-07 21:05:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
Execution effect
Code and parsing :
//
// Triangle.cpp
// Triangle
//
// Created by fengsser on 15/6/20.
// Copyright (c) 2015 year fengsser. All rights reserved.
//
#include <GLTools.h>// Used to mask the differences between different platforms , Establish forms and other work
#include <GLShaderManager.h>
#ifdef __APPLE__
#include <glut/glut.h>
#else
#define FREEGLUT_STATIC
#endif
GLBatch triangleBatch;
GLShaderManager shaderManager;
// Accept new width and height when the window size changes , The parameter unit is image number
void ChangeSize(int w,int h)
{
// Complete the mapping from the target coordinate system to the screen coordinate system ,Glint x,Glint y by viewPort Coordinates in the lower left corner of the form .veiwPort Is the render area .
glViewport(0, 0, w, h);
}
//set render-context
void SetupRC()
{
// Set the back color r,g,b,a
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
// Initialize the shading Manager
shaderManager.InitializeStockShaders();
// Set triangles . Middle array vVert Including all 3 Vertex x,y,z, Cartesian coordinates ( It is the coordinate system learned in junior high school ). GLfloat vVerts[] = { -0.5f,0.0f,0.0f, 0.5f,0.0f,0.0f, 0.0f,0.5f,0.0f, }; // Create a triangular batch triangleBatch.Begin(GL_TRIANGLES,3); triangleBatch.CopyVertexData3f(vVerts); triangleBatch.End();}// Start rendering void RenderScene(void){ // Clear buffer : Color | depth | Templates glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Set a set of floating-point numbers to represent red GLfloat vRed[] = {1.0f,0.0f,0.0f,1.0f}; // Transfer colors to storage shaders , namely GLT_SHADER_IDENTITY Shaders , This shader simply renders the geometry on the screen using the specified color with the default Cartesian coordinates shaderManager.UseStockShader(GLT_SHADER_IDENTITY,vRed); // Submit geometry shaders triangleBatch.Draw(); // Will render in the background buffer . Then switch to the front desk at the end glutSwapBuffers();}int main(int argc,char* argv[]){ gltSetWorkingDirectory(argv[0]);// Set the current working folder . in the light of MAC OS X glutInit(&argc, argv); // Transfer command line parameters and initialize GLUT library // tell GLUT Which display mode does the library use when creating forms ,GLUT_DOUBLE: Double buffered form .GLUT_RGBA:RGBA Color mode ;GLUT_DEPTH: Depth test GLUT_STENCIL: Template testing glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL); glutInitWindowSize(800, 600);//GLUT Form size , Title Form glutCreateWindow("Triangle");// Create to Triangle Form with title // Register to listen , Events will be issued in the out loop , Form size changes and openGl Rendering glutReshapeFunc(ChangeSize); glutDisplayFunc(RenderScene); // initialization openGL Missing entry point in driver glewInit, And check whether initialization fails . GLenum err = glewInit(); if (GLEW_OK != err) { fprintf(stderr, "glew error:%s\n",glewGetErrorString(err)); return 1; } SetupRC();//RC-Render context glutMainLoop();// Start the main cycle return 0;}
The key process
About viewports (viewPort) And forms :
viewport . Rendering ( draw ) Area .
Generally, it is as big as the window . Viewports are used to map pixel coordinates from the logical Cartesian coordinate system to the physical screen .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116433.html Link to the original text :https://javaforall.cn
边栏推荐
- 使用高斯Redis实现二级索引
- SQL注入报错注入函数图文详解
- Write a jump table
- 刚开户的能买什么股票呢?炒股账户安全吗
- Lingyun going to sea | yidiantianxia & Huawei cloud: promoting the globalization of Chinese e-commerce enterprise brands
- Intelligent transportation is full of vitality. What will happen in the future? [easy to understand]
- UVA 11080 – Place the Guards(二分图判定)
- 权限不足
- [award publicity] issue 22 publicity of the award list in June 2022: Community star selection | Newcomer Award | blog synchronization | recommendation Award
- 私募基金在中国合法吗?安全吗?
猜你喜欢
Implement secondary index with Gaussian redis
Make this crmeb single merchant wechat mall system popular, so easy to use!
MySQL storage expression error
Static analysis of software defects codesonar 5.2 release
解决使用uni-app MediaError MediaError ErrorCode -5
OneSpin | 解决IC设计中的硬件木马和安全信任问题
复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
AADL inspector fault tree safety analysis module
ISO 26262 - 基于需求测试以外的考虑因素
C语言多角度帮助你深入理解指针(1. 字符指针2. 数组指针和 指针数组 、数组传参和指针传参3. 函数指针4. 函数指针数组5. 指向函数指针数组的指针6. 回调函数)
随机推荐
POJ 3140 Contestants Division「建议收藏」
Micro service remote debug, nocalhost + rainbow micro service development second bullet
恶魔奶爸 A1 语音听力初挑战
Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
CodeSonar通过创新型静态分析增强软件可靠性
国家正规的股票交易app有哪些?使用安不安全
Postgresql数据库character varying和character的区别说明
I wrote a markdown command line gadget, hoping to improve the efficiency of sending documents by garden friends!
Write a jump table
DataTable数据转换为实体
神兵利器——敏感文件发现工具
[function recursion] do you know all five classic examples of simple recursion?
Object-C programming tips timer "suggestions collection"
guava多线程,futurecallback线程调用不平均
微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
Numerical method for solving optimal control problem (0) -- Definition
万字总结数据存储,三大知识点
Mysql子查询关键字的使用方式(exists)
嵌入式系统真正安全了吗?[ OneSpin如何为开发团队全面解决IC完整性问题 ]
恶魔奶爸 A0 英文零基础的自我提升路