当前位置:网站首页>初识OpenGL (2)编译着色器
初识OpenGL (2)编译着色器
2022-07-26 15:51:00 【thefist11】
step1. 创建一个着色器对象
用ID来引用,储存这个顶点着色器为unsigned int,
unsigned int vertexShader;
vertexShader = glCreateShader(GL_VERTEX_SHADER);
. glCreateShader 创建着色器。
参数: 着色器类型。eg. 顶点着色器,传递的参数是GL_VERTEX_SHADER。
step2. 把着色器源码附加到着色器对象上并编译
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函数
第一个参数: 要编译的着色器对象。
第二参数: 指定了传递的源码字符串数量,这里只有一个。
第三个参数:顶点着色器真正的源码
第四个参数:先设置为NULL。
step3. 检测编译结果
检测调用glCompileShader后编译是否成功了,如果没成功的话,你还会希望知道错误是什么,这样你才能修复它们。检测编译时错误可以通过以下代码来实现:
int success;
char infoLog[512];
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
首先我们定义一个整型变量来表示是否成功编译,还定义了一个储存错误消息(如果有的话)的容器。然后我们用glGetShaderiv检查是否编译成功。如果编译失败,我们会用glGetShaderInfoLog获取错误消息,然后打印它。
if(!success)
{
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl;
}
如果编译的时候没有检测到任何错误,顶点着色器就被编译成功了
边栏推荐
- 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]
- Zynq PS + PL heterogeneous multicore Case Development Manual of Ti C6000 tms320c6678 DSP + zynq-7045 (1)
- 绘制漂亮的中学操场轮廓,生成带经纬度数据
- 什么是GPIO,它有什么用
- VS2019Debug模式太卡进不去断点
- Is CICC Fortune Securities safe? How long does it take to open an account
- 《硅谷之谜》读后感
- 白话详解决策树模型之使用信息熵构建决策树
- 2021年软件测试工具趋势
- Coo format of adjacency matrix
猜你喜欢

反射、枚举以及lambda表达式

German EMG e-anji thruster ed301/6 HS

换把人体工学椅,缓解久坐写代码的老腰吧~

Google Earth engine - merra-2 m2t1nxlv: 1980 present global pressure, temperature, wind and other data sets

Development and implementation of campus epidemic prevention and control management system based on SSM

全志A40i工业核心板,100%国产4核ARM Cortex-A7,支持“双屏异显”【显示接口能力,工业HMI首选方案】

OSPF comprehensive experiment

潘多拉 IOT 开发板学习(RT-Thread)—— 实验17 ESP8266 实验(学习笔记)

Implementation of personalized healthy diet recommendation system based on SSM

Refuse noise, the entry journey of earphone Xiaobai
随机推荐
Digital warehouse: iqiyi digital warehouse platform construction practice
promise,async-await 和 跨域问题的解决--代理服务器的原理
Data warehouse: Data Modeling and log system in data warehouse construction
原来卡布奇诺信息安全协会是干这个的呀,一起来看看吧。
My brother created his own AI anti procrastination system, and he was "blinded" when playing with his mobile phone | reddit was hot
Research and application of the whole configuration of large humanoid robot
御神楽的学习记录之SoC FPGA的第一个工程-Hello World
物联网工业级串口转WiFi转网口转以太网模块的选型
Paper:《All Models are Wrong, but Many are Useful: 所有模型都是错误的,但许多模型都是有用的:通过同时研究一整类预测模型来了解变量的重要性》翻译与解读
Tutorial (7.0) 05. Issue forticlient * forticlient EMS * Fortinet network security expert NSE 5 through forticlient EMS
教大模型自己跳过“无用”层,推理速度×3性能不变,谷歌MIT这个新方法火了...
请问一下各位大佬,mysql-cdc建表如何指定表的字符集呢,在官网没找到相应的连接器参数。我读一个
关于我写的IDEA插件能一键生成service,mapper....这件事(附源码)
This article explains in detail the discovery and processing of bigkey and hotkey in redis
Using information entropy to construct decision tree
全志A40i工业核心板,100%国产4核ARM Cortex-A7,支持“双屏异显”【显示接口能力,工业HMI首选方案】
PS + PL heterogeneous multicore case development manual for Ti C6000 tms320c6678 DSP + zynq-7045 (3)
Super simple! It only takes a few steps to customize the weather assistant for TA!!
Clojure 运行原理之编译器剖析
TKE集群节点max-pod是如何配置的