当前位置:网站首页>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
边栏推荐
猜你喜欢
How to meet the dual needs of security and confidentiality of medical devices?
使用高斯Redis实现二级索引
How to meet the dual needs of security and confidentiality of medical devices?
OneSpin 360 DV新版发布,刷新FPGA形式化验证功能体验
Implement secondary index with Gaussian redis
最新版本的CodeSonar改进了功能安全性,支持MISRA,C ++解析和可视化
MySQL storage expression error
Klocwork code static analysis tool
Don't fall behind! Simple and easy-to-use low code development to quickly build an intelligent management information system
ISO 26262 - 基于需求测试以外的考虑因素
随机推荐
2022年在启牛开中银股票的账户安全吗?
How to meet the dual needs of security and confidentiality of medical devices?
ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
[UVALive 6663 Count the Regions] (dfs + 离散化)[通俗易懂]
Ubuntu安装mysql8遇到的问题以及详细安装过程
Write a jump table
Intelligent software analysis platform embold
Is it safe to open an account online now? I want to know where I can open an account in Nanning now?
uva 12230 – Crossing Rivers(概率)「建议收藏」
How to meet the dual needs of security and confidentiality of medical devices?
死锁的产生条件和预防处理[通俗易懂]
Hdu4876zcc love cards (multi check questions)
Écrivez une liste de sauts
恶魔奶爸 A0 英文零基础的自我提升路
MySQL约束之默认约束default与零填充约束zerofill
Nebula importer data import practice
最新版本的CodeSonar改进了功能安全性,支持MISRA,C ++解析和可视化
Small guide for rapid formation of manipulator (12): inverse kinematics analysis
Codeforces 474 F. Ant colony
微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹