void OpenGLRenderable::initializeGLRenderable(bool pAllowAliasing) { static bool sMakingCurrent = false; CG_GL_ERROR_CHECK if(!sMakingCurrent) { sMakingCurrent = true; if(!makeGLContextCurrent()) { printf("Error: could not enable current context (%s:%d).\n", __FILE__, __LINE__); fflush(stdout); } sMakingCurrent = false; } // Basic OpenGL setup glClearColor(0.0, 0.0, 0.0, 0.0); glEnable(GL_TEXTURE_2D); mAllowAliasing = pAllowAliasing; if(!mAllowAliasing) glEnable(GL_MULTISAMPLE); else glDisable(GL_MULTISAMPLE); if(!mOrtho2D) glEnable(GL_DEPTH_TEST); CG_GL_ERROR_CHECK }
void OpenGLRenderable::initializeGLRenderable(bool pAllowAliasing) { static bool sMakingCurrent = false; CG_GL_ERROR_CHECK if(!sMakingCurrent) { sMakingCurrent = true; if(!makeGLContextCurrent()) { printf("Error: could not enable current context (%s:%d).\n", __FILE__, __LINE__); fflush(stdout); } sMakingCurrent = false; } /* EDIT: GLEW support is disabled for now, may bring back later // Initialize GLEW static GLenum err = glewInit(); if(err != GLEW_OK) fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); */ // Basic OpenGL setup glClearColor(0.0, 0.0, 0.0, 0.0); glEnable(GL_TEXTURE_2D); mAllowAliasing = pAllowAliasing; if(!mAllowAliasing) glEnable(GL_MULTISAMPLE); else glDisable(GL_MULTISAMPLE); if(!mOrtho2D) glEnable(GL_DEPTH_TEST); CG_GL_ERROR_CHECK }
void StelQGLRenderer::renderFrame(StelRenderClient& renderClient) { invariant(); recentFrames.update(); clearFrameStatistics(); if(previousFrameEndTime < 0.0) { previousFrameEndTime = StelApp::getTotalRunTime(); } viewport.setDefaultPainter(renderClient.getPainter(), glContext); makeGLContextCurrent(); viewport.startFrame(); // When using the GUI, try to have the best reactivity, // even if we need to lower the FPS. const int minFps = StelApp::getInstance().getGui()->isCurrentlyUsed() ? 16 : 2; glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); while (true) { const bool doneDrawing = !renderClient.drawPartial(); if(doneDrawing) { viewport.finishFrame(); break; } const double spentTime = StelApp::getTotalRunTime() - previousFrameEndTime; // We need FBOs to do partial drawing. if (viewport.useFBO() && 1.0 / spentTime <= minFps) { // We stop the painting operation for now viewport.suspendFrame(); break; } } drawWindow(renderClient.getViewportEffect()); viewport.setDefaultPainter(NULL, glContext); // Flushing GL commands helps FPS somewhat (not sure why, though) glFlush(); previousFrameEndTime = StelApp::getTotalRunTime(); invariant(); }
void GL3DShaderWidget::paintGL() { // If it's not yet visible don't try and draw (you can upset OpenGL on some systems if you do) if(!isVisible()) return; CG_GL_ERROR_CHECK // Make sure this OpenGL context is current #ifdef GLCONTEXT_DEBUG fprintf(stderr, "Making current (%s:%d)\n", __FILE__, __LINE__); fflush(stderr); #endif makeGLContextCurrent(); CG_GL_ERROR_CHECK // Clear the buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); CG_GL_ERROR_CHECK // Allow special processing before drawContents() (implement in child) // Note: buffer clears before but not after, shader is not bound if(mShader != NULL) mShader->release(); CG_GL_ERROR_CHECK prePaint(); CG_GL_ERROR_CHECK // Bind the shader and draw the maincontents if(mShader != NULL) mShader->bind(); else glColor4f(0.0, 0.0, 0.0, 1.0); drawContents(); CG_GL_ERROR_CHECK // Allow special procesing after drawContents() but before buffer swap (implement in child) // Note: shader is not bound if(mShader != NULL) mShader->release(); postPaintPreSwap(); CG_GL_ERROR_CHECK // Swap back and front buffers // NO! Qt does this automatically and doing it manually will cause a // double swap on some OSs and seisure inducing flashing. // swapBuffers(); }