本文整理汇总了C++中LoadShader函数的典型用法代码示例。如果您正苦于以下问题:C++ LoadShader函数的具体用法?C++ LoadShader怎么用?C++ LoadShader使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LoadShader函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LOGI
GLuint GlUtil::CreateProgram(const char* vertex_source, const char* fragment_source)
{
LOGI("%s\n", vertex_source);
GLuint vertexShader = 0;
GLuint fragment_shader = 0;
if (vertex_source)
{
vertexShader = LoadShader(GL_VERTEX_SHADER, vertex_source);
if (!vertexShader) {
return 0;
}
}
if (fragment_source)
{
fragment_shader = LoadShader(GL_FRAGMENT_SHADER, fragment_source);
if (!fragment_shader) {
return 0;
}
}
GLuint program = glCreateProgram();
if (program) {
glAttachShader(program, vertexShader);
CheckGlError("glAttachShader");
if (fragment_shader)
{
glAttachShader(program, fragment_shader);
CheckGlError("glAttachShader");
}
LinkProgram(program);
}
return program;
}
示例2: LoadProgram
static GLuint LoadProgram ( const char *vertShaderSrc, const char *fragShaderSrc )
{
GLuint vertexShader;
GLuint fragmentShader;
GLuint programObject;
GLint linked;
// Load the vertex/fragment shaders
vertexShader = LoadShader ( GL_VERTEX_SHADER, vertShaderSrc );
if ( vertexShader == 0 )
return 0;
fragmentShader = LoadShader ( GL_FRAGMENT_SHADER, fragShaderSrc );
if ( fragmentShader == 0 )
{
glDeleteShader( vertexShader );
return 0;
}
// Create the program object
programObject = glCreateProgram ( );
if ( programObject == 0 )
return 0;
glAttachShader ( programObject, vertexShader );
glAttachShader ( programObject, fragmentShader );
// Link the program
glLinkProgram ( programObject );
// Check the link status
glGetProgramiv ( programObject, GL_LINK_STATUS, &linked );
if ( !linked )
{
GLint infoLen = 0;
glGetProgramiv ( programObject, GL_INFO_LOG_LENGTH, &infoLen );
if ( infoLen > 1 )
{
char* infoLog = malloc (sizeof(char) * infoLen );
glGetProgramInfoLog ( programObject, infoLen, NULL, infoLog );
fprintf (stderr, "Error linking program:\n%s\n", infoLog );
free ( infoLog );
}
glDeleteProgram ( programObject );
return 0;
}
// Free up no longer needed shader resources
glDeleteShader ( vertexShader );
glDeleteShader ( fragmentShader );
return programObject;
}
示例3: Init
///
// Initialize the shader and program object
//
int Init()
{
char vShaderStr[] =
"attribute vec4 vPosition; \n"
"void main() \n"
"{ \n"
" gl_Position = vPosition; \n"
"} \n";
char fShaderStr[] =
"precision mediump float; \n"
"void main() \n"
"{ \n"
#ifndef __FIXED__
" gl_FragColor = vec4(0.2, 0.5, 0.1, 1.0); \n"
#else
" gl_FragColor = vec4(0.4, 0.3, 0.7, 1.0); \n"
#endif
"} \n";
GLuint vertexShader;
GLuint fragmentShader;
GLuint programObject;
GLint linked;
// Load the vertex/fragment shaders
vertexShader = LoadShader(GL_VERTEX_SHADER, vShaderStr);
fragmentShader = LoadShader(GL_FRAGMENT_SHADER, fShaderStr);
// Create the program object
programObject = glCreateProgram();
if(programObject == 0)
return -1;
glAttachShader(programObject, vertexShader);
glAttachShader(programObject, fragmentShader);
// Bind vPosition to attribute 0
glBindAttribLocation(programObject, 0, "vPosition");
// Link the program
glLinkProgram(programObject);
// Check the link status
glGetProgramiv(programObject, GL_LINK_STATUS, &linked);
if(!linked)
{
GLint infoLen = 0;
glGetProgramiv(programObject, GL_INFO_LOG_LENGTH, &infoLen);
if(infoLen > 1)
{
char* infoLog = (char*)malloc(sizeof(char) * infoLen);
glGetProgramInfoLog(programObject, infoLen, NULL, infoLog);
printf("Error linking program:\n%s\n", infoLog);
free(infoLog);
}
glDeleteProgram(programObject);
return -1;
}
// Store the program object
#ifndef __FIXED__
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
#else
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
#endif
return programObject;
}
示例4: LoadShader
// load all shaders
void ShaderManager::LoadShaders()
{
LoadShader(BasicShader, "../common_res/Basic.vsh", "../common_res/Basic.fsh");
LoadShader(BasicShaderInstanced, "../common_res/BasicInstanced.vsh", "../common_res/Basic.fsh", "../common_res/BasicInstanced.gsh");
LoadShader(OVRFrustumShader, "../common_res/OVRFrustum.vsh", "../common_res/OVRFrustum.fsh");
LoadShader(FontShader, "../common_res/Font.vsh", "../common_res/Font.fsh");
LoadShader(BasicShaderNoTex, "../common_res/BasicNoTex.vsh", "../common_res/BasicNoTex.fsh");
}
示例5: LoadShader
void VulkanTexturedQuad::CreatePipelineStateObject()
{
vertexShader_ = LoadShader(device_, BasicVertexShader, sizeof(BasicVertexShader));
fragmentShader_ = LoadShader(device_, TexturedFragmentShader, sizeof(TexturedFragmentShader));
pipeline_ = CreatePipeline(device_, renderPass_, pipelineLayout_,
vertexShader_, fragmentShader_);
}
示例6: InitializeProgram
void InitializeProgram(void) {
std::cout << "OpenGL initialization function\n" << std::endl;
std::vector<GLuint> shaders;
shaders.push_back(LoadShader(GL_VERTEX_SHADER, "pass_along.vert"));
shaders.push_back(LoadShader(GL_FRAGMENT_SHADER, "uniform_color.frag"));
shader_program = CreateProgram(shaders);
std::for_each(shaders.begin(), shaders.end(), glDeleteShader);
}
示例7: LoadShader
bool cShader::BuildShader(const std::string& vs_filename, const std::string& ps_filename)
{
GLuint vs = LoadShader(vs_filename, GL_VERTEX_SHADER);
GLuint ps = LoadShader(ps_filename, GL_FRAGMENT_SHADER);
mProg = CreateShader(vs, ps);
return mProg != -1;
}
示例8: main
int main( int argc, char* argv[] )
{
g_InitialCameraPosition = glm::vec3( 0, 0, 10 );
g_Camera.SetPosition( g_InitialCameraPosition );
g_Camera.SetRotation( g_InitialCameraRotation );
InitGL(argc, argv);
InitGLEW();
// Load some shaders.
GLuint vertexShader = LoadShader( GL_VERTEX_SHADER, "../data/shaders/simpleShader.vert" );
GLuint fragmentShader = LoadShader( GL_FRAGMENT_SHADER, "../data/shaders/simpleShader.frag" );
std::vector<GLuint> shaders;
shaders.push_back(vertexShader);
shaders.push_back(fragmentShader);
// Create the shader program.
g_ShaderProgram = CreateShaderProgram( shaders );
assert( g_ShaderProgram != 0 );
GLint positionAtribID = glGetAttribLocation( g_ShaderProgram, "in_position" );
GLint colorAtribID = glGetAttribLocation( g_ShaderProgram, "in_color" );
g_uniformMVP = glGetUniformLocation( g_ShaderProgram, "MVP" );
// Create a VAO for the cube.
glGenVertexArrays( 1, &g_vaoCube );
glBindVertexArray( g_vaoCube );
GLuint vertexBuffer, indexBuffer;
glGenBuffers( 1, &vertexBuffer );
glGenBuffers( 1, &indexBuffer );
glBindBuffer( GL_ARRAY_BUFFER, vertexBuffer );
glBufferData( GL_ARRAY_BUFFER, sizeof(g_Vertices), g_Vertices, GL_STATIC_DRAW );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexBuffer );
glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof(g_Indices), g_Indices, GL_STATIC_DRAW );
glVertexAttribPointer( positionAtribID, 3, GL_FLOAT, false, sizeof(VertexXYZColor),
reinterpret_cast<const GLvoid*>(offsetof(VertexXYZColor,m_Pos)) );
glEnableVertexAttribArray( positionAtribID );
glVertexAttribPointer( colorAtribID, 3, GL_FLOAT, false, sizeof(VertexXYZColor),
reinterpret_cast<const GLvoid*>(offsetof(VertexXYZColor,m_Color)));
glEnableVertexAttribArray( colorAtribID );
// Make sure we disable and unbind everything to prevent rendering issues later.
glBindVertexArray( 0 );
glBindBuffer( GL_ARRAY_BUFFER, 0 );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
glDisableVertexAttribArray( positionAtribID );
glDisableVertexAttribArray( colorAtribID );
glutMainLoop();
}
示例9: Camera
bool APP_SpotRotate::Start()
{
m_appName = "Spot rotate";
m_time = 0.0f;
Gizmos::create();
GameCam = new Camera();
// create shaders
const char* vsSource = nullptr;
std::string vsResult = LoadShader("./assets/shaders/RotateVertShader.vert");
vsSource = vsResult.c_str();
const char* fsSource = nullptr;
std::string fsResult = LoadShader("./assets/shaders/RotateFragShader.frag");
fsSource = fsResult.c_str();
int success = GL_FALSE;
unsigned int vertexShader = glCreateShader(GL_VERTEX_SHADER);
unsigned int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
//glBindAttributeLocation
glShaderSource(vertexShader, 1, (const char**)&vsSource, 0);
glCompileShader(vertexShader);
glShaderSource(fragmentShader, 1, (const char**)&fsSource, 0);
glCompileShader(fragmentShader);
m_programID = glCreateProgram();
glAttachShader(m_programID, vertexShader);
glAttachShader(m_programID, fragmentShader);
glLinkProgram(m_programID);
glGetProgramiv(m_programID, GL_LINK_STATUS, &success);
if (success == GL_FALSE) {
int infoLogLength = 0;
glGetProgramiv(m_programID, GL_INFO_LOG_LENGTH, &infoLogLength);
char* infoLog = new char[infoLogLength];
glGetProgramInfoLog(m_programID, infoLogLength, 0, infoLog);
printf("Error: Failed to link shader program!\n");
printf("%s\n", infoLog);
delete[] infoLog;
}
glDeleteShader(fragmentShader);
glDeleteShader(vertexShader);
// Generate our GL Buffers
glGenBuffers(1, &m_VBO);
glGenBuffers(1, &m_IBO);
glGenVertexArrays(1, &m_VAO); //generate a VertexArrayObject
isLoaded = true;
return true; //not being used in this lesson
}
示例10: initRender
void initRender() {
// Create 2 shader programs
Shader[0] = glCreateShader(GL_VERTEX_SHADER);
Shader[1] = glCreateShader(GL_FRAGMENT_SHADER);
LoadShader((char *)VertexShader, Shader[0]);
LoadShader((char *)FragmentShader, Shader[1]);
// Create the prorgam and attach the shaders & attributes
Program = glCreateProgram();
glAttachShader(Program, Shader[0]);
glAttachShader(Program, Shader[1]);
glBindAttribLocation(Program, 0, "Position");
glBindAttribLocation(Program, 1, "Normal");
glBindAttribLocation(Program, 2, "Texture");
// Link
glLinkProgram(Program);
// Validate our work thus far
int ShaderStatus;
glGetProgramiv(Program, GL_LINK_STATUS, &ShaderStatus);
if (ShaderStatus != GL_TRUE) {
LOGE("Error: Failed to link GLSL program\n");
int Len = 1024;
char Error[1024];
glGetProgramInfoLog(Program, 1024, &Len, Error);
LOGE("%s",Error);
exit(-1);
}
glValidateProgram(Program);
checkGlError("glValidateProgram");
// Enable the program
glUseProgram (Program);
// Retrieve our uniforms
iProj = glGetUniformLocation(Program, "Proj");
iModel = glGetUniformLocation(Program, "Model");
iCamera = glGetUniformLocation(Program, "Camera");
// Basic GL setup
glClearColor (0.15, 0.15, 0.15, 1.0);
glEnable (GL_CULL_FACE);
glEnable (GL_DEPTH_TEST);
glCullFace (GL_BACK);
}
示例11: InitializeProgram
void InitializeProgram()
{
std::vector<GLuint> shaderList;
shaderList.push_back(LoadShader(GL_VERTEX_SHADER, "FragPosition.vert"));
shaderList.push_back(LoadShader(GL_FRAGMENT_SHADER, "FragPosition.frag"));
theProgram = CreateProgram(shaderList);
std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader);
}
示例12: InitializeProgram
void InitializeProgram()
{
std::vector<GLuint> shaderList;
shaderList.push_back(LoadShader(GL_VERTEX_SHADER, "OrthoWithOffset.vert"));
shaderList.push_back(LoadShader(GL_FRAGMENT_SHADER, "StandardColors.frag"));
theProgram = CreateProgram(shaderList);
offsetUniform = glGetUniformLocation(theProgram, "offset");
std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader);
}
示例13: LoadShaderFile
//--------------------------- Constructor
cShader::cShader(char* Filename){
//printf("------------- Loading Shader. /n");
//Temp Variables
GLint iPass = 0;
GLchar cErrorLog[1024] = { 0 };
//create 2 temp chars, adding the .vert and .frag extensions
//vert
std::string sVert;
sVert.append(Filename);
sVert.append(".vert");
char* vertShad = Filename;
vertShad = LoadShaderFile(sVert.c_str());
//frag
std::string sFrag;
sFrag.append(Filename);
sFrag.append(".frag");
char* fragShad = Filename;
fragShad = LoadShaderFile(sFrag.c_str());
//Create the shader Program
GLuint ShaderProgram = glCreateProgram();
//check it opened
if (ShaderProgram == 0){
printf("Error creating ShaderProgram \n '%i' \n",ShaderProgram);
iShaderID = -1;
return;
}
//apply the shader
LoadShader(ShaderProgram,GL_VERTEX_SHADER,vertShad);
LoadShader(ShaderProgram,GL_FRAGMENT_SHADER,fragShad);
//Link the Shader
glLinkProgram(ShaderProgram);
glGetProgramiv(ShaderProgram,GL_LINK_STATUS,&iPass);
//Check it is linked
if (iPass == 0){
glGetProgramInfoLog(ShaderProgram,sizeof(cErrorLog),NULL,cErrorLog);
printf("Error while linking ShaderProgram \n '%s' \n",cErrorLog);
iShaderID = -1;
return;
}
//Validate the Shader
glValidateProgram(ShaderProgram);
glGetProgramiv(ShaderProgram,GL_LINK_STATUS,&iPass);
//Check it is Valid
if (iPass == 0){
glGetProgramInfoLog(ShaderProgram,sizeof(cErrorLog),NULL,cErrorLog);
printf("Error while validating ShaderProgram \n '%s' \n",cErrorLog);
iShaderID = -1;
return;
}
iShaderID = ShaderProgram;
//printf("------------- Shader Loading finished! \n \n");
}
示例14: glCreateProgram
GLuint Shader::load()
{
GLuint program = glCreateProgram();
GLuint vertex = glCreateShader(GL_VERTEX_SHADER);
GLuint fragment = glCreateShader(GL_FRAGMENT_SHADER);
std::string vertSourceString = LoadShader(m_Vertpath);
std::string fragSourceString = LoadShader(m_Fragpath);
const char* vertSource = vertSourceString.c_str();
const char* fragSource = fragSourceString.c_str();
glShaderSource(vertex, 1, &vertSource, NULL);
glCompileShader(vertex);
GLint result;
glGetShaderiv(vertex, GL_COMPILE_STATUS, &result);
if (result == GL_FALSE)
{
GLint length;
glGetShaderiv(vertex, GL_INFO_LOG_LENGTH, &length);
std::vector<char> error(length);
glGetShaderInfoLog(vertex, length, &length, &error[0]);
std::cout <<"Vertex Failed : " << &error[0] << std::endl;
glDeleteShader(vertex);
return 0;
}
glShaderSource(fragment, 1, &fragSource, NULL);
glCompileShader(fragment);
glGetShaderiv(fragment, GL_COMPILE_STATUS, &result);
if (result == GL_FALSE)
{
GLint length;
glGetShaderiv(fragment, GL_INFO_LOG_LENGTH, &length);
std::vector<char> error(length);
glGetShaderInfoLog(fragment, length, &length, &error[0]);
std::cout << "fragment fucked " << &error[0] << std::endl;
glDeleteShader(fragment);
return 0;
}
glAttachShader(program, vertex);
glAttachShader(program, fragment);
glLinkProgram(program);
glValidateProgram(program);
glDeleteShader(vertex);
glDeleteShader(fragment);
return program;
}
示例15: LoadShader
void VulkanQuad::CreatePipelineStateObject ()
{
vertexShader_ = LoadShader (device_, BasicVertexShader, sizeof (BasicVertexShader));
fragmentShader_ = LoadShader (device_, BasicFragmentShader, sizeof (BasicFragmentShader));
pipelineLayout_ = CreatePipelineLayout (device_);
VkExtent2D extent = {
static_cast<uint32_t> (window_->GetWidth ()),
static_cast<uint32_t> (window_->GetHeight ())
};
pipeline_ = CreatePipeline(device_, renderPass_, pipelineLayout_,
vertexShader_, fragmentShader_, extent);
}