本文整理汇总了C++中GLSLProgram::compileShaderFromFile方法的典型用法代码示例。如果您正苦于以下问题:C++ GLSLProgram::compileShaderFromFile方法的具体用法?C++ GLSLProgram::compileShaderFromFile怎么用?C++ GLSLProgram::compileShaderFromFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GLSLProgram
的用法示例。
在下文中一共展示了GLSLProgram::compileShaderFromFile方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Load
//Loads and compiles vertice and fragment shaders from Files into one GLSLProgram*
GLSLProgram* ShaderManager::Load(std::string vertName, std::string fragName)
{
GLSLProgram* prog = new GLSLProgram();
///Compile the vertex portion of the shader
if (!prog->compileShaderFromFile(vertName, GLSLShader::VERTEX))
{
printf("Vertex shader failed to compile!\n%s", prog->log().c_str());
assert(false && "Vertex shader failed to compile");
return NULL;
}
///Compile the fragment portion of the shader
if (!prog->compileShaderFromFile(fragName, GLSLShader::FRAGMENT))
{
printf("Fragment shader failed to compile!\n%s", prog->log().c_str());
assert(false && "Fragment shader failed to compile");
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;
}
示例2: Load
GLSLProgram* ShaderManager::Load(const char* vertName, const char*fragName)
{
GLSLProgram* prog = new GLSLProgram();
if (!prog->compileShaderFromFile(vertName, GLSLShader::VERTEX))
{
printf("Vertex shader failed to compile!\n%s", prog->log().c_str());
sLog(Level::Severe) << "Vertex shader <" << vertName << "> failed to compile." << prog->log();
assert(false && "Vertex shader failed to compile");
return NULL;
}
if (!prog->compileShaderFromFile(fragName, GLSLShader::FRAGMENT))
{
printf("Fragment shader failed to compile!\n%s", prog->log().c_str());
sLog(Level::Severe) << "Fragment shader <" << fragName << "> failed to compile." << prog->log();
assert(false && "Fragment shader failed to compile");
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;
}
示例3: 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);
}
示例4: 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);
}
示例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("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);
}
示例6: 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();
}
示例7: 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 );
//.........这里部分代码省略.........
示例8: 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;
}