本文整理汇总了C++中FrameBufferObject::Bind方法的典型用法代码示例。如果您正苦于以下问题:C++ FrameBufferObject::Bind方法的具体用法?C++ FrameBufferObject::Bind怎么用?C++ FrameBufferObject::Bind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FrameBufferObject
的用法示例。
在下文中一共展示了FrameBufferObject::Bind方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RenderIntoBuffer
void RenderIntoBuffer(FrameBufferObject fbo, GLuint handle)
{
fbo.Bind();
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-fbo.size.x/2, fbo.size.x/2, -fbo.size.y/2, fbo.size.y/2, 1, 10);
if (sh_vertices.size() == 0)
{
for (float i = -1.0; i <= 1.0; i += 0.01f)
{
for (float j = -1.0; j <= 1.0; j += 0.01f )
{
sh_vertices.push_back(glm::vec2( j, i ));
sh_vertices.push_back(glm::vec2( j + 0.01, i ));
sh_vertices.push_back(glm::vec2( j + 0.01, i + 0.01));
sh_vertices.push_back(glm::vec2( j, i + 0.01));
tex_vertices.push_back(glm::vec2( (j+1)/2.0f, (i+1)/2.0f ));
tex_vertices.push_back(glm::vec2( ((j + 0.01)+1)/2.0f, (i+1)/2.0f ));
tex_vertices.push_back(glm::vec2( ((j + 0.01)+1)/2.0f, ((i + 0.01)+1)/2.0f));
tex_vertices.push_back(glm::vec2( (j+1)/2.0f, ((i + 0.01)+1)/2.0f));
//Uncomment the code below to see the vertices
/*
cout << "Vertex Coords: " << i << ", " << j << " - ";
cout << i + 0.01 << ", " << j << " - ";
cout << i + 0.01 << ", " << j + 0.01 << " - ";
cout << i << ", " << j + 0.01 << endl;
//*/
}
}
glGenBuffers(1, &vertex_coordinate_handle);
assert(vertex_coordinate_handle != (GLuint) -1);
glBindBuffer(GL_ARRAY_BUFFER, vertex_coordinate_handle);
glBufferData(GL_ARRAY_BUFFER, sh_vertices.size() * sizeof(glm::vec2), &sh_vertices[0], GL_STATIC_DRAW);
glGenBuffers(1, &tex_coord_handle);
assert(tex_coord_handle != (GLuint) -1);
glBindBuffer(GL_ARRAY_BUFFER, tex_coord_handle);
glBufferData(GL_ARRAY_BUFFER, tex_vertices.size() * sizeof(glm::vec2), &tex_vertices[0], GL_STATIC_DRAW);
glGenVertexArrays(1, &vertex_array_handle);
glBindVertexArray(vertex_array_handle);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, vertex_coordinate_handle);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (GLubyte *) NULL);
glBindBuffer(GL_ARRAY_BUFFER, tex_coord_handle);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (GLubyte *) NULL);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
shader.Use();
glUniform2i(shader.size_handle, fbo.size.x, fbo.size.y);
glUniform2f(shader.mouse_handle, mouse.x, mouse.y);
glUniform2f(shader.mouse_start_handle, mouse_start.x, mouse_start.y);
glBindTexture(GL_TEXTURE_2D, handle);
glUniform1i(shader.image_handle, GL_TEXTURE0 + handle);
glViewport(0, 0, fbo.size.x, fbo.size.y);
glClearColor(0, 0, 0.5, 0);
glClear(GL_COLOR_BUFFER_BIT);
assert(vertex_array_handle != (GLuint) -1);
glBindVertexArray(vertex_array_handle);
glDrawArrays(GL_QUADS, 0, (GLsizei) sh_vertices.size());
glBindVertexArray(0);
glUseProgram(0);
glEnable(GL_DEPTH_TEST);
fbo.Unbind();
}
示例2: RenderIntoFrameBuffer
void RenderIntoFrameBuffer()
{
float time = float(glutGet(GLUT_ELAPSED_TIME)) / 1000.0f;
fbo.Bind();
glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushAttrib(GL_VIEWPORT_BIT | GL_TRANSFORM_BIT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPerspective(20, double(fbo.size.x) / double(fbo.size.y), 1, 10);
glViewport(0, 0, fbo.size.x, fbo.size.y);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
gluLookAt(0, 0, 5.5, 0, 0, 0, 0, 1, 0);
glRotatef(-time * 60.0f, 1.0f, 1.0f, 0.0f);
Axes();
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(0.0f, 0.5f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2f(-0.5f, -0.5f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex2f(0.5f, -0.5f);
glEnd();
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glPopAttrib();
fbo.Unbind();
fbo.Bind(1);
glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushAttrib(GL_VIEWPORT_BIT | GL_TRANSFORM_BIT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPerspective(20, double(fbo.size.x) / double(fbo.size.y), 1, 10);
glViewport(0, 0, fbo.size.x, fbo.size.y);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
gluLookAt(0, 0, 5.5, 0, 0, 0, 0, 1, 0);
glRotatef(-time * 60.0f, 1.0f, 1.0f, 0.0f);
Axes();
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 1.0f, 0.0f);
glVertex2f(0.0f, 0.5f);
glColor3f(0.0f, 1.0f, 1.0f);
glVertex2f(-0.5f, -0.5f);
glColor3f(1.0f, 0.0f, 1.0f);
glVertex2f(0.5f, -0.5f);
glEnd();
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glPopAttrib();
fbo.Unbind();
}