void QGLWidget::resizeEvent(QResizeEvent *) { Q_D(QGLWidget); if(!isValid()) return; if (!isWindow()) d->glcx->d_func()->update = true; makeCurrent(); if(!d->glcx->initialized()) glInit(); resizeGL(width(), height()); if(d->olcx) { makeOverlayCurrent(); aglUpdateContext((AGLContext)d->olcx); resizeOverlayGL(width(), height()); } }
///// translateZ ////////////////////////////////////////////////////////////// void GLView::translateZ(const int amount) /// Handles the request for a translation in /// the Z-direction. Here the complete scene is translated (=zoomed). { // a zoom over a distance of the height of the OpenGL window should translate // in half the size of the molecule if(amount != 0) { float zoomFactor = static_cast<float>(amount)/height(); // percentage if(baseParameters.perspectiveProjection) zoomFactor *= 2.0f * maxRadius; zPos += zoomFactor; if(zPos < 0.1f) zPos = 0.1f; if(!baseParameters.perspectiveProjection) resizeGL(width(), height()); // zooming for ortho projection is in fact direct scaling of the view } }
void GLWidget::initializeGL() { QGLWidget::initializeGL(); qglClearColor(Qt::black); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glFrontFace(GL_CCW); glEnable(GL_NORMALIZE); // Initialise shaders program = new QGLShaderProgram(); initShaders(); resizeGL(this->size().width(), this->size().height()); // Initialise geometry objects object = new Cube(); object->init(); }
int main(int argc, char *argv[]) { string recipe = parseCLArgs(argc, argv); // Initialize GLFW if( !glfwInit() ) exit( EXIT_FAILURE ); // Select OpenGL 4.3 with a forward compatible core profile. glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 4 ); glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 3 ); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); // Open the window string title = "Chapter 03 -- " + recipe; window = glfwCreateWindow( WIN_WIDTH, WIN_HEIGHT, title.c_str(), NULL, NULL ); if( !window ) { glfwTerminate(); exit( EXIT_FAILURE ); } glfwMakeContextCurrent(window); // Load the OpenGL functions. if( ogl_LoadFunctions() == ogl_LOAD_FAILED ) { glfwTerminate(); exit(EXIT_FAILURE); } GLUtils::dumpGLInfo(); // Initialization initializeGL(); resizeGL(WIN_WIDTH,WIN_HEIGHT); // Enter the main loop mainLoop(); // Close window and terminate GLFW glfwTerminate(); // Exit program exit( EXIT_SUCCESS ); }
int main(int argc, char *argv[]) { string recipe = parseCLArgs(argc, argv); // Initialize GLFW if( !glfwInit() ) exit( EXIT_FAILURE ); // Select OpenGL 3.2 with a forward compatible core profile. glfwOpenWindowHint( GLFW_OPENGL_VERSION_MAJOR, 4 ); glfwOpenWindowHint( GLFW_OPENGL_VERSION_MINOR, 3 ); glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE); glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 8); // Open the window if( !glfwOpenWindow( WIN_WIDTH, WIN_HEIGHT, 8,8,8,8,24,0, GLFW_WINDOW ) ) { glfwTerminate(); exit( EXIT_FAILURE ); } string title = "Chapter 9 -- " + recipe; glfwSetWindowTitle(title.c_str()); // Load the OpenGL functions. if( ogl_LoadFunctions() == ogl_LOAD_FAILED ) { glfwTerminate(); exit(EXIT_FAILURE); } GLUtils::dumpGLInfo(); // Initialization initializeGL(); resizeGL(WIN_WIDTH,WIN_HEIGHT); // Enter the main loop mainLoop(); // Close window and terminate GLFW glfwTerminate(); // Exit program exit( EXIT_SUCCESS ); }
void QGLWidget::glDraw() { makeCurrent(); if ( glcx->deviceIsPixmap() ) glDrawBuffer( GL_FRONT_LEFT ); if ( !glcx->initialized() ) { glInit(); QPaintDeviceMetrics dm( glcx->device() ); resizeGL( dm.width(), dm.height() ); // New context needs this "resize" } paintGL(); if ( doubleBuffer() ) { if ( autoSwap ) swapBuffers(); } else { glFlush(); } }
void ExampleRenderThread::run( ) { // lock the render mutex of the Gl widget // and makes the rendering context of the glwidget current in this thread glw.lockGLContext(); // general GL init initializeGL(); // do as long as the flag is true while( render_flag ) { // resize the GL viewport if requested if (resize_flag) { resizeGL(viewport_size.width(), viewport_size.height()); resize_flag = false; } // render code goes here paintGL(); // swap the buffers of the GL widget glw.swapBuffers(); glw.doneCurrent(); // release the GL render context to make picking work! // wait until the gl widget says that there is something to render // glwidget.lockGlContext() had to be called before (see top of the function)! // this will release the render mutex until the wait condition is met // and will lock the render mutex again before exiting // waiting this way instead of insane looping will not waste any CPU ressources glw.renderCondition().wait(&glw.renderMutex()); glw.makeCurrent(); // get the GL render context back // DEACTIVATED -- alternatively render a frame after a certain amount of time // prevent to much continous rendering activity // msleep(16); //sleep for 16 ms } // unlock the render mutex before exit glw.unlockGLContext(); }
void SDLMainLoop::handleEvents() { SDL_Event event; while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: EMIT_EVENT(new Event::QuitEvent()); break; case SDL_VIDEORESIZE: SDL_SetVideoMode(event.resize.w, event.resize.h, 0, sdl_init_flags); resizeGL(event.resize.w, event.resize.h); /*projector.setCurrentDimensions( Point2D(event.resize.w, event.resize.h));*/ break; } loop->handleEvent(&event); inputManager->getInputMapper()->handleEvent(&event); } }
void PCViewerWidget::initializeGL() { glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glClearDepth(1.0); glDepthFunc(GL_LESS); glShadeModel(GL_SMOOTH); // line anti-aliasing glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LINE_SMOOTH); // light values and coordinates glFrontFace(GL_CCW); glEnable(GL_CULL_FACE); // Enable lighting // glEnable(GL_LIGHTING); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, whiteLight); glLightfv(GL_LIGHT0, GL_DIFFUSE, sourceLight); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glLightfv(GL_LIGHT0, GL_SPECULAR, specular); glEnable(GL_LIGHT0); // Enable color tracking glEnable(GL_COLOR_MATERIAL); // Set Material properties to follow glColor values glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); // Set Material shine with specular light glMaterialfv(GL_FRONT, GL_SPECULAR, specular); glMateriali(GL_FRONT, GL_SHININESS, 1); resizeGL(1280, 480); }
void OpenGLWidget::wheelEvent(QWheelEvent *e) { QPoint numDegrees = e->angleDelta() / 8; if (!numDegrees.isNull()) { QPoint numSteps = numDegrees / 15; QVector3D val = m_camera.position() - QVector3D(0, 0, numSteps.y()); if (val.z() > m_camera.farPlane() || val.z() < m_camera.nearPlane()) return; m_camera.setPosition(val); resizeGL(width(), height()); updateGL(); } e->accept(); }
// --------------------------------------------------------------------------- // Function: initGL // Design: Belongs to OpenGL component // Purpose: // Updated: Sep 10, 2012 // --------------------------------------------------------------------------- void initGL() { //glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.1f, 0.0f, 1.0f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // We use resizeGL once to set up our initial perspective resizeGL(windowWidth, windowHeight);//physicalWidth,physicalHeight);//width, height); top = 1.0f; bottom = 0.0f; // top = -top; // bottom = -bottom; glFlush(); }
void initGL(unsigned int width, unsigned int height) { glClearColor(0, 0, 0, 0); //glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glDisable(GL_DEPTH_TEST); resizeGL(width, height); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); loadFunctions(); loadResources(); loadShaderProgram(SHADER_SRC); //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE); //glFrontFace(GL_CW); //glEnable(GL_CULL_FACE); //glCullFace(GL_BACK); // set up default camera g_cam_pos.x = 0; g_cam_pos.y = 0; g_cam_pos.z = -10; g_cam_rot.x = 0; g_cam_rot.y = 0; }
void QCastViewGL::wheelEvent(QWheelEvent *e) { double trans_scale = 0.01, zoom_scale = 0.5; if (e->modifiers() & Qt::ControlModifier) { const double lvlmin = -ZOOM_RANGE; const double lvlmax = ZOOM_RANGE; double lvl = zoomLevel; if (e->delta() > 0) zoomLevel += zoom_scale; else zoomLevel -= zoom_scale; if (zoomLevel < lvlmin) zoomLevel = lvlmin; if (zoomLevel > lvlmax) zoomLevel = lvlmax; if (lvl != zoomLevel) { resizeGL(this->width(), this->height()); updateGL(); } } else { double dz = (double) e->delta(); setCameraEye(m_camera.eye + m_camera.view * dz * trans_scale); } }
void SDLMainLoop::changeScreenModeHandler(Event::ChangeScreenMode *event) { int width = event->getWidth(); int height = event->getHeight(); int bpp = event->getBPP(); bool fullscreen = event->getFullscreen(); #ifndef WIN32 // special case: if just toggling fullscreen, and the operating system // supports it, can just call ToggleFullScreen instead of setting the mode if(width == GET_SETTING("display.width", 0) && height == GET_SETTING("display.height", 0) && bpp == GET_SETTING("display.bpp", 0) && fullscreen != GET_SETTING("display.fullscreen", 0)) { if(SDL_WM_ToggleFullScreen(SDL_GetVideoSurface())) return; } #endif Settings::SettingsManager::getInstance()->set( "display.width", Misc::StreamAsString() << width); Settings::SettingsManager::getInstance()->set( "display.height", Misc::StreamAsString() << height); Settings::SettingsManager::getInstance()->set( "display.bpp", Misc::StreamAsString() << bpp); Settings::SettingsManager::getInstance()->set( "display.fullscreen", Misc::StreamAsString() << fullscreen); if(fullscreen) { sdl_init_flags |= SDL_FULLSCREEN; } else { sdl_init_flags &= ~SDL_FULLSCREEN; } SDL_SetVideoMode(width, height, bpp, this->sdl_init_flags); resizeGL(width, height); }
void QGLWidget::resizeEvent(QResizeEvent *e) { Q_D(QGLWidget); if (!isValid()) return; // Shared widget can ignore resize events which // may happen due to orientation change if (this == qt_gl_share_widget()) return; if (!d->surfaceSizeInitialized || e->oldSize() != e->size()) { // On Symbian we need to recreate the surface on resize. d->recreateEglSurface(); d->surfaceSizeInitialized = true; } makeCurrent(); if (!d->glcx->initialized()) glInit(); resizeGL(width(), height()); }
void GLWidgetRenderer2::showEvent(QShowEvent *) { onShowEvent(); resizeGL(width(), height()); }
static int generated_defineMask(PARAM *p) { int w,h,depth; if(p == NULL) return 1; w = h = depth = strcmp(toolTip[0],whatsThis[0]); if(widgetType[0] == -1) return 1; if(w==h) depth=0; // fool the compiler pvStartDefinition(p,ID_END_OF_WIDGETS); printf("generated_defineMaks 1\n"); pvQGL(p,OpenGL1,0); printf("generated_defineMaks 2\n"); pvSetGeometry(p,OpenGL1,105,0,1024,768); printf("generated_defineMaks 3\n"); pvGlBegin(p,OpenGL1); printf("generated_defineMaks 4\n"); initializeGL(p); // (todo: write your gl initialization routine) see example printf("generated_defineMaks 5\n"); resizeGL(p,1024,768); // (todo: write your resize routine) see example printf("generated_defineMaks 6\n"); pvGlEnd(p); printf("generated_defineMaks 7\n"); pvQGroupBox(p,group1,0,-1,HORIZONTAL,"w2d"); pvSetGeometry(p,group1,0,0,100,515); pvSetFont(p,group1,"Sans Serif",10,0,0,0,0); pvSetMaxSize(p,group1,100,99999); pvQSlider(p,sliderPos,group1,0,100,1,10,Horizontal); pvSetGeometry(p,sliderPos,10,145,80,30); pvSetFont(p,sliderPos,"Sans Serif",10,0,0,0,0); pvQSlider(p,sliderScale,group1,0,100,1,31,Vertical); pvSetGeometry(p,sliderScale,70,55,25,75); pvSetFont(p,sliderScale,"Sans Serif",10,0,0,0,0); pvDownloadFile(p,"1center.png"); pvQImage(p,btCenter,group1,"1center.png",&w,&h,&depth); pvSetGeometry(p,btCenter,25,85,25,25); pvSetFont(p,btCenter,"Sans Serif",10,0,0,0,0); pvDownloadFile(p,"1leftarrow.png"); pvQImage(p,btLeft,group1,"1leftarrow.png",&w,&h,&depth); pvSetGeometry(p,btLeft,5,85,25,25); pvSetFont(p,btLeft,"Sans Serif",10,0,0,0,0); pvDownloadFile(p,"1rightarrow.png"); pvQImage(p,btRight,group1,"1rightarrow.png",&w,&h,&depth); pvSetGeometry(p,btRight,45,85,25,25); pvSetFont(p,btRight,"Sans Serif",10,0,0,0,0); pvDownloadFile(p,"1uparrow.png"); pvQImage(p,btUp,group1,"1uparrow.png",&w,&h,&depth); pvSetGeometry(p,btUp,25,65,25,25); pvSetFont(p,btUp,"Sans Serif",10,0,0,0,0); pvDownloadFile(p,"1downarrow.png"); pvQImage(p,btDown,group1,"1downarrow.png",&w,&h,&depth); pvSetGeometry(p,btDown,25,105,25,25); pvSetFont(p,btDown,"Sans Serif",10,0,0,0,0); pvQLabel(p,obj1,group1); pvSetGeometry(p,obj1,80,45,15,15); pvSetText(p,obj1,"+"); pvSetFont(p,obj1,"Sans Serif",10,0,0,0,0); pvQPushButton(p,btBack,group1); pvSetGeometry(p,btBack,5,25,75,30); pvSetText(p,btBack,"Back"); pvSetFont(p,btBack,"Sans Serif",10,0,0,0,0); pvQLabel(p,obj2,group1); pvSetGeometry(p,obj2,80,135,15,15); pvSetText(p,obj2,"-"); pvSetFont(p,obj2,"Sans Serif",10,0,0,0,0); pvQLayoutHbox(p,ID_MAIN_WIDGET,-1); pvQLayoutVbox(p,layout1,-1); pvAddWidgetOrLayout(p,ID_MAIN_WIDGET,layout1,-1,-1); pvAddWidgetOrLayout(p,ID_MAIN_WIDGET,OpenGL1,-1,-1); pvAddWidgetOrLayout(p,layout1,group1,-1,-1); printf("generated_defineMaks x\n"); pvEndDefinition(p); printf("generated_defineMaks end\n"); return 0; }
void QXipIvWidget::resizeEvent(QResizeEvent* event) { QWidget::resizeEvent(event); resizeGL(width(), height()); }
void QSceneWidget::resizeEvent(QResizeEvent *event) { resizeGL(event->size().width(), event->size().height()); }
int SDL2TestApplication::run() { m_window = SDL_CreateWindow("SDL2TestApplication", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 0, 0, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN); if (m_window == NULL) { printf("Could not create window: %s\n", SDL_GetError()); return 1; } int w, h; SDL_GetWindowSize(m_window, &w, &h); printf("Window size after create: (%d, %d)\n", w, h); #if 0 SDL_SetWindowFullscreen(window, SDL_FALSE); SDL_GetWindowSize(window, &w, &h); printf("Window size after fullscreen off: (%d, %d)\n", w, h); SDL_SetWindowSize(window, 200, 200); SDL_GetWindowSize(window, &w, &h); printf("Window size after resize: (%d, %d)\n", w, h); SDL_SetWindowFullscreen(window, SDL_TRUE); SDL_GetWindowSize(window, &w, &h); printf("Window size after fullscreen on: (%d, %d)\n", w, h); #endif if (m_major != 0 && m_minor != 0) { SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, m_major); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, m_minor); } m_gl_context = SDL_GL_CreateContext(m_window); initGL(); resizeGL(w, h); std::list<TouchPoint*>::iterator it; TouchPoint *touch; SDL_Event event; int quit = 0; while (!quit) { while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: quit = 1; break; case SDL_WINDOWEVENT: printf("Window event: %d (%d, %d)\n", event.window.event, event.window.data1, event.window.data2); break; case SDL_FINGERDOWN: touch = new TouchPoint(event.tfinger.fingerId, event.tfinger.x, event.tfinger.y); m_touches.push_back(touch); onPressed(touch); printf("Finger down: (%.2f, %.2f)\n", touch->x, touch->y); break; case SDL_FINGERUP: case SDL_FINGERMOTION: for (it=m_touches.begin(); it != m_touches.end(); ++it) { touch = *it; if (touch->id == event.tfinger.fingerId) { if (event.type == SDL_FINGERMOTION) { touch->x = event.tfinger.x; touch->y = event.tfinger.y; printf("finger move: (%.2f, %.2f)\n", touch->x, touch->y); } else { printf("Finger up: (%.2f, %.2f)\n", touch->x, touch->y); m_touches.erase(it); } break; } } break; default: printf("SDL Event: %d\n", event.type); break; } } if (quit) { /* Application has to quit - don't render anymore */ break; } renderGL(); SDL_GL_SwapWindow(m_window); SDL_Delay(10); } SDL_GL_DeleteContext(m_gl_context); SDL_DestroyWindow(m_window); SDL_Quit(); return 0; }
void VibratoSpeedWidget::doUpdate() { Channel *active = gdata->getActiveChannel(); float vibratoSpeed = 0; float vibratoWidth = 0; int currentNoteNumber = -1; if(active) { //if ((active) && (active->doingDetailedPitch()) && (active->pitchLookupSmoothed.size() > 0)) { AnalysisData *data; if(gdata->soundMode & SOUND_REC) data = active->dataAtChunk(active->chunkAtCurrentTime() - active->pronyDelay()); else data = active->dataAtCurrentChunk(); if(data && active->isVisibleNote(data->noteIndex) && active->isLabelNote(data->noteIndex)) { NoteData *note = new NoteData(); note = &(active->noteData[data->noteIndex]); currentNoteNumber = data->noteIndex; if (useProny) { vibratoSpeed = data->vibratoSpeed; vibratoWidth = 200 * data->vibratoWidth; } else if((active->doingDetailedPitch()) && (active->pitchLookupSmoothed.size() > 0)) { large_vector<float> pitchLookupUsed = active->pitchLookupSmoothed; int smoothDelay = active->pitchBigSmoothingFilter->delay(); int currentTime = active->chunkAtCurrentTime() * active->framesPerChunk() + smoothDelay; int maximumTime = 0; int minimumTime = 0; int maximaSize = note->maxima->size(); int minimaSize = note->minima->size(); // Find the most recent maximum for (int i = 1; i < maximaSize; i++) { if ((currentTime > note->maxima->at(i-1)) && (currentTime <= note->maxima->at(i))) { maximumTime = note->maxima->at(i-1); break; } } if ((maximaSize > 0) && (currentTime > note->maxima->at(maximaSize - 1))) { maximumTime = note->maxima->at(maximaSize - 1); } // Find the most recent minimum for (int i = 1; i < note->minima->size(); i++) { if ((currentTime > note->minima->at(i-1)) && (currentTime <= note->minima->at(i))) { minimumTime = note->minima->at(i-1); break; } } if ((note->minima->size() > 0) && (currentTime > note->minima->at(minimaSize - 1))) { minimumTime = note->minima->at(minimaSize - 1); } if ((maximumTime !=0 ) && (minimumTime != 0)) { // The speed and width can be calculated vibratoSpeed = active->rate() / (float)(2 * abs(maximumTime - minimumTime)); vibratoWidth = fabs(100 * (pitchLookupUsed.at(maximumTime) - pitchLookupUsed.at(minimumTime))); } } } } if ((fabs(prevVibratoSpeed - vibratoSpeed) < 0.05) && (fabs(prevVibratoWidth - vibratoWidth) < 0.05)) { // Needle values haven't changed (much) , no update needed } else { // Needle values have changed makeCurrent(); glNewList(speedNeedle, GL_COMPILE); glEndList(); glNewList(widthNeedle, GL_COMPILE); glEndList(); if ((vibratoSpeed == 0) && (vibratoWidth == 0)) { // No needle values, don't draw the needles this update prevVibratoSpeed = 0; prevVibratoWidth = 0; speedValueToDraw = 0; widthValueToDraw = 0; prevNoteNumber = -1; updateGL(); } else { // Needle values, draw the needles this update prevVibratoSpeed = vibratoSpeed; prevVibratoWidth = vibratoWidth; speedValueToDraw = vibratoSpeed; widthValueToDraw = vibratoWidth; const float halfWidth = 0.5 * width(); const float halfHeight = 0.5 * height(); const float radius = 1.8 * MAX(0.5 * height(), halfWidth); const float theta = asin(float(width()) / (2 * radius)); const float rho = (PI * 0.5) - theta; const int halfKnobWidth = MAX(toInt(radius * 0.02), 1); // Calculate the speed needle, if speedValueToDraw is set to sensible value if ((speedValueToDraw > 0) && (speedValueToDraw <= 12)) { const float centerX = halfWidth; const float centerY = height() - radius; float hzAngle = (2 * theta) / 14.0; float note = PI - rho - (speedValueToDraw * hzAngle) - hzAngle; float noteX = centerX + radius * cos(note); float noteY = centerY + radius * sin(note); float knobLeftX = centerX - halfKnobWidth; float knobLeftY = centerY; float knobRightX = centerX + halfKnobWidth; float knobRightY = centerY; glNewList(speedNeedle, GL_COMPILE); // Inside of the needle glBegin(GL_TRIANGLES); glColor3ub(255, 0, 0); glVertex2f(noteX, noteY); glVertex2f(knobLeftX, knobLeftY); glVertex2f(knobRightX, knobRightY); glEnd(); // Outside of the needle glBegin(GL_LINE_LOOP); glColor3ub(127, 0, 0); glVertex2f(noteX, noteY); glVertex2f(knobLeftX, knobLeftY); glVertex2f(knobRightX, knobRightY); glEnd(); glEndList(); } // Determine whether the scale needs adjusting int oldWidthLimit = widthLimit; if ((widthValueToDraw > 0) && (currentNoteNumber == prevNoteNumber)) { if (widthValueToDraw > 50) { widthLimit = std::max(widthLimit, 100); } if (widthValueToDraw > 100) { widthLimit = std::max(widthLimit, 200); } if (widthValueToDraw > 200) { widthLimit = std::max(widthLimit, 300); } } if (prevNoteNumber != currentNoteNumber) { widthLimit = 50; } if (widthLimit != oldWidthLimit) { // Do resize and redraw the dial if the scale is adjusted resizeGL(width(), height()); } prevNoteNumber = currentNoteNumber; // Calculate the width needle, if widthValueToDraw is set to sensible value if ((widthValueToDraw > 0) && (widthValueToDraw <= widthLimit)) { const float centerX = halfWidth; const float centerY = halfHeight - radius; float centAngle = (2 * theta) / (widthLimit + 2 * (widthLimit/10)); float note = PI - rho - (widthValueToDraw * centAngle) - (widthLimit/10) * centAngle; int halfKnobWidth = MAX(toInt(radius * 0.02), 1); float noteX = centerX + radius * cos(note); float noteY = centerY + radius * sin(note); float knobLeftX = centerX - halfKnobWidth; float knobLeftY = centerY; float knobRightX = centerX + halfKnobWidth; float knobRightY = centerY; glNewList(widthNeedle, GL_COMPILE); // Inside of the needle glBegin(GL_TRIANGLES); glColor3ub(255, 0, 0); glVertex2f(noteX, noteY); glVertex2f(knobLeftX, knobLeftY); glVertex2f(knobRightX, knobRightY); glEnd(); // Outside of the needle glBegin(GL_LINE_LOOP); glColor3ub(127, 0, 0); glVertex2f(noteX, noteY); glVertex2f(knobLeftX, knobLeftY); glVertex2f(knobRightX, knobRightY); glEnd(); glEndList(); } updateGL(); } } }
void hrRender::setZoom(float zoom) { this->zoom = zoom; resizeGL(width()*devicePixelRatio(), height()*devicePixelRatio()); updateGL(); }
void GLWidget::resizeEvent(QResizeEvent *event) { resizeGL(width(), height()); }
void LifeWidget::paintGL() { float caseXmin, caseYmin, caseXmax, caseYmax; if ((mouseX <= 1.0) && (mouseX >= 0.0) && (mouseY <= 1.0) && (mouseY >= 0.0)) setCursor(NULL); else setCursor(Qt::ArrowCursor); glPushAttrib(GL_ALL_ATTRIB_BITS); glMatrixMode(GL_PROJECTION); glPushMatrix(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); resizeGL(width(), height()); glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glColor3f(0.0, 0.2, 0.8); glBegin(GL_QUADS); for (int i = 0; i < nbCases; i++) for (int j = 0; j < nbCases; j++) if (lifeGame->isAlive(i, j)) { caseXmin =(float)i / (float)nbCases; caseXmax =(float)(i + 1) / (float)nbCases; caseYmin =(float)j / (float)nbCases; caseYmax =(float)(j + 1) / (float)nbCases; glVertex3f(caseXmin, caseYmin, -0.1); glVertex3f(caseXmin, caseYmax, -0.1); glVertex3f(caseXmax, caseYmax, -0.1); glVertex3f(caseXmax, caseYmin, -0.1); } glEnd(); if (showGrid) { glColor3f(0.5, 0.5, 0.5); glBegin(GL_LINES); for (int i = 0; i <= nbCases; i++) { float j = (float)i / (float)nbCases; glVertex3f(0.0, j, -0.05); glVertex3f(1.0, j, -0.05); glVertex3f(j, 0.0, -0.05); glVertex3f(j, 1.0, -0.05); } glEnd(); } glColor3f(1.0, 0.0, 0.0); glBegin(GL_LINE_LOOP); caseXmin =(float)posX / (float)nbCases; caseXmax =(float)(posX + 1) / (float)nbCases; caseYmin =(float)posY / (float)nbCases; caseYmax =(float)(posY + 1) / (float)nbCases; glVertex3f(caseXmin, caseYmin, -0.02); glVertex3f(caseXmin, caseYmax, -0.02); glVertex3f(caseXmax, caseYmax, -0.02); glVertex3f(caseXmax, caseYmin, -0.02); glEnd(); glColor3f(0.0, 1.0, 1.0); glBegin(GL_LINES); glVertex3f(mouseX - 0.01, mouseY, -0.01); glVertex3f(mouseX - 0.0025, mouseY, -0.01); glVertex3f(mouseX + 0.01, mouseY, -0.01); glVertex3f(mouseX + 0.0025, mouseY, -0.01); glVertex3f(mouseX, mouseY - 0.01, -0.01); glVertex3f(mouseX, mouseY - 0.0025, -0.01); glVertex3f(mouseX, mouseY + 0.01, -0.01); glVertex3f(mouseX, mouseY + 0.0025, -0.01); glEnd(); glFlush(); glPopAttrib(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); }
void View3D::paintGL() { if (m_badOpenGL) return; QTime frameTimer; frameTimer.start(); // Get window size double dPR = getDevicePixelRatio(); int w = width() * dPR; int h = height() * dPR; // detecting a change in the device pixel ratio, since only the new QWindow (Qt5) would // provide a signal for screen changes and this is the easiest solution if (dPR != m_devicePixelRatio) { m_devicePixelRatio = dPR; resizeGL(w, h); } glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_incrementalFramebuffer); //-------------------------------------------------- // Draw main scene TransformState transState(Imath::V2i(w, h), m_camera.projectionMatrix(), m_camera.viewMatrix()); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glClearColor(m_backgroundColor.redF(), m_backgroundColor.greenF(), m_backgroundColor.blueF(), 1.0f); if (!m_incrementalDraw) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); std::vector<const Geometry*> geoms = selectedGeometry(); // Draw bounding boxes if(m_drawBoundingBoxes && !m_incrementalDraw) { if (m_boundingBoxShader->isValid()) { QGLShaderProgram &boundingBoxShader = m_boundingBoxShader->shaderProgram(); // shader boundingBoxShader.bind(); // matrix stack transState.setUniforms(boundingBoxShader.programId()); for (size_t i = 0; i < geoms.size(); ++i) { drawBoundingBox(transState, geoms[i]->getVAO("boundingbox"), geoms[i]->boundingBox().min, Imath::C3f(1), geoms[i]->shaderId("boundingbox")); //boundingBoxShader.programId() } } } // Draw meshes and lines if (!m_incrementalDraw) { drawMeshes(transState, geoms); // Generic draw for any other geometry // (TODO: make all geometries use this interface, or something similar) // FIXME - Do generic quality scaling const double quality = 1; for (size_t i = 0; i < geoms.size(); ++i) geoms[i]->draw(transState, quality); } // Aim for 40ms frame time - an ok tradeoff for desktop usage const double targetMillisecs = 40; double quality = m_drawCostModel.quality(targetMillisecs, geoms, transState, m_incrementalDraw); // Render points DrawCount drawCount = drawPoints(transState, geoms, quality, m_incrementalDraw); // Measure frame time to update estimate for how much geometry we can draw // with a reasonable frame rate glFinish(); int frameTime = frameTimer.elapsed(); if (!geoms.empty()) m_drawCostModel.addSample(drawCount, frameTime); // Debug: print bar showing how well we're sticking to the frame time // int barSize = 40; // std::string s = std::string(barSize*frameTime/targetMillisecs, '='); // if ((int)s.size() > barSize) // s[barSize] = '|'; // tfm::printfln("%12f %4d %s", quality, frameTime, s); // TODO: this should really render a texture onto a quad and not use glBlitFramebuffer glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindFramebuffer(GL_READ_FRAMEBUFFER, m_incrementalFramebuffer); glBlitFramebuffer(0,0,w,h, 0,0,w,h, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); // has to be GL_NEAREST to work with DEPTH // Draw a grid for orientation purposes if (m_drawGrid) drawGrid(); // Draw overlay stuff, including cursor position. if (m_drawCursor) drawCursor(transState, m_cursorPos, 10); //drawCursor(transState, m_camera.center(), 10); // Draw overlay axes if (m_drawAxes) drawAxes(); // Set up timer to draw a high quality frame if necessary if (!drawCount.moreToDraw) m_incrementalFrameTimer->stop(); else m_incrementalFrameTimer->start(10); m_incrementalDraw = true; glFrameBufferStatus(m_incrementalFramebuffer); glCheckError(); }
void GLWidget::initializeGL() { resizeGL(width(),height()); }
void CaptureWinGLEngine::changeShader() { m_formatChange = false; clearShader(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, m_frameWidth, m_frameHeight, 0, 0, 1); resizeGL(QGLWidget::width(), QGLWidget::height()); checkError("Render settings.\n"); switch (m_frameFormat) { case V4L2_PIX_FMT_YUYV: case V4L2_PIX_FMT_YVYU: case V4L2_PIX_FMT_UYVY: case V4L2_PIX_FMT_VYUY: shader_YUY2(m_frameFormat); break; case V4L2_PIX_FMT_YUV420: case V4L2_PIX_FMT_YVU420: shader_YUV(); break; case V4L2_PIX_FMT_RGB32: m_screenTextureCount = 1; glActiveTexture(GL_TEXTURE0); glGenTextures(m_screenTextureCount, m_screenTexture); configureTexture(0); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA4, m_frameWidth, m_frameHeight, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, NULL); checkError("RGB32 shader"); break; case V4L2_PIX_FMT_BGR32: m_screenTextureCount = 1; glActiveTexture(GL_TEXTURE0); glGenTextures(m_screenTextureCount, m_screenTexture); configureTexture(0); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA4, m_frameWidth, m_frameHeight, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, NULL); checkError("BGR32 shader"); break; case V4L2_PIX_FMT_RGB555: m_screenTextureCount = 1; glActiveTexture(GL_TEXTURE0); glGenTextures(m_screenTextureCount, m_screenTexture); configureTexture(0); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5_A1, m_frameWidth, m_frameHeight, 0, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, NULL); checkError("RGB555 shader"); break; case V4L2_PIX_FMT_RGB565: m_screenTextureCount = 1; glActiveTexture(GL_TEXTURE0); glGenTextures(m_screenTextureCount, m_screenTexture); configureTexture(0); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_frameWidth, m_frameHeight, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL); checkError("RGB565 shader"); break; case V4L2_PIX_FMT_BGR24: shader_BGR(); break; case V4L2_PIX_FMT_RGB24: default: m_screenTextureCount = 1; glActiveTexture(GL_TEXTURE0); glGenTextures(m_screenTextureCount, m_screenTexture); configureTexture(0); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_frameWidth, m_frameHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); checkError("Default shader"); break; } glClear(GL_COLOR_BUFFER_BIT); }
/******************************************************* * unitTest_GenerateContent() * * Description: Loads hard coded battle map content for * unit testing. * * Inputs: none * * Outputs: none * * Return: none *******************************************************/ void GLWidget::unitTest_GenerateContent() { // Select a battle map. battleMap.imageFileName = "backgrounds/plains.png"; battleMap.audioFileName = "sounds/Battle_02.mp3"; battleMap.cellsTall = 6; battleMap.cellsWide = 9; battleMap.gridHeight = 0.58; // Create a new unit (for gl debug purposes). unit[0].name = "Knight"; unit[0].actionTime = 10; unit[0].actionRate=450; unit[0].hitPoints = 100; unit[0].totalHitPoints = 100; unit[0].image.load("sprites/knight.png"); unit[0].mask_image.load("sprites/mask_knight.png"); unit[0].status = UNIT_OK; unit[0].vLocation = 1; unit[0].hLocation = 2; unit[0].attackPower = 12; unit[0].attackRange = 2; unit[0].faceLeft = false; unit[0].movementRange = 2; unit[0].team =USER_UNIT; // Create a new unit (for gl debug purposes). unit[1].name = "Crusader"; unit[1].actionTime = 10; unit[1].actionRate = 500; unit[1].hitPoints = 100; unit[1].totalHitPoints = 100; unit[1].image.load("sprites/crusader.png"); unit[1].mask_image.load("sprites/mask_crusader.png"); unit[1].status =UNIT_OK; unit[1].vLocation = 2; unit[1].hLocation = 1; unit[1].attackPower = 16; unit[1].attackRange = 2; unit[1].faceLeft = false; unit[1].movementRange = 1; unit[1].team =USER_UNIT; // Create a new unit (for gl debug purposes). unit[2].name = "Thai Boxer"; unit[2].actionTime = 60; unit[2].actionRate =400; unit[2].hitPoints = 80; unit[2].totalHitPoints = 80; unit[2].image.load("sprites/thaiboxer.png"); unit[2].mask_image.load("sprites/mask_thaiboxer.png"); unit[2].status =UNIT_OK; unit[2].vLocation = 3; unit[2].hLocation = 2; unit[2].attackPower = 15; unit[2].attackRange = 1; unit[2].faceLeft = false; unit[2].movementRange = 4; unit[2].team =USER_UNIT; // Create a new unit (for gl debug purposes). unit[3].name = "Assassin"; unit[3].actionTime = 40; unit[3].actionRate = 400; unit[3].hitPoints = 60; unit[3].totalHitPoints = 60; unit[3].image.load("sprites/assassin.png"); unit[3].mask_image.load("sprites/mask_assassin.png"); unit[3].status =UNIT_OK; unit[3].vLocation = 1; unit[3].hLocation = 5; unit[3].attackPower = 12; unit[3].attackRange = 3; unit[3].faceLeft = false; unit[3].movementRange = 2; unit[3].team =USER_UNIT; // Create a new unit (for gl debug purposes). unit[4].name = "Berserker"; unit[4].actionTime = 40; unit[4].actionRate = 300; unit[4].hitPoints = 90; unit[4].totalHitPoints = 90; unit[4].image.load("sprites/berserker.png"); unit[4].mask_image.load("sprites/mask_berserker.png"); unit[4].status =UNIT_OK; unit[4].vLocation = 3; unit[4].hLocation = 5; unit[4].attackPower = 10; unit[4].attackRange = 1; unit[4].faceLeft = true; unit[4].movementRange = 2; unit[4].team =AI_UNIT; // Create a new unit (for gl debug purposes). unit[5].name = "Valkyrie"; unit[5].actionTime = 40; unit[5].actionRate = 500; unit[5].hitPoints = 70; unit[5].totalHitPoints = 70; unit[5].image.load("sprites/valkyrie.png"); unit[5].mask_image.load("sprites/mask_valkyrie.png"); unit[5].status =UNIT_OK; unit[5].vLocation = 4; unit[5].hLocation = 7; unit[5].attackPower = 14; unit[5].attackRange = 1; unit[5].faceLeft = true; unit[5].movementRange = 1; unit[5].team =AI_UNIT; // Create a new unit (for gl debug purposes). unit[6].name = "Valkyrie"; unit[6].actionTime = 40; unit[6].actionRate = 500; unit[6].hitPoints = 70; unit[6].totalHitPoints = 70; unit[6].image.load("sprites/valkyrie.png"); unit[6].mask_image.load("sprites/mask_valkyrie.png"); unit[6].status =UNIT_OK; unit[6].vLocation = 2; unit[6].hLocation = 2; unit[6].attackPower = 8; unit[6].attackRange = 2; unit[6].faceLeft = true; unit[6].movementRange = 4; unit[6].team =AI_UNIT; // Create a new unit (for gl debug purposes). unit[7].name = "Bard"; unit[7].actionTime = 40; unit[7].actionRate = 400; unit[7].hitPoints = 60; unit[7].totalHitPoints = 60; unit[7].image.load("sprites/bard.png"); unit[7].mask_image.load("sprites/mask_bard.png"); unit[7].status =UNIT_OK; unit[7].vLocation = 4; unit[7].hLocation = 8; unit[7].attackPower = 13; unit[7].attackRange = 3; unit[7].faceLeft = true; unit[7].movementRange = 2; unit[7].team =AI_UNIT; // Load a background image (debug). bkImage.load(battleMap.imageFileName); bkImage = bkImage.scaled(GLWidget::width(), GLWidget::height(), Qt::KeepAspectRatio, Qt::SmoothTransformation ); glBkImage = QGLWidget::convertToGLFormat(bkImage); // Initialize the grid. initGrid(); musicTrack = battleMap.audioFileName; playBackgroundTrack(); // Start the battle. isBattle = true; // Ensure proper graphics scaling. resizeGL(GLWidget::width(), GLWidget::height()); }
void DhQGLWidget::DvhresizeGL(int x1, int x2) { return resizeGL(x1, x2); }
void forcedResize() { if (initialized) { // makeCurrent(); resizeGL(width(), height()); } }