当前位置:网站首页>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
边栏推荐
- 可信隐私计算框架“隐语”开源专家观点集锦
- HaWe screw cartridge check valve RK4
- 德国emg电动执行器EB800-60II
- 互联网协议
- Parker solenoid valve d1vw020dnypz5
- 《From SICP to Lisp》视频回播
- We were tossed all night by a Kong performance bug
- PS + PL heterogeneous multicore case development manual for Ti C6000 tms320c6678 DSP + zynq-7045 (2)
- 一文详解 Redis 中 BigKey、HotKey 的发现与处理
- “核弹级” Log4j 漏洞仍普遍存在,并造成持续影响
猜你喜欢

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

Paper:《All Models are Wrong, but Many are Useful: 所有模型都是错误的,但许多模型都是有用的:通过同时研究一整类预测模型来了解变量的重要性》翻译与解读

OSPF comprehensive experiment

Google Earth Engine——MERRA-2 M2T1NXAER:1980-2022年气溶胶逐日数据集

bucher齿轮泵QX81-400R301

Google Earth engine - merra-2 m2t1nxlv: 1980 present global pressure, temperature, wind and other data sets
Specific practice cases of "card note taking method" in Siyuan

测试用例千万不能随便,记录由一个测试用例异常引起的思考

Some cutting-edge research work sharing of SAP ABAP NetWeaver containerization

终于有人把红蓝对抗讲明白了
随机推荐
2022年最新北京建筑安全员模拟题库及答案
[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
SAP ABAP 守护进程的实现方式
哪本书才是编程领域的“九阴真经”
【DSCTF2022】pwn补题记录
2022 test questions and answers for the latest national fire facility operator (senior fire facility operator)
Kalibr calibration realsensed435i -- multi camera calibration
Development daily summary (11): file upload function improvement: Chinese character detection and text content processing
Development and implementation of campus epidemic prevention and control management system based on SSM
Encryption model
Jmeter快速上手之接口测试
C# 给Word每一页设置不同文字水印
How to use job plug-in type to call a kettle job through ETL scheduling tool taskctl?
tensorboard多个events文件显示紊乱的解决办法
parker泵PV140R1K1T1PMMC
【物理模拟】最简单的shape matching的原理与实践
FTP协议
hawe螺旋插装式单向阀RK4
.net get injection object manually
Clojure 运行原理之字节码生成篇