本文整理汇总了C++中GLSLProgram::link方法的典型用法代码示例。如果您正苦于以下问题:C++ GLSLProgram::link方法的具体用法?C++ GLSLProgram::link怎么用?C++ GLSLProgram::link使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GLSLProgram
的用法示例。
在下文中一共展示了GLSLProgram::link方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadFromStrings
GLSLProgram* ShaderManager::LoadFromStrings(const char* vertName, const char*fragName, std::string vertString, std::string fragString)
{
GLSLProgram* prog = new GLSLProgram();
if(!prog->compileShaderFromString(vertString, GLSLShader::VERTEX))
{
printf("Vertex shader failed to compile from string!\n%s", prog->log().c_str());
sLog(Level::Severe) << "Vertex shader <" << vertName << "> failed to compile from string." << prog->log();
assert(false && "Vertex shader failed to compile from string");
return NULL;
}
if(!prog->compileShaderFromString(fragString, GLSLShader::FRAGMENT))
{
printf("Fragment shader failed to compile from string!\n%s", prog->log().c_str());
sLog(Level::Severe) << "Fragment shader <" << fragName << "> failed to compile from string." << prog->log();
assert(false && "Fragment shader failed to compile from string");
return NULL;
}
if(!prog->link())
{
printf("Shader program failed to link!\n%s", prog->log().c_str());
sLog(Level::Severe) << "Shader program failed to link." << prog->log();
assert(false && "Shader program failed to link.");
return NULL;
}
assert(prog != NULL);
return prog;
}
示例2: customInit
void OgroInvasion::customInit()
{
filename = g_programName + "/" + "Lenna.png";
try
{
glslProgram.loadShader(GLSLShaderType::VERTEX, g_programName + "/" + "shader.vert");
glslProgram.loadShader(GLSLShaderType::FRAGMENT, g_programName + "/" + "shader.frag");
}
catch (GLSLProgramException& e)
{
printf("%s\n", e.what());
system("pause");
exit(EXIT_FAILURE);
}
glslProgram.link();
GLint vertexAttribLoc = glslProgram.getAttributeLocation("vVertex");
//quad vertices and indices
glm::vec2 vertices[4];
GLushort indices[6];
vertices[0] = glm::vec2(0.0f, 0.0f);
vertices[1] = glm::vec2(1.0f, 0.0f);
vertices[2] = glm::vec2(1.0f, 1.0f);
vertices[3] = glm::vec2(0.0f, 1.0f);
GLushort* id = indices;
*id++ = 0;
*id++ = 1;
*id++ = 2;
*id++ = 0;
*id++ = 2;
*id++ = 3;
glGenVertexArrays(1, &vaoID);
glBindVertexArray(vaoID);
glGenBuffers(1, &vboVerticesID);
glGenBuffers(1, &vboIndicesID);
glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
glVertexAttribPointer(vertexAttribLoc, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
glEnableVertexAttribArray(vertexAttribLoc);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
mTexture = new Texture(filename);
mTexture->load();
mTexture->activateTexture(0); // GL_TEXTURE0
glslProgram.setUniform("textureMap", 0); // GL_TEXTURE0
}
示例3: customInit
void HelloGLSL::customInit()
{
try
{
glslProgram.loadShader(GLSLShaderType::VERTEX, g_programName + "/" + "HelloGLSL.vert");
glslProgram.loadShader(GLSLShaderType::FRAGMENT, g_programName + "/" + "HelloGLSL.frag");
}
catch (GLSLProgramException& e)
{
printf("%s\n", e.what());
system("pause");
exit(EXIT_FAILURE);
}
glslProgram.link();
glGenBuffers(1, &positionBufferObject);
glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW);
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
GLint positionLoc = glslProgram.getAttributeLocation("position");
glEnableVertexAttribArray(positionLoc);
glVertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, 0);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
示例4: LoadFromStrings
//Loads and compiles vertice and fragment shaders from strings into one GLSLProgram*
GLSLProgram* ShaderManager::LoadFromStrings(std::string vertName, std::string fragName, std::string vertString, std::string fragString)
{
GLSLProgram* prog = new GLSLProgram();
///Compile the vertex portion of the shader
if(!prog->compileShaderFromString(vertString, GLSLShader::VERTEX))
{
printf("Vertex shader failed to compile from string!\n%s", prog->log().c_str());
assert(false && "Vertex shader failed to compile from string");
return NULL;
}
///Compile the fragment portion of the shader
if(!prog->compileShaderFromString(fragString, GLSLShader::FRAGMENT))
{
printf("Fragment shader failed to compile from string!\n%s", prog->log().c_str());
assert(false && "Fragment shader failed to compile from string");
return NULL;
}
///Links the shader to OpenGL using the handle obtained during the compile
if ( !prog->link() )
{
printf("Shader program failed to link!\n%s", prog->log().c_str());
assert(false && "Shader program failed to link.");
return NULL;
}
assert(prog != NULL);
return prog;
}
示例5: SetupRC
///////////////////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering context.
// This is the first opportunity to do any OpenGL related tasks.
void SetupRC()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
prog.compileShaderFromFile("phong.vert", GLSLShader::VERTEX);
prog.compileShaderFromFile("phong.frag", GLSLShader::FRAGMENT);
prog.link();
prog.use();
glEnable(GL_DEPTH_TEST);
teapot = new VBOTeapot(13, mat4(1.0f));
//torus = new VBOTorus(0.7f, 0.3f, 50, 50);
torus = new VBOTorus(1.75f, 0.75f, 50, 50);
current = teapot;
model = mat4(1.0f);
model *= glm::translate(vec3(0.0f,0.0f,0.0f));
model *= glm::rotate(-90.0f, vec3(1.0f,0.0f,0.0f));
view = glm::lookAt(vec3(0.0f,3.0f,5.0f), vec3(0.0f,0.75f,0.0f), vec3(0.0f,1.0f,0.0f));
vec4 worldLight = vec4(5.0f,5.0f,2.0f,1.0f);
prog.setUniform("Material.Kd", 0.9f, 0.5f, 0.3f);
prog.setUniform("Light.Ld", 1.0f, 1.0f, 1.0f);
prog.setUniform("Light.Position", view * worldLight );
prog.setUniform("Material.Ka", 0.9f, 0.5f, 0.3f);
prog.setUniform("Light.La", 0.4f, 0.4f, 0.4f);
prog.setUniform("Material.Ks", 0.8f, 0.8f, 0.8f);
prog.setUniform("Light.Ls", 1.0f, 1.0f, 1.0f);
prog.setUniform("Material.Shininess", 100.0f);
}
示例6: SetupRC
///////////////////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering context.
// This is the first opportunity to do any OpenGL related tasks.
void SetupRC()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
glEnable(GL_DEPTH_TEST);
prog.compileShaderFromFile("texture.vs", GLSLShader::VERTEX);
prog.compileShaderFromFile("texture.fs", GLSLShader::FRAGMENT);
prog.link();
prog.use();
cube = new VBOCube();
glActiveTexture(GL_TEXTURE0);
GLuint tex_2d = SOIL_load_OGL_texture("brick1.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS|SOIL_FLAG_INVERT_Y);
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, tex_2d);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
prog.setUniform("Tex1", 0);
view = glm::lookAt(vec3(1.0f,1.25f,1.25f), vec3(0.0f,0.0f,0.0f), vec3(0.0f,1.0f,0.0f));
projection = mat4(1.0f);
prog.setUniform("Light.Position", vec4(0.0f,0.0f,0.0f,1.0f) );
prog.setUniform("Light.Intensity", vec3(1.0f,1.0f,1.0f) );
prog.setUniform("Material.Kd", 0.9f, 0.9f, 0.9f);
prog.setUniform("Material.Ks", 0.95f, 0.95f, 0.95f);
prog.setUniform("Material.Ka", 0.1f, 0.1f, 0.1f);
prog.setUniform("Material.Shininess", 100.0f);
}
示例7: SetupRC
///////////////////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering context.
// This is the first opportunity to do any OpenGL related tasks.
void SetupRC()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
prog.compileShaderFromFile("subroutine.vert", GLSLShader::VERTEX);
prog.compileShaderFromFile("subroutine.frag", GLSLShader::FRAGMENT);
prog.link();
prog.use();
glEnable(GL_DEPTH_TEST);
plane = new VBOPlane(50.0f, 50.0f, 1, 1);
teapot = new VBOTeapot(14, mat4(1.0f));
view = glm::lookAt(vec3(0.0f,0.0f,10.0f), vec3(0.0f,0.0f,0.0f), vec3(0.0f,1.0f,0.0f));
prog.setUniform("Light.Position", vec4(0.0f,0.0f,0.0f,1.0f));
prog.setUniform("Light.La", 0.4f, 0.4f, 0.4f);
prog.setUniform("Light.Ld", 1.0f, 1.0f, 1.0f);
prog.setUniform("Light.Ls", 1.0f, 1.0f, 1.0f);
prog.setUniform("Material.Kd", 0.9f, 0.5f, 0.3f);
prog.setUniform("Material.Ka", 0.9f, 0.5f, 0.3f);
prog.setUniform("Material.Ks", 0.8f, 0.8f, 0.8f);
prog.setUniform("Material.Shininess", 100.0f);
}
示例8: glCreateProgram
void GLSLProgram::createFromSourceStrings
(
GLSLProgram & prog,
const std::string &shader,
unsigned int shaderType,
const GLuint & geomIn ,
const GLuint & geomOut
)
{
prog.clear();
prog.handle_ = glCreateProgram();
prog._geomIn = geomIn;
prog._geomOut = geomOut;
switch ( shaderType )
{
case GL_VERTEX_SHADER_ARB:
prog.vertex_ = new GLSLShader ( shader, shaderType );
prog.attach ( prog.vertex_ );
break;
case GL_GEOMETRY_SHADER_EXT:
prog.geometry_ = new GLSLShader ( shader, shaderType );
prog.attach ( prog.geometry_ );
if ( ( prog._geomIn == 0 ) || ( prog._geomOut == 0 ) )
{
_ERROR ( "invalid geomin/geomout" );
throw "invalid geomin/geomout at ";
}
break;
case GL_FRAGMENT_SHADER_ARB:
prog.fragment_ = new GLSLShader ( shader, shaderType );
prog.attach ( prog.fragment_ );
break;
}
prog.link();
}
示例9: SetupRC
///////////////////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering context.
// This is the first opportunity to do any OpenGL related tasks.
void SetupRC()
{
// Black background
glClearColor(0.0f , 0.0f , 0.0f , 1.0f );
prog.compileShaderFromString (szIdentityShaderVP, GLSLShader:: VERTEX);
prog.compileShaderFromString (szIdentityShaderFP, GLSLShader:: FRAGMENT);
prog.link ();
prog.use ();
/////////////////// Create the VBO ////////////////////
GLfloat positionData [] = {
-0.8f, -0.8f , 0.0f ,
0.8f, -0.8f, 0.0f,
0.0f, 0.8f, 0.0f };
GLfloat colorData[] = {
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f };
// Create and populate the buffer objects
GLuint vboHandles[2];
glGenBuffers(2, vboHandles);
GLuint positionBufferHandle = vboHandles[0];
GLuint colorBufferHandle = vboHandles[1];
glBindBuffer(GL_ARRAY_BUFFER, positionBufferHandle);
glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(GLfloat), positionData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, colorBufferHandle);
glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(GLfloat), colorData, GL_STATIC_DRAW);
// Create and set-up the vertex array object
glGenVertexArrays( 1, &vaoHandle );
glBindVertexArray(vaoHandle);
glEnableVertexAttribArray(0); // Vertex position
glEnableVertexAttribArray(1); // Vertex color
glBindBuffer(GL_ARRAY_BUFFER, positionBufferHandle);
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL );
glBindBuffer(GL_ARRAY_BUFFER, colorBufferHandle);
glVertexAttribPointer( 1, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL );
}
示例10: printf
void SceneParticlesInstanced::compileAndLinkShader
(GLSLProgram& glslProg, const char* vertexPath, const char* fragmentPath, const char* geometryPath)
{
// "shader/particleinstanced.vs"
if( !glslProg.compileShaderFromFile(vertexPath, GLSLShader::VERTEX) )
{
printf("Vertex shader failed to compile!\n%s",
glslProg.log().c_str());
do
{
cout << '\n' << "Press a key to continue...";
} while (cin.get() != '\n');
exit(1);
}
// "shader/particleinstanced.fs"
if( !glslProg.compileShaderFromFile(fragmentPath, GLSLShader::FRAGMENT))
{
printf("Fragment shader failed to compile!\n%s",
glslProg.log().c_str());
do
{
cout << '\n' << "Press a key to continue...";
} while (cin.get() != '\n');
exit(1);
}
if (geometryPath != NULL && geometryPath[0] != '\0') {
// compile geometry shader
if (!glslProg.compileShaderFromFile(geometryPath, GLSLShader::GEOMETRY))
{
printf("Geometry shader failed to compile!\n%s",
glslProg.log().c_str());
do
{
cout << '\n' << "Press a key to continue...";
} while (cin.get() != '\n');
exit(1);
}
}
if( !glslProg.link() )
{
printf("Shader program failed to link!\n%s",
glslProg.log().c_str());
do
{
cout << '\n' << "Press a key to continue...";
} while (cin.get() != '\n');
exit(1);
}
glslProg.use();
}
示例11: loadAssets
void loadAssets()
{
loadParticles();
loadPlane();
pstack.push(glm::perspective(45.0f,
(GLfloat)window.GetWidth()/window.GetHeight(), 0.1f, 175.0f));
mstack.push(glm::lookAt(vec3(0, 2.7, 7), vec3(0, 2.4, 6), vec3(0, 1, 0)));
// Load terrain shader
if (!g_program.compileShaderFromFile(
ROOT_PATH_RELATIVE SHADER_DIR "terrain-vert.glsl",
GLSLShader::VERTEX)) {
fprintf(stderr, "%s\n", g_program.log().c_str());
exit(1);
}
if (!g_program.compileShaderFromFile(
ROOT_PATH_RELATIVE SHADER_DIR "terrain-frag.glsl",
GLSLShader::FRAGMENT)) {
fprintf(stderr, "%s\n", g_program.log().c_str());
exit(1);
}
if (!g_program.compileShaderFromFile(
ROOT_PATH_RELATIVE SHADER_DIR "terrain-tc.glsl",
GLSLShader::TESS_CONTROL)) {
fprintf(stderr, "%s\n", g_program.log().c_str());
exit(1);
}
if (!g_program.compileShaderFromFile(
ROOT_PATH_RELATIVE SHADER_DIR "terrain-te.glsl",
GLSLShader::TESS_EVALUATION)) {
fprintf(stderr, "%s\n", g_program.log().c_str());
exit(1);
}
if (!g_program.link()) {
fprintf(stderr, "%s\n", g_program.log().c_str());
exit(1);
}
// Load plane shader
if (!d_program.compileShaderFromFile(
ROOT_PATH_RELATIVE SHADER_DIR "default-vert.glsl",
GLSLShader::VERTEX)) {
fprintf(stderr, "%s\n", d_program.log().c_str());
exit(1);
}
if (!d_program.compileShaderFromFile(
ROOT_PATH_RELATIVE SHADER_DIR "default-frag.glsl",
GLSLShader::FRAGMENT)) {
fprintf(stderr, "%s\n", d_program.log().c_str());
exit(1);
}
const char *outputNames[] = { "Position" };
glTransformFeedbackVaryings(d_program.getHandle(), 1, outputNames, GL_SEPARATE_ATTRIBS);
if (!d_program.link()) {
fprintf(stderr, "%s\n", d_program.log().c_str());
exit(1);
}
g_program.use();
g_program.setUniform("Viewport", viewport);
g_program.setUniform("MinTessLevel", 1.0f);
g_program.setUniform("MaxTessLevel", max_tess);
//g_program.setUniform("MaxTessLevel", 20.0f);
g_program.setUniform("NearClip", 0.1f);
g_program.setUniform("FarClip", 175.0f);
g_program.setUniform("NearFog", 10.0f);
g_program.setUniform("FarFog", 125.0f);
g_program.setUniform("Light0.position", vec3(L0POSITION));
g_program.setUniform("Light0.La", vec3(L0AMBIENT));
g_program.setUniform("Light0.Ld", vec3(L0DIFFUSE));
GLuint terrainmap = SOIL_load_OGL_texture (
ROOT_PATH_RELATIVE TEXTURE_DIR "heightmap-vlarge.png",
SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
GLuint watermap = SOIL_load_OGL_texture (
ROOT_PATH_RELATIVE TEXTURE_DIR "watermap.jpg",
SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
GLuint ttex1 = SOIL_load_OGL_texture (
ROOT_PATH_RELATIVE TEXTURE_DIR "grass.jpg",
SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
GLuint ttex2 = SOIL_load_OGL_texture (
ROOT_PATH_RELATIVE TEXTURE_DIR "stonesnow.jpg",
SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
GLuint ttex3 = SOIL_load_OGL_texture (
ROOT_PATH_RELATIVE TEXTURE_DIR "water.jpg",
SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
//.........这里部分代码省略.........
示例12: main
int main()
{
GLFWwindow* window = nullptr;
if(!init(window))
{
system("pause");
exit(0);
}
glClearColor(0.0, 0.0, 0.0, 0.0);
//set up audio engine
SoundSystemClass sounds;
GLSLProgram shaders;
//load shaders, compile and link
shaders.compileShaderFromFile("triangle.v.glsl", VERTEX);
shaders.compileShaderFromFile("triangle.f.glsl", FRAGMENT);
shaders.link();
shaders.use();
Screen* currentScreen;
MainMenuScreen *mms = new MainMenuScreen(&sounds, &shaders);
currentScreen = mms;
//Text t(glm::vec3(0, 0, 0), glm::vec4(1.0, 0.0, 0.0, 1.0), 40, 40, "arial_0.png", "arial.fnt");
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//create projection matrix
glm::mat4 projectionMatrix = glm::ortho(0.0f, 800.0f, 0.0f, 600.0f);
double lastTime = glfwGetTime(), currentTime;
while(!glfwWindowShouldClose(window) && currentScreen != nullptr)
{
//calculate delta time
currentTime = glfwGetTime();
double deltaTime = currentTime - lastTime;
//draw
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
currentScreen->Draw();
glfwSwapBuffers(window);
//update
Screen* next = currentScreen->Update(deltaTime);
//if returned screen is null, pop current screen
if(next != currentScreen)
{
delete currentScreen;
currentScreen = next;
}
//else continue with current top of stack
glfwPollEvents();
lastTime = currentTime;
}
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}