当前位置:网站首页>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
边栏推荐
- guava多线程,futurecallback线程调用不平均
- 阿里云有奖体验:如何通过ECS挂载NAS文件系统
- Cocos2d-x game archive [easy to understand]
- You want to kill a port process, but you can't find it in the service list. You can find this process and kill it through the command line to reduce restarting the computer and find the root cause of
- 【矩阵乘】【NOI 2012】【cogs963】随机数生成器
- Small guide for rapid formation of manipulator (11): standard nomenclature of coordinate system
- ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
- Onespin | solve the problems of hardware Trojan horse and security trust in IC Design
- 嵌入式系统真正安全了吗?[ OneSpin如何为开发团队全面解决IC完整性问题 ]
- Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
猜你喜欢

Ubuntu安装mysql8遇到的问题以及详细安装过程

How does codesonar help UAVs find software defects?

Don't fall behind! Simple and easy-to-use low code development to quickly build an intelligent management information system

恶魔奶爸 B3 少量泛读,完成两万词汇量+

Small guide for rapid formation of manipulator (11): standard nomenclature of coordinate system

Apifox interface integrated management new artifact

Static analysis of software defects codesonar 5.2 release
Codesonar enhances software reliability through innovative static analysis

C language helps you understand pointers from multiple perspectives (1. Character pointers 2. Array pointers and pointer arrays, array parameter passing and pointer parameter passing 3. Function point
Klocwork 代码静态分析工具
随机推荐
阿洛的烦恼
AADL Inspector 故障树安全分析模块
Nebula Importer 数据导入实践
Flask1.1.4 werkzeug1.0.1 source code analysis: Routing
开户还得用身份证银行卡安全吗,我是小白不懂
Hdu4876zcc love cards (multi check questions)
[paper reading] maps: Multi-Agent Reinforcement Learning Based Portfolio Management System
gridView自己定义做时间排版「建议收藏」
Cantata9.0 | 全 新 功 能
Codesonar Webinar
国家正规的股票交易app有哪些?使用安不安全
Object-C programming tips timer "suggestions collection"
npm uninstall和rm直接删除的区别
[award publicity] issue 22 publicity of the award list in June 2022: Community star selection | Newcomer Award | blog synchronization | recommendation Award
私募基金在中國合法嗎?安全嗎?
Is it safe to open an account of BOC shares in kainiu in 2022?
Le capital - investissement est - il légal en Chine? C'est sûr?
Implement secondary index with Gaussian redis
easyui 日期控件清空值
How to meet the dual needs of security and confidentiality of medical devices?