1. <tfoot id='ypHM5'></tfoot>

    <small id='ypHM5'></small><noframes id='ypHM5'>

    • <bdo id='ypHM5'></bdo><ul id='ypHM5'></ul>

  2. <i id='ypHM5'><tr id='ypHM5'><dt id='ypHM5'><q id='ypHM5'><span id='ypHM5'><b id='ypHM5'><form id='ypHM5'><ins id='ypHM5'></ins><ul id='ypHM5'></ul><sub id='ypHM5'></sub></form><legend id='ypHM5'></legend><bdo id='ypHM5'><pre id='ypHM5'><center id='ypHM5'></center></pre></bdo></b><th id='ypHM5'></th></span></q></dt></tr></i><div id='ypHM5'><tfoot id='ypHM5'></tfoot><dl id='ypHM5'><fieldset id='ypHM5'></fieldset></dl></div>
    <legend id='ypHM5'><style id='ypHM5'><dir id='ypHM5'><q id='ypHM5'></q></dir></style></legend>

    1. C++ OpenGL 窗口只跟踪背景

      时间:2023-09-17
        <bdo id='UG1jL'></bdo><ul id='UG1jL'></ul>
        <legend id='UG1jL'><style id='UG1jL'><dir id='UG1jL'><q id='UG1jL'></q></dir></style></legend>

        <small id='UG1jL'></small><noframes id='UG1jL'>

        <tfoot id='UG1jL'></tfoot>

              <i id='UG1jL'><tr id='UG1jL'><dt id='UG1jL'><q id='UG1jL'><span id='UG1jL'><b id='UG1jL'><form id='UG1jL'><ins id='UG1jL'></ins><ul id='UG1jL'></ul><sub id='UG1jL'></sub></form><legend id='UG1jL'></legend><bdo id='UG1jL'><pre id='UG1jL'><center id='UG1jL'></center></pre></bdo></b><th id='UG1jL'></th></span></q></dt></tr></i><div id='UG1jL'><tfoot id='UG1jL'></tfoot><dl id='UG1jL'><fieldset id='UG1jL'></fieldset></dl></div>
                  <tbody id='UG1jL'></tbody>
                本文介绍了C++ OpenGL 窗口只跟踪背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                Anyone knows why this happens when trying to generate a simple square in OpenGL?

                I am using the following source code from the book Computer Graphics Through OpenGL: From Theory to Experiments.

                ////////////////////////////////////////////////////          
                // square.cpp
                //
                // Stripped down OpenGL program that draws a square.
                // 
                // Sumanta Guha.
                ////////////////////////////////////////////////////
                
                #include <iostream>
                
                #ifdef __APPLE__
                #  include <GLUT/glut.h>
                #else
                #  include <GL/glut.h>
                #endif
                
                using namespace std;
                
                // Drawing (display) routine.
                void drawScene(void)
                {
                   // Clear screen to background color.
                   glClear(GL_COLOR_BUFFER_BIT);
                
                   // Set foreground (or drawing) color.
                   glColor3f(0.0, 0.0, 0.0);
                
                   // Draw a polygon with specified vertices.
                   glBegin(GL_POLYGON);
                      glVertex3f(20.0, 20.0, 0.0);
                      glVertex3f(80.0, 20.0, 0.0);
                      glVertex3f(80.0, 80.0, 0.0);
                      glVertex3f(20.0, 80.0, 0.0);
                   glEnd();
                
                   // Flush created objects to the screen, i.e., force rendering.
                   glFlush(); 
                }
                
                // Initialization routine.
                void setup(void) 
                {
                   // Set background (or clearing) color.
                   glClearColor(1.0, 1.0, 1.0, 0.0); 
                }
                
                // OpenGL window reshape routine.
                void resize(int w, int h)
                {
                   // Set viewport size to be entire OpenGL window.
                   glViewport(0, 0, (GLsizei)w, (GLsizei)h);
                
                   // Set matrix mode to projection.
                   glMatrixMode(GL_PROJECTION);
                
                   // Clear current projection matrix to identity.
                   glLoadIdentity();
                
                   // Specify the orthographic (or perpendicular) projection, 
                   // i.e., define the viewing box.
                   glOrtho(0.0, 100.0, 0.0, 100.0, -1.0, 1.0);
                
                   // Set matrix mode to modelview.
                   glMatrixMode(GL_MODELVIEW);
                
                   // Clear current modelview matrix to identity.
                   glLoadIdentity();
                }
                
                // Keyboard input processing routine.
                void keyInput(unsigned char key, int x, int y)
                {
                   switch(key) 
                   {
                  // Press escape to exit.
                      case 27:
                         exit(0);
                         break;
                      default:
                         break;
                   }
                }
                
                // Main routine: defines window properties, creates window,
                // registers callback routines and begins processing.
                int main(int argc, char **argv) 
                {  
                   // Initialize GLUT.
                   glutInit(&argc, argv);
                
                   // Set display mode as single-buffered and RGB color.
                   glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); 
                
                   // Set OpenGL window size.
                   glutInitWindowSize(500, 500);
                
                   // Set position of OpenGL window upper-left corner.
                   glutInitWindowPosition(100, 100); 
                
                   // Create OpenGL window with title.
                   glutCreateWindow("square.cpp");
                
                   // Initialize.
                   setup(); 
                
                   // Register display routine.
                   glutDisplayFunc(drawScene); 
                
                   // Register reshape routine.
                   glutReshapeFunc(resize);  
                
                   // Register keyboard routine.
                   glutKeyboardFunc(keyInput);
                
                   // Begin processing.
                   glutMainLoop(); 
                
                   return 0;  
                }
                

                I've been trying for the longest time...

                For more details here:

                The screen opens displaying only the background, if you drag it along, it will then proceed to track the background, and this is the result of moving the window to the bottom and then moving it up to the original position again. I've tested the same source code on a linux machine, and it works fine... :(

                EDIT: I have tried using glutSwapBuffers() and that didn't seem to work either.

                解决方案

                On Windows Vista and newer Windows operating systems, there is a component known as the Desktop Window Manager (DWM) which has a special mode called "Desktop Composition" that draws windows into offscreen buffers and then composites them. It does this to provide new visual effects such as live window previews in the Alt+Tab screen.

                A consequence of this new architecture is that you cannot draw single buffered applications (in windowed mode anyway) the same way you could in Windows XP (or in Windows Vista+ with Desktop Composition disabled). In a nutshell, the DWM uses a copy of your render context's back buffer for composition. You should switch to double buffered drawing.

                To use double buffered drawing in GLUT, you would use GLUT_DOUBLE instead of GLUT_SINGLE in your call to glutInitDisplayMode (...). Additionally, you need to replace your calls to glFlush (...) with glutSwapBuffers (...).

                这篇关于C++ OpenGL 窗口只跟踪背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何在不违反 C++ 核心准则的情况下将整数转换为 下一篇:c++ - 当c ++未指定结构布局时,为什么glBufferData可

                相关文章

                最新文章

                1. <legend id='uGddA'><style id='uGddA'><dir id='uGddA'><q id='uGddA'></q></dir></style></legend>
                2. <small id='uGddA'></small><noframes id='uGddA'>

                3. <tfoot id='uGddA'></tfoot>
                    <bdo id='uGddA'></bdo><ul id='uGddA'></ul>

                  <i id='uGddA'><tr id='uGddA'><dt id='uGddA'><q id='uGddA'><span id='uGddA'><b id='uGddA'><form id='uGddA'><ins id='uGddA'></ins><ul id='uGddA'></ul><sub id='uGddA'></sub></form><legend id='uGddA'></legend><bdo id='uGddA'><pre id='uGddA'><center id='uGddA'></center></pre></bdo></b><th id='uGddA'></th></span></q></dt></tr></i><div id='uGddA'><tfoot id='uGddA'></tfoot><dl id='uGddA'><fieldset id='uGddA'></fieldset></dl></div>