当前位置:网站首页>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
边栏推荐
- 【矩阵乘】【NOI 2012】【cogs963】随机数生成器
- Phoenix JDBC
- Unity3d 4.3.4f1 execution project
- 权限不足
- 复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
- Codeforces round 296 (Div. 2) A. playing with paper[easy to understand]
- 201215-03-19—cocos2dx内存管理–具体解释「建议收藏」
- C语言 整型 和 浮点型 数据在内存中存储详解(内含原码反码补码,大小端存储等详解)
- Is embedded system really safe? [how does onespin comprehensively solve the IC integrity problem for the development team]
- Is private equity legal in China? Is it safe?
猜你喜欢
Onespin | solve the problems of hardware Trojan horse and security trust in IC Design
Tensorflow2. How to run under x 1 Code of X
AADL inspector fault tree safety analysis module
Lex & yacc of Pisa proxy SQL parsing
Helix QAC 2020.2 new static test tool maximizes the coverage of standard compliance
Nebula importer data import practice
95年专注安全这一件事 沃尔沃未来聚焦智能驾驶与电气化领域安全
Is embedded system really safe? [how does onespin comprehensively solve the IC integrity problem for the development team]
[paper reading] maps: Multi-Agent Reinforcement Learning Based Portfolio Management System
Make this crmeb single merchant wechat mall system popular, so easy to use!
随机推荐
npm uninstall和rm直接删除的区别
Apifox interface integrated management new artifact
Spark judges that DF is empty
开户还得用身份证银行卡安全吗,我是小白不懂
2022年在启牛开中银股票的账户安全吗?
使用高斯Redis实现二级索引
【C语言】指针进阶---指针你真的学懂了吗?
FatMouse&#39; Trade (Hangdian 1009)
Differences and connections between MinGW, mingw-w64, tdm-gcc and other tool chains "suggestions collection"
How to meet the dual needs of security and confidentiality of medical devices?
Mysql子查询关键字的使用方式(exists)
DataTable数据转换为实体
Hoj 2245 planktonic triangle cell (Mathematics)
阿洛的烦恼
Do you have to make money in the account to open an account? Is the fund safe?
【矩阵乘】【NOI 2012】【cogs963】随机数生成器
A brief understanding of the in arc__ bridge、__ bridge_ Retained and__ bridge_ transfer
Codeforces Round #296 (Div. 2) A. Playing with Paper[通俗易懂]
Implement secondary index with Gaussian redis
程序猿赚的那点钱算个P啊!