本文整理汇总了C++中ShaderProgram::Link方法的典型用法代码示例。如果您正苦于以下问题:C++ ShaderProgram::Link方法的具体用法?C++ ShaderProgram::Link怎么用?C++ ShaderProgram::Link使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShaderProgram
的用法示例。
在下文中一共展示了ShaderProgram::Link方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WinMain
int CALLBACK WinMain(
__in HINSTANCE hInstance,
__in HINSTANCE hPrevInstance,
__in LPSTR lpCmdLine,
__in int nCmdShow
)
#endif
{
if (!glfwInit())
return 0;
GLFWwindow* window = glfwCreateWindow(640, 480, "Window Title", NULL, NULL);
glfwMakeContextCurrent(window);
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK)
return -1;
GLuint vertexBuffer;
glGenBuffers(1, &vertexBuffer);
Shader* vertexShader = new Shader("Content\\Shaders\\vertexShader.vs", GL_VERTEX_SHADER);
Shader* fragmentShader = new Shader("Content\\Shaders\\fragmentShader.fs", GL_FRAGMENT_SHADER);
ShaderProgram* program = new ShaderProgram();
program->AttachShader(vertexShader);
program->AttachShader(fragmentShader);
program->BindFragDataLocation(0, "outColour");
program->Link();
program->Use();
GLint posAttrib = program->GetAttribLocation("position");
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
GLuint vbo;
glGenBuffers(1, &vbo);
float vertices[] = {
0.0f, 0.5f,
0.5f, -0.5f,
-0.5f, -0.5f
};
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(posAttrib);
glVertexAttribPointer
(posAttrib, // Ref input
2, // Number of values for input
GL_FLOAT, // Type of each component
GL_FALSE, // Whether to normalise
0, // Stride
0); // Offset
while (!glfwWindowShouldClose(window))
{
glClearColor(0.f, 0.f, 0.f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 3);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
return 0;
}
示例2: main
int main(int argc, char * argv[]) {
char path[256];
engine = new Engine(argc, argv);
ShaderProgram* defergbufferShader = new ShaderProgram();
FBO g_buffer(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT), 1);
FBO shadow_buffer(2000, 2000, 1);
GET_SHADER_VISBUFFER_PATH(path, 256, "defergbuffer.vert");
if (!defergbufferShader->AddVertexShaderPath(path)) return 0;
GET_SHADER_VISBUFFER_PATH(path, 256, "defergbuffer.frag");
if (!defergbufferShader->AddFragmentShaderPath(path)) return 0;
if (!defergbufferShader->Link()) return 0;
defergbufferShader->SetAttribVertex("vertex_coord");
defergbufferShader->SetAttribNormal("normal_coord");
ShaderProgram* shadowMapShader = new ShaderProgram();
GET_SHADER_VISBUFFER_PATH(path, 256, "shadow.vert");
if (!shadowMapShader->AddVertexShaderPath(path)) return 0;
GET_SHADER_VISBUFFER_PATH(path, 256, "shadow.frag");
if (!shadowMapShader->AddFragmentShaderPath(path)) return 0;
if (!shadowMapShader->Link()) return 0;
shadowMapShader->SetAttribVertex("vertex");
ShaderProgram* shadowRenderShader = new ShaderProgram();
GET_SHADER_VISBUFFER_PATH(path, 256, "shadowRender.vert");
if (!shadowRenderShader->AddVertexShaderPath(path)) return 0;
GET_SHADER_VISBUFFER_PATH(path, 256, "shadowRender.frag");
if (!shadowRenderShader->AddFragmentShaderPath(path)) return 0;
if (!shadowRenderShader->Link()) return 0;
shadowRenderShader->SetAttribVertex("vertex");
shadowRenderShader->SetAttribTexture("texture_coordinate");
// --------------SHADER LOADING--------------------------
GET_MODEL_PATH(path, 256, "bunny_smooth.ply");
Mesh bunny1, bunny2, bunny3;
Mesh shadowBunny1, shadowBunny2, shadowBunny3;
Mesh square1, square2, square3, square4, square5, square6;
Mesh shadowSquare1, shadowSquare2, shadowSquare3, shadowSquare4, shadowSquare5, shadowSquare6;
bunny1.Load(path);
bunny2.Load(path);
bunny3.Load(path);
shadowBunny1.Load(path);
shadowBunny2.Load(path);
shadowBunny3.Load(path);
square1.LoadSquare();
square2.LoadSquare();
square3.LoadSquare();
square4.LoadSquare();
square5.LoadSquare();
square6.LoadSquare();
shadowSquare1.LoadSquare();
shadowSquare2.LoadSquare();
shadowSquare3.LoadSquare();
shadowSquare4.LoadSquare();
shadowSquare5.LoadSquare();
shadowSquare6.LoadSquare();
GET_MODEL_PATH(path, 256, "sphere.ply");
Mesh Light1, Light2, Light3;
Light1.Load(path);
Light2.Load(path);
Light3.Load(path);
Mesh AmbientFSQ;
AmbientFSQ.LoadSquare();
Mesh ShadowRenderFSQ;
ShadowRenderFSQ.LoadSquare();
Mesh DeferredBRDFFSQ;
DeferredBRDFFSQ.LoadSquare();
// ---------------MODEL LOADING--------------------------
Scene bunnyScene;
bunnyScene.addObject(&bunny1);
bunnyScene.addObject(&bunny2);
bunnyScene.addObject(&bunny3);
bunnyScene.addObject(&Light1);
bunnyScene.addObject(&Light2);
bunnyScene.addObject(&Light3);
bunnyScene.addObject(&square1);
bunnyScene.addObject(&square2);
bunnyScene.addObject(&square3);
bunnyScene.addObject(&square4);
bunnyScene.addObject(&square5);
bunnyScene.addObject(&square6);
Scene ambientScene;
ambientScene.addObject(&AmbientFSQ);
Scene shadowMapScene;
shadowMapScene.addObject(&shadowBunny1);
//.........这里部分代码省略.........
示例3: Init
void Renderer::Init()
{
// initialize OpenGL ES and EGL
/*
* Here specify the attributes of the desired configuration.
* Below, we select an EGLConfig with at least 8 bits per color
* component compatible with on-screen windows
*/
const EGLint attribs[] =
{
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8,
EGL_NONE
};
EGLint format;
EGLint numConfigs;
EGLConfig config;
m_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(m_display, NULL, NULL);
/* Here, the application chooses the configuration it desires. In this
* sample, we have a very simplified selection process, where we pick
* the first EGLConfig that matches our criteria */
eglChooseConfig(m_display, attribs, &config, 1, &numConfigs);
/* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
* guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
* As soon as we picked a EGLConfig, we can safely reconfigure the
* ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
eglGetConfigAttrib(m_display, config, EGL_NATIVE_VISUAL_ID, &format);
ANativeWindow_setBuffersGeometry(m_pState->window, 0, 0, format);
m_surface = eglCreateWindowSurface(m_display, config, m_pState->window, NULL);
EGLint contextAttribs[] =
{
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
m_context = eglCreateContext(m_display, config, NULL, contextAttribs);
eglMakeCurrent(m_display, m_surface, m_surface, m_context);
eglQuerySurface(m_display, m_surface, EGL_WIDTH, &m_width);
eglQuerySurface(m_display, m_surface, EGL_HEIGHT, &m_height);
for (TextureVectorIterator iter = m_textures.begin(); iter != m_textures.end(); ++iter)
{
Texture* pCurrent = *iter;
pCurrent->Init();
}
for (ShaderVectorIterator iter = m_shaders.begin(); iter != m_shaders.end(); ++iter)
{
ShaderProgram* pCurrent = *iter;
pCurrent->Link();
}
m_initialized = true;
DLOG() << "initialized" << m_initialized;
}