当前位置:网站首页>Osgsimplegl3 example analysis
Osgsimplegl3 example analysis
2022-07-29 08:25:00 【longlongway2012】
osgSimplegl3 Example analysis
author: longlongwaytogo
date: 2022/07/12
email: [email protected]
repo: https://github.com/longlongwaytogo/LearnOsgGL3
brief introduction
The front is finished osg GL3 Construction of environment , Here is the main analysis osg How to combine gl3 Carry out development work .
A detailed explanation of the example
- establish osg gl3 Environmental Science
const int width( 800 ), height( 450 );
const std::string version( "3.0" );
osg::ref_ptr< osg::GraphicsContext::Traits > traits = new osg::GraphicsContext::Traits();
traits->x = 20; traits->y = 30;
traits->width = width; traits->height = height;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->glContextVersion = version;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
osg::ref_ptr< osg::GraphicsContext > gc = osg::GraphicsContext::createGraphicsContext( traits.get() );
if( !gc.valid() )
{
osg::notify( osg::FATAL ) << "Unable to create OpenGL v" << version << " context." << std::endl;
return( 1 );
}
The above code is mainly for osg::GraphicsContext::traits Object to set parameters , The key is to specify gl Version is 3.0.
take traits Parameters are applied to the camera :
osg::Camera* cam = viewer.getCamera(); cam->setGraphicsContext( gc.get() );take shader Parameters are applied to the scene root node
void configureShaders( osg::StateSet* stateSet ) { const std::string vertexSource = "#version 130 \n" " \n" "uniform mat4 osg_ModelViewProjectionMatrix; \n" "uniform mat3 osg_NormalMatrix; \n" "uniform vec3 ecLightDir; \n" " \n" "in vec4 osg_Vertex; \n" "in vec3 osg_Normal; \n" "out vec4 color; \n" " \n" "void main() \n" "{ \n" " vec3 ecNormal = normalize( osg_NormalMatrix * osg_Normal ); \n" " float diffuse = max( dot( ecLightDir, ecNormal ), 0. ); \n" " color = vec4( vec3( diffuse ), 1. ); \n" " \n" " gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex; \n" "} \n"; osg::Shader* vShader = new osg::Shader( osg::Shader::VERTEX, vertexSource ); const std::string fragmentSource = "#version 130 \n" " \n" "in vec4 color; \n" "out vec4 fragData; \n" " \n" "void main() \n" "{ \n" " fragData = color; \n" "} \n"; osg::Shader* fShader = new osg::Shader( osg::Shader::FRAGMENT, fragmentSource ); osg::Program* program = new osg::Program; program->addShader( vShader ); program->addShader( fShader ); stateSet->setAttribute( program ); osg::Vec3f lightDir( 0., 0.5, 1. ); lightDir.normalize(); stateSet->addUniform( new osg::Uniform( "ecLightDir", lightDir ) ); }Above code , The use of shader Obviously older , It's best to use it really 3.3 The later version statement is better , This allows you to use renderdoc Perform frame grabbing debugging (renderdoc The use of will be introduced in detail in the following article ).
Set projection matrix and vertex attribute reference , But this code only gl3 Previous versions required , Really develop gl3 Version of osg The program does not need the following code
// for non GL3/GL4 and non GLES2 platforms we need enable the osg_ uniforms that the shaders will use, // you don't need thse two lines on GL3/GL4 and GLES2 specific builds as these will be enable by default. gc->getState()->setUseModelViewAndProjectionUniforms(true); gc->getState()->setUseVertexAttributeAliasing(true);summary :
although osgSimplegl3 An example is a demonstration gl3 Characteristic , But the environment in which it is written is not fully open GL3 Run in core mode , It's running on gl3 In compatibility mode , This can run version edition 130 Of shader Code .
This example is just a simple demonstration of how to run gl3 Environment . Yes osg Compilation is not required , Even if osg There is no setting in the compilation settings gl shader The version is higher , You can also use a higher version shader characteristic . But the suggestion is still to set gl3 Operating under the environment of gl3 Program , The main reasons are as follows :
- First of all : You can use higher version features ;
- second : There can be more efficient api Interface , Can improve performance ;
- Third : Third party debugging tools can be used (renderdoc、gpa、NSight etc. ) Debug error . Next article , Will explain osg and gl 3.3 Configuration of the above version .
边栏推荐
- User identity identification and account system practice
- Week 2: convolutional neural network basics
- torch.Tensor.to的用法
- Node: file write data (readfile, WriteFile), two modes: overwrite and increment
- 【Transformer】SegFormer:Simple and Efficient Design for Semantic Segmentation with Transformers
- Simplefoc parameter adjustment 3-pid parameter setting strategy
- 用户身份标识与账号体系实践
- Hc-sr04 use method and routine of ultrasonic ranging module (STM32)
- Intelligent temperature control system
- Lesson 3 threejs panoramic preview room case
猜你喜欢

Simplefoc parameter adjustment 1-torque control

pnpm install出现:ERR_PNPM_PEER_DEP_ISSUES Unmet peer dependencies

Week 1 task deep learning and pytorch Foundation

Application scheme of charging pile

Virtual augmentation and reality Part 2 (I'm a Firebird)

Gan: generate adversarial networks

Unity Shader学习(六)实现雷达扫描效果
![[opencv] - Operator (Sobel, canny, Laplacian) learning](/img/24/4e40408b61ec2c714b750b05a534c7.png)
[opencv] - Operator (Sobel, canny, Laplacian) learning

Intelligent shelf safety monitoring system

Qt/pyqt window type and window flag
随机推荐
Component transfer participation lifecycle
TCP——滑动窗口
用户身份标识与账号体系实践
MySQL rownum implementation
Simplefoc parameter adjustment 1-torque control
Unity Shader学习(六)实现雷达扫描效果
Privacy is more secure in the era of digital RMB
Solve the problem of MSVC2017 compiler with yellow exclamation mark in kits component of QT
Multifunctional signal generator based on AD9850
torch.nn.functional.one_hot()
Flask reports an error runtimeerror: the session is unavailable because no secret key was set
Huawei wireless device configuration uses WDS technology to deploy WLAN services
Use SQL client How can the job generated by SH achieve breakpoint continuation after cancle?
ROS tutorial (Xavier)
torch.Tensor.to的用法
Cs4344 domestic substitute for dp4344 192K dual channel 24 bit DA converter
sql判断语句的编写
PostgreSQL manually creates hikaridatasource to solve the error cannot commit when autocommit is enabled
Tensorboard use
BiSeNet v2