Examples: OpenGL2/3: Save/setup/restore viewport as part of render function. Update SDL example to match GL2 one. (fix #392)

This commit is contained in:
ocornut
2015-10-30 15:44:47 +01:00
parent 6ffe0fddbf
commit 980ca286fe
3 changed files with 22 additions and 11 deletions

View File

@ -30,8 +30,8 @@ void ImGui_ImplGlfw_RenderDrawLists(ImDrawData* draw_data)
{
// We are using the OpenGL fixed pipeline to make the example code simpler to read!
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers.
GLint last_texture;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -49,7 +49,8 @@ void ImGui_ImplGlfw_RenderDrawLists(ImDrawData* draw_data)
float fb_height = io.DisplaySize.y * io.DisplayFramebufferScale.y;
draw_data->ScaleClipRects(io.DisplayFramebufferScale);
// Setup orthographic projection matrix
// Setup viewport, orthographic projection matrix
glViewport(0, 0, (GLsizei)io.DisplaySize.x, (GLsizei)io.DisplaySize.y);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
@ -97,6 +98,7 @@ void ImGui_ImplGlfw_RenderDrawLists(ImDrawData* draw_data)
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glPopAttrib();
glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
}
static const char* ImGui_ImplGlfw_GetClipboardText()