当前位置:网站首页>First knowledge of OpenGL (2) compilation shaders
First knowledge of OpenGL (2) compilation shaders
2022-07-26 16:07:00 【thefist11】
step1. Create a shader object
use ID To quote , Save this vertex shader as unsigned int,
unsigned int vertexShader;
vertexShader = glCreateShader(GL_VERTEX_SHADER);
. glCreateShader Create shader .
Parameters : Shader type .eg. Vertex shader , The parameters passed are GL_VERTEX_SHADER.
step2. Attach the shader source code to the shader object and compile
const char *vertexShaderSource = "#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
"}\0";
glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
glCompileShader(vertexShader);
glShaderSource function
The first parameter : The shader object to compile .
The second parameter : Specifies the number of source strings passed , There's only one .
The third parameter : Vertex shader real source code
Fourth parameter : Set to NULL.
step3. Check the compilation results
Detect call glCompileShader Whether the post compilation is successful , If it doesn't succeed , You will also want to know what the mistake is , So you can fix them . Detecting compile time errors can be achieved by the following code :
int success;
char infoLog[512];
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
First, we define an integer variable to indicate whether the compilation was successful , It also defines a storage error message ( If any ) The container of . And then we use glGetShaderiv Check if the compilation is successful . If compilation fails , We will use glGetShaderInfoLog Get error messages , And print it .
if(!success)
{
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl;
}
If no errors are detected during compilation , The vertex shader is compiled successfully
边栏推荐
- 理解卷积神经网络中的权值共享
- 使用 ClojureScript 开发浏览器插件的过程与收获
- 提问征集丨快来向NLLB作者提问啦!(智源Live第24期)
- OSPF comprehensive experiment
- Zynq PS + PL heterogeneous multicore Case Development Manual of Ti C6000 tms320c6678 DSP + zynq-7045 (1)
- Build resume editor based on Nocode
- Sklearn clustering clustering
- Is CICC Fortune Securities safe? How long does it take to open an account
- Teach the big model to skip the "useless" layer and improve the reasoning speed × 3. The performance remains unchanged, and the new method of Google MIT is popular
- Pandora IOT development board learning (RT thread) - Experiment 17 esp8266 experiment (learning notes)
猜你喜欢

Parker solenoid valve d1vw020dnypz5

PAT甲级 1050 String Subtraction

Google Earth Engine——MERRA-2 M2T1NXSLV:1980-至今全球压力、温度、风等数据集

VS2019Debug模式太卡进不去断点

Quanzhi a40i industrial core board, 100% domestic 4-core arm cortex-a7, supports "dual screen abnormal display" [display interface capability, preferred scheme for industrial HMI]

kalibr标定realsenseD435i --多相机标定

互联网协议

PAT甲级 1047 Student List for Course

Musk was exposed to be the founder of Google: he broke up his best friend's second marriage and knelt down to beg for forgiveness

博途PLC顺序开关机功能块(SCL)
随机推荐
【物理模拟】最简单的shape matching的原理与实践
我们被一个 kong 的性能 bug 折腾了一个通宵
Refuse noise, the entry journey of earphone Xiaobai
Development daily summary (11): file upload function improvement: Chinese character detection and text content processing
《硅谷之谜》读后感
[expdp export data] expdp exports a table with 23 rows of records and no lob field. It takes 48 minutes. Please help us have a look
Alibaba cloud DMS MySQL cloud database report error, solve!!
操作系统迁移实战之在openEuler上部署MySQL数据库
Paper:《All Models are Wrong, but Many are Useful: 所有模型都是错误的,但许多模型都是有用的:通过同时研究一整类预测模型来了解变量的重要性》翻译与解读
2022年最新北京建筑安全员模拟题库及答案
Google Earth Engine——MERRA-2 M2T1NXAER:1980-2022年气溶胶逐日数据集
API version control [eolink translation]
【工具分享】自动生成文件目录结构工具mddir
2021年软件测试工具趋势
PAT甲级 1050 String Subtraction
Kalibr calibration realsensed435i -- multi camera calibration
测试用例千万不能随便,记录由一个测试用例异常引起的思考
一文搞懂│XSS攻击、SQL注入、CSRF攻击、DDOS攻击、DNS劫持
Finally, someone explained the red blue confrontation clearly
我们被一个 kong 的性能 bug 折腾了一个通宵