// the overridden render function void TestOpenGLPlugin::render(const OFX::RenderArguments &args) { if (!kSupportsRenderScale && (args.renderScale.x != 1. || args.renderScale.y != 1.)) { OFX::throwSuiteStatusException(kOfxStatFailed); } assert(kSupportsMultipleClipPARs || !_srcClip || _srcClip->getPixelAspectRatio() == _dstClip->getPixelAspectRatio()); assert(kSupportsMultipleClipDepths || !_srcClip || _srcClip->getPixelDepth() == _dstClip->getPixelDepth()); bool openGLRender = false; #if defined(OFX_SUPPORTS_OPENGLRENDER) const OFX::ImageEffectHostDescription &gHostDescription = *OFX::getImageEffectHostDescription(); if (gHostDescription.supportsOpenGLRender) { _useGPUIfAvailable->getValueAtTime(args.time, openGLRender); } // do the rendering if (openGLRender) { return renderGL(args); } #endif #ifdef HAVE_OSMESA if (!openGLRender) { return renderMesa(args); } #endif // HAVE_OSMESA OFX::throwSuiteStatusException(kOfxStatFailed); }
void Ibex::Ibex::render(double timeDiff) { if (controlDesktop) { walkForward = strafeRight = 0; } double rx = relativeMouseX; double ry = relativeMouseY; relativeMouseX = 0; relativeMouseY = 0; if(!OGRE3D) { processRawMotion(ry, rx, desktop3DLocation); relativeMouseX = 0; relativeMouseY = 0; desktop3DLocation.walk(walkForward+sixenseWalkForward, strafeRight+sixenseStrafeRight, timeDiff); } if(resetPosition) { resetPosition = 0; desktop3DLocation.resetState(); } renderer->setDesktopTexture(desktopTexture); if(OGRE3D) { renderer->move(walkForward+sixenseWalkForward, strafeRight+sixenseStrafeRight, jump, ry, rx); } renderer->processEvents(); renderGL(desktop3DLocation, timeDiff, renderer); // ts_start = ts_current; }
int main(int argc, char* argv[]) { SDLOpenGL window("Test",0,0,1024,720); window.makeCurrent(); initializeGL(); bool _while=true; while(_while) { renderGL(); window.swapWindow(); SDL_Delay(10); if(SDL_QUIT==1) { _while=false; }; } SDL_Quit(); return 0; }
void OpenGL_Window::renderOneFrame() { if(running) { while(SDL_PollEvent(&event)) { processEvent(event); } renderGL(); SDL_GL_SwapWindow(window); } }
int main(int argc, char *argv[]) { SDLOpenGL window("test",0,0,1024,720); window.makeCurrent(); initializedGL(); while(true) { renderGL(); window.swapWindow(); SDL_Delay(10); } }
int main(int argc, char *argv[]) { SDLOpenGL window("test",0,0,1024,720); window.makeCurrent(); initalizeGL(); while(true) { renderGL(); window.swapWindow(); SDL_Delay(10); } std::cout<<"working\n"; }
///////////////////////////////////////////////////////// // bangMess // ///////////////////////////////////////////////////////// void gemhead :: bangMess() { int renderon = m_renderOn; // make sure that the window and the cache exist if ( !GemMan::windowExists() || !m_cache ) { return; } // make a dummy GemState GemState tempState; GemMan::fillGemState(tempState); m_renderOn = 1; renderGL(&tempState); m_renderOn = renderon; glFlush(); }
void newFrame() { // Update gettimeofday( &tv, NULL); unsigned long long timeNow = (unsigned long long)(tv.tv_sec) * 1000 + (unsigned long long)(tv.tv_usec) / 1000; double delta = ((double)timeNow - (double)timePrev)*0.001; //logMsg("New frame (delta %d msec)\n",delta); Tangram::update(delta); timePrev = timeNow; // Render Tangram::render(); renderGL(); }
void Ibex::Ibex::render(double timeDiff) { if (controlDesktop) { walkForward = strafeRight = 0; } double rx = relativeMouseX; double ry = relativeMouseY; relativeMouseX = 0; relativeMouseY = 0; if(!OGRE3D) { processRawMotion(ry, rx, desktop3DLocation); relativeMouseX = 0; relativeMouseY = 0; // desktop3DLocation.walk(walkForward+sixenseWalkForward, strafeRight+sixenseStrafeRight, jump, timeDiff); } if(resetPosition) { resetPosition = 0; desktop3DLocation.resetState(); renderer->reset(); } //renderer->setDesktopTexture(desktopTexture); if(OGRE3D) { renderer->move(walkForward+sixenseWalkForward, strafeRight+sixenseStrafeRight, jump, ry, rx); } if(bringUpIbexDisplay) { bringUpIbexDisplay = false; renderer->bringUpIbexDisplay(); } if(bringUpAppLauncher) { bringUpAppLauncher = false; renderer->bringUpAppLauncher(); } renderer->processEvents(); renderGL(desktop3DLocation, timeDiff, renderer); checkForErrors(); // std::cerr << "checked errors FRAME DONE!" << std::endl; // ts_start = ts_current; }
void gemhead :: receive(t_symbol*s, int argc, t_atom*argv) { if(m_renderOn && gensym("gem_state")==s) { if(1==argc && A_FLOAT==argv->a_type) { int i=atom_getint(argv); switch(i) { case 0: stopRendering(); break; default: startRendering(); } } else if (2==argc && A_POINTER==argv[0].a_type && A_POINTER==argv[1].a_type) { //GemCache*cache=reinterpret_cast<GemCache*>(argv[0].a_w.w_gpointer); GemState*state=reinterpret_cast<GemState*>(argv[1].a_w.w_gpointer); renderGL(state); } } else { // not for us... } }
void GLWidget::direct_render(){ render_OffScreen(); renderGL(); }
void Waveform::UpdatePlayMarker() { renderGL(); }
void GLWidget::paintGL() { glReadBuffer(GL_BACK); // --------------------------------------------------------- // Drawing env // --------------------------------------------------------- bakeEnviromentalMaps(); colorFBO->bindDefault(); GLCHK( glViewport(0, 0, width(), height()) ); if(cameraInterpolation < 1.0){ double w = cameraInterpolation; camera.position = camera.position*(1-w) + newCamera.position * w; cameraInterpolation += 0.01; } // setting the camera viewpoint viewMatrix = camera.updateCamera(); colorFBO->bind(); GLCHK( glDisable(GL_CULL_FACE) ); projectionMatrix.setToIdentity(); projectionMatrix.perspective(zoom,ratio,0.1,350.0); // set to which FBO result will be drawn GLuint attachments[4] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 , GL_COLOR_ATTACHMENT3 }; glDrawBuffers(4, attachments); GLCHK( glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ); // --------------------------------------------------------- // Drawing skybox // --------------------------------------------------------- skybox_program->bind(); objectMatrix.setToIdentity(); if(skybox_mesh->isLoaded()){ objectMatrix.translate(camera.position); objectMatrix.scale(150.0); } modelViewMatrix = viewMatrix * objectMatrix; NormalMatrix = modelViewMatrix.normalMatrix(); glDisable(GL_DEPTH_TEST); // disable depth GLCHK( skybox_program->setUniformValue("ModelViewMatrix" , modelViewMatrix) ); GLCHK( skybox_program->setUniformValue("NormalMatrix" , NormalMatrix) ); GLCHK( skybox_program->setUniformValue("ModelMatrix" , objectMatrix) ); GLCHK( skybox_program->setUniformValue("ProjectionMatrix" , projectionMatrix) ); GLCHK( glActiveTexture(GL_TEXTURE0) ); GLCHK( m_env_map->bind()); GLCHK( skybox_mesh->drawMesh(true) ); // --------------------------------------------------------- // Drawing model // --------------------------------------------------------- QOpenGLShaderProgram* program_ptrs[2] = {program,line_program}; GLCHK( glEnable(GL_CULL_FACE) ); GLCHK( glEnable(GL_DEPTH_TEST) ); GLCHK( glCullFace(GL_FRONT) ); glDisable(GL_POLYGON_OFFSET_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); for(int pindex = 0 ; pindex < 2 ; pindex ++){ QOpenGLShaderProgram* program_ptr = program_ptrs[pindex]; GLCHK( program_ptr->bind() ); GLCHK( program_ptr->setUniformValue("ProjectionMatrix", projectionMatrix) ); objectMatrix.setToIdentity(); if( fboIdPtrs[0] != NULL){ float fboRatio = float((*(fboIdPtrs[0]))->width())/(*(fboIdPtrs[0]))->height(); objectMatrix.scale(fboRatio,1,fboRatio); } if(mesh->isLoaded()){ objectMatrix.scale(0.5/mesh->radius); objectMatrix.translate(-mesh->centre_of_mass); } modelViewMatrix = viewMatrix*objectMatrix; NormalMatrix = modelViewMatrix.normalMatrix(); float mesh_scale = 0.5/mesh->radius; GLCHK( program_ptr->setUniformValue("ModelViewMatrix" , modelViewMatrix) ); GLCHK( program_ptr->setUniformValue("NormalMatrix" , NormalMatrix) ); GLCHK( program_ptr->setUniformValue("ModelMatrix" , objectMatrix) ); GLCHK( program_ptr->setUniformValue("meshScale" , mesh_scale) ); GLCHK( program_ptr->setUniformValue("lightPos" , lightPosition) ); GLCHK( program_ptr->setUniformValue("lightDirection" , lightDirection.direction) ); GLCHK( program_ptr->setUniformValue("cameraPos" , camera.get_position()) ); GLCHK( program_ptr->setUniformValue("gui_depthScale" , depthScale) ); GLCHK( program_ptr->setUniformValue("gui_uvScale" , uvScale) ); GLCHK( program_ptr->setUniformValue("gui_uvScaleOffset" , uvOffset) ); GLCHK( program_ptr->setUniformValue("gui_bSpecular" , bToggleSpecularView) ); GLCHK( program_ptr->setUniformValue("gui_bDiffuse" , bToggleDiffuseView) ); GLCHK( program_ptr->setUniformValue("gui_bOcclusion" , bToggleOcclusionView) ); GLCHK( program_ptr->setUniformValue("gui_bHeight" , bToggleHeightView) ); GLCHK( program_ptr->setUniformValue("gui_bNormal" , bToggleNormalView) ); GLCHK( program_ptr->setUniformValue("gui_bRoughness" , bToggleRoughnessView) ); GLCHK( program_ptr->setUniformValue("gui_bMetallic" , bToggleMetallicView) ); GLCHK( program_ptr->setUniformValue("gui_shading_type" , shadingType) ); GLCHK( program_ptr->setUniformValue("gui_shading_model" , shadingModel) ); GLCHK( program_ptr->setUniformValue("gui_SpecularIntensity" , specularIntensity) ); GLCHK( program_ptr->setUniformValue("gui_DiffuseIntensity" , diffuseIntensity) ); GLCHK( program_ptr->setUniformValue("gui_LightPower" , lightPower) ); GLCHK( program_ptr->setUniformValue("gui_LightRadius" , lightRadius) ); // number of mipmaps GLCHK( program_ptr->setUniformValue("num_mipmaps" , m_env_map->numMipmaps ) ); // 3D settings GLCHK( program_ptr->setUniformValue("gui_bUseCullFace" , performanceSettings.bUseCullFace) ); GLCHK( program_ptr->setUniformValue("gui_bUseSimplePBR" , performanceSettings.bUseSimplePBR) ); GLCHK( program_ptr->setUniformValue("gui_noTessSub" , performanceSettings.noTessSubdivision) ); GLCHK( program_ptr->setUniformValue("gui_noPBRRays" , performanceSettings.noPBRRays) ); if(performanceSettings.bShowTriangleEdges && pindex == 0){ glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); glEnable( GL_POLYGON_OFFSET_FILL ); glPolygonOffset( 1.0f, 1.0f ); GLCHK( program_ptr->setUniformValue("gui_bShowTriangleEdges", true) ); GLCHK( program_ptr->setUniformValue("gui_bMaterialsPreviewEnabled" , true) ); }else{ if(performanceSettings.bShowTriangleEdges){ glDisable( GL_POLYGON_OFFSET_FILL ); glEnable( GL_POLYGON_OFFSET_LINE ); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glPolygonOffset( -2.0f, -2.0f ); glLineWidth(1.0f); } GLCHK( program_ptr->setUniformValue("gui_bShowTriangleEdges", performanceSettings.bShowTriangleEdges) ); // Material preview: M key : when triangles are disabled if(!performanceSettings.bShowTriangleEdges) GLCHK( program_ptr->setUniformValue("gui_bMaterialsPreviewEnabled" , bool(keyPressed == KEY_SHOW_MATERIALS)) ); } if( fboIdPtrs[0] != NULL){ int tindeks = 0; for(tindeks = 0 ; tindeks < MAX_TEXTURES_TYPE ; tindeks++){ GLCHK( glActiveTexture(GL_TEXTURE0+tindeks) ); GLCHK( glBindTexture(GL_TEXTURE_2D, (*(fboIdPtrs[tindeks]))->texture()) ); } GLCHK( glActiveTexture(GL_TEXTURE0 + tindeks ) ); GLCHK(m_prefiltered_env_map->bind()); tindeks++; GLCHK( glActiveTexture(GL_TEXTURE0 + tindeks) ); GLCHK( m_env_map->bind()); GLCHK( mesh->drawMesh() ); // set default active texture glActiveTexture(GL_TEXTURE0); } if(!performanceSettings.bShowTriangleEdges) break; }// end of loop over triangles glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable( GL_POLYGON_OFFSET_LINE ); // return to standard settings GLCHK( glDisable(GL_CULL_FACE) ); GLCHK( glDisable(GL_DEPTH_TEST) ); // set to which FBO result will be drawn GLuint attachments2[1] = { GL_COLOR_ATTACHMENT0 }; glDrawBuffers(1, attachments2); colorFBO->bindDefault(); GLCHK( glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ); GLCHK( filters_program->bind() ); // do post processing if materials are not shown if( keyPressed != KEY_SHOW_MATERIALS ){ // ----------------------------------------------------------- // Post processing: // 1. Bloom (can be disabled/enabled by gui) // ----------------------------------------------------------- // enable of disable bloom effect if(performanceSettings.bBloomEffect){ applyGlowFilter(outputFBO->fbo); copyTexToFBO(outputFBO->fbo->texture(),colorFBO->fbo); //applyNormalFilter(outputFBO->fbo->texture()); }// end of if bloom effect // ----------------------------------------------------------- // Post processing: // 2. DOF (can be disabled/enabled by gui) // ----------------------------------------------------------- if(performanceSettings.bDofEffect){ applyDofFilter(colorFBO->fbo->texture(),auxFBO->fbo,outputFBO->fbo); copyTexToFBO(outputFBO->fbo->texture(),colorFBO->fbo); } applyNormalFilter(colorFBO->fbo->texture()); }else{ // end of if SHOW MATERIALS TEXTURE DISABLED GLCHK( applyNormalFilter(colorFBO->fbo->texture())); } GLCHK( filters_program->release() ); emit renderGL(); }
int main( int argc, char **argv ) { int nRC= 0; printf("ess-sample v1.0\n"); ctx= EssContextCreate(); if ( ctx ) { int len; bool error= false; for( int i= 1; i < argc; ++i ) { len= strlen(argv[i]); if ( (len == 9) && !strncmp( (const char*)argv[i], "--wayland", len) ) { if ( !EssContextSetUseWayland( ctx, true ) ) { error= true; break; } } } if ( !EssContextSetTerminateListener( ctx, 0, &terminateListener ) ) { error= true; } if ( !EssContextSetKeyListener( ctx, 0, &keyListener ) ) { error= true; } if ( !EssContextSetPointerListener( ctx, 0, &pointerListener ) ) { error= true; } if ( !error ) { struct sigaction sigint; sigint.sa_handler= signalHandler; sigemptyset(&sigint.sa_mask); sigint.sa_flags= SA_RESETHAND; sigaction(SIGINT, &sigint, NULL); if ( !EssContextStart( ctx ) ) { error= true; } else if ( !EssContextGetDisplaySize( ctx, &gDisplayWidth, &gDisplayHeight ) ) { error= true; } if ( !error ) { setupGL(); gRunning= true; while( gRunning ) { EssContextRunEventLoopOnce( ctx ); renderGL(); EssContextUpdateDisplay( ctx ); } } } if ( error ) { const char *detail= EssContextGetLastErrorDetail( ctx ); printf("Essos error: (%s)\n", detail ); } EssContextDestroy( ctx ); } return nRC; }
int main(int argc, char** argv) { //! The pointer to the GLFW window GLFWwindow* window; //! Setting up the GLFW Error callback glfwSetErrorCallback(csX75::error_callback); //! Initialize GLFW if (!glfwInit()) return -1; //We want OpenGL 4.0 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); //This is for MacOSX - can be omitted otherwise //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); //We don't want the old OpenGL //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //! Create a windowed mode window and its OpenGL context window = glfwCreateWindow(512, 512, "Assignment1", NULL, NULL); if (!window) { glfwTerminate(); return -1; } //! Make the window's context current glfwMakeContextCurrent(window); //Initialize GLEW //Turn this on to get Shader based OpenGL glewExperimental = GL_TRUE; GLenum err = glewInit(); if (GLEW_OK != err) { //Problem: glewInit failed, something is seriously wrong. std::cerr<<"GLEW Init Failed : %s"<<std::endl; } //Keyboard Callback glfwSetKeyCallback(window, csX75::key_callback); //Framebuffer resize callback glfwSetFramebufferSizeCallback(window, csX75::framebuffer_size_callback); // Ensure we can capture the escape key being pressed below //glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); glfwSetInputMode(window, GLFW_STICKY_MOUSE_BUTTONS, GL_TRUE); //glfwSetCursorPosCallback(window, csX75::cursor_callback); //Initialize GL state csX75::initGL(); initBuffersGL(); initBufferFrustrumGL(); std::cout<<"Press 1 to go to VCS, 2 to go to CCS, 3 to go to NDCS and 4 to go to DCS"<<std::endl; std::cout<<"Press 'f' to toggle between moving the frustum and moving the world"<<std::endl; std::cout<<"Press 'c' to enable/disable clipping"<<std::endl; // Loop until the user closes the window while (glfwWindowShouldClose(window) == 0) { // Render here renderGL(); // Swap front and back buffers glfwSwapBuffers(window); // Poll for and process events glfwPollEvents(); } glfwTerminate(); return 0; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // console for debugging //AllocConsole(); //freopen("CONOUT$","wb",stdout); WNDCLASSEX wc; HWND hwnd; MSG msg; // register window class wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = g_windowClass; wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); unsigned int winWidth = WINDOW_WIDTH; unsigned int winHeight = WINDOW_HEIGHT; if(!RegisterClassEx(&wc)) { MessageBox(NULL, "Window Registration Failed", "Error", MB_ICONEXCLAMATION | MB_OK); return 0; } // create window hwnd = CreateWindowEx( WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, g_windowClass, "Title Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, winWidth, winHeight, NULL, NULL, hInstance, NULL); if(hwnd == NULL) { MessageBox(NULL, "Window Creation Failed", "Error", MB_ICONEXCLAMATION | MB_OK); return 0; } HDC hdc; if(!(hdc = GetDC(hwnd))) printf("GetDC failed\n"); //* old set pixel format // set pixel format PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, // flags PFD_TYPE_RGBA, // rgba framebuffer 32, // 32 bit color depth 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 8, // 24 bit depth, 8 bit stencil 0, // # of aux buffers PFD_MAIN_PLANE, 0, 0, 0, 0 }; // get available matching pixel format int iPixelFormat; if(!(iPixelFormat = ChoosePixelFormat(hdc, &pfd))) printf("ChoosePixelFormat failed\n"); //*/ // assign pixel format to device context if(!(SetPixelFormat(hdc, iPixelFormat, &pfd))) printf("SetPixelFormat failed\n"); // create opengl context HGLRC context; if(!(context = wglCreateContext(hdc))) printf("wglCreateContext failed\n"); if(!(wglMakeCurrent(hdc, context))) printf("wglMakeCurrent failed\n"); // Now we want an updated pixel format and context //* PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB"); if(!wglChoosePixelFormatARB) { printf("wgl choose pixel format not supported?\n"); } PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB"); if(!wglCreateContextAttribsARB) printf("wglCreateContextAttribsARB undefined\n"); // using wglchoosepixelformat const int attribList[] = { WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, WGL_SUPPORT_OPENGL_ARB, GL_TRUE, WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, WGL_DOUBLE_BUFFER_ARB, GL_TRUE, WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB, WGL_DEPTH_BITS_ARB, 24, WGL_STENCIL_BITS_ARB, 8, 0, }; int ePixelFormat; unsigned int numFormats; int valid = wglChoosePixelFormatARB(hdc, attribList, NULL, 1, &ePixelFormat, &numFormats); if (valid && numFormats >= 1) { // we have a valid format printf("we have a valid format\n"); } else { printf("wglchoosepixel format didn't find a valid format\n"); } // if we found a valid format, it is stored in ePixelFormat // delete old rendering context int delc = wglDeleteContext(context); if (!delc) printf("failed to delete old context\n"); // release device context ReleaseDC(hwnd, hdc); // destroy the window DestroyWindow(hwnd); while(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { // get rid of the first destroy message so it doesn't screw up later int temp = GetMessage(&msg, NULL, 0, 0); if (temp != 0) { printf("whoops, something other than destroy was in message queue after destroywindow: (%i)\n", temp); } else { printf("disposed of the first destory message\n"); } } // now, make it all again hwnd = CreateWindowEx( WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, g_windowClass, "Title Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, winWidth, winHeight, NULL, NULL, hInstance, NULL); // get the new device context if(!(hdc = GetDC(hwnd))) printf("second GetDC failed\n"); // set the pixel format the the extended one we got earlier if (!SetPixelFormat(hdc, ePixelFormat, &pfd)) { // failed to set pixel format printf("failed to set extended pixel format\n"); } // create extended opengl rendering context int contextAttribs[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 4, WGL_CONTEXT_MINOR_VERSION_ARB, 2, WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, //WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, 0 }; if(!(context = wglCreateContextAttribsARB(hdc, NULL, contextAttribs))) printf("second wglCreateContext failed\n"); if(!(wglMakeCurrent(hdc, context))) printf("second wglMakeCurrent failed\n"); //*/ ShowWindow(hwnd, nCmdShow); SetForegroundWindow(hwnd); SetFocus(hwnd); UpdateWindow(hwnd); // set initial mouse position POINT p; if(GetCursorPos(&p)) { if (ScreenToClient(hwnd, &p)) { g_mouse_x = p.x; g_mouse_y = p.y; } else { printf("ScreenToClient failed\n"); } } else { printf("GetCursorPos failed\n"); } initGL(winWidth, winHeight); printf("finished init, starting main loop\n"); g_hwnd = hwnd; g_current_millis = currentMillis(); // main loop while(g_running) { while(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { int temp = GetMessage(&msg, NULL, 0, 0); if(temp > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } else { printf("getmessage returned nonpositive: (%i)\n", temp); g_running = false; break; } } long long current_millis = currentMillis(); //printf("current_millis is %i\n", current_millis); // wouldn't current_millis be bigger? float dt = g_current_millis - current_millis; g_current_millis = current_millis; // draw stuff renderGL(); update(dt); g_running &= !keys[frontKeyBuffer][VK_ESCAPE]; swapKeyBuffers(); SwapBuffers(hdc); } printf("quitting\n"); //FreeConsole(); // delete the rendering context wglMakeCurrent(NULL, NULL); wglDeleteContext(context); return msg.wParam; }
int main (int argc, char *argv[]) { progname=argv[0]; //! The pointer to the GLFW window GLFWwindow* window; //! Setting up the GLFW Error callback glfwSetErrorCallback(csX75::error_callback); //! Initialize GLFW if (!glfwInit()) return -1; setup(argc, argv); int win_width=512; int win_height=512; //! Create a windowed mode window and its OpenGL context window = glfwCreateWindow(win_width, win_height, "ToyLOGO", NULL, NULL); if (!window) { glfwTerminate(); return -1; } //! Make the window's context current glfwMakeContextCurrent(window); //Keyboard Callback glfwSetKeyCallback(window, csX75::key_callback); //Framebuffer resize callback glfwSetFramebufferSizeCallback(window, csX75::framebuffer_size_callback); // Ensure we can capture the escape key being pressed below glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); glfwGetFramebufferSize(window, &win_width, &win_height); csX75::framebuffer_size_callback(window, win_width, win_height); //Initialize GL state csX75::initGL(); glEnable(GL_DEPTH_TEST); // Loop until the user closes the window while (glfwWindowShouldClose(window) == 0) { // Render here renderGL(window); // Swap front and back buffers glfwSwapBuffers(window); // Poll for and process events glfwPollEvents(); } glfwDestroyWindow(window); glfwTerminate(); return 0; }
void renderThread(int argc, char **argv) { // Prepare viewport glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); // Setup setup(); // Turn on Alpha blending glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // Clear the background glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); int textureCounter = 0; //Load the the resources (textures) for (uint i = 1; i < argc ; i++){ std::string argument = std::string(argv[i]); if (argument == "-x" || argument == "-y" || argument == "-w" || argument == "--width" || argument == "-h" || argument == "--height" ) { i++; } else if ( argument == "--square" || argument == "-l" || argument == "--life-coding" ) { } else if ( argument == "-m" ) { bCursor = true; cursor.init(); } else if ( argument == "-s" || argument == "--sec") { i++; argument = std::string(argv[i]); timeLimit = getFloat(argument); std::cout << "Will exit in " << timeLimit << " seconds." << std::endl; } else if ( argument == "-o" ){ i++; argument = std::string(argv[i]); if( haveExt(argument,"png") ){ outputFile = argument; std::cout << "Will save screenshot to " << outputFile << " on exit." << std::endl; } else { std::cout << "At the moment screenshots only support PNG formats" << std::endl; } } else if (argument.find("-") == 0) { std::string parameterPair = argument.substr(argument.find_last_of('-')+1); i++; argument = std::string(argv[i]); Texture* tex = new Texture(); if( tex->load(argument) ){ textures[parameterPair] = tex; std::cout << "Loading " << argument << " as the following uniform: " << std::endl; std::cout << " uniform sampler2D " << parameterPair << "; // loaded"<< std::endl; std::cout << " uniform vec2 " << parameterPair << "Resolution;"<< std::endl; } } else if ( haveExt(argument,"png") || haveExt(argument,"PNG") || haveExt(argument,"jpg") || haveExt(argument,"JPG") || haveExt(argument,"jpeg") || haveExt(argument,"JPEG") ) { Texture* tex = new Texture(); if( tex->load(argument) ){ std::string name = "u_tex"+getString(textureCounter); textures[name] = tex; std::cout << "Loading " << argument << " as the following uniform: " << std::endl; std::cout << " uniform sampler2D " << name << "; // loaded"<< std::endl; std::cout << " uniform vec2 " << name << "Resolution;"<< std::endl; textureCounter++; } } } // Render Loop while (isGL() && bPlay) { // Update updateGL(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Draw draw(); // Swap the buffers renderGL(); if ( timeLimit > 0.0 && getTime() > timeLimit ) { onKeyPress('s'); bPlay = false; } } }
void Waveform::renderGL( wxPaintEvent& event ) { renderGL(); }
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; }
int main(int argc, char** argv) { //! The pointer to the GLFW window GLFWwindow* window; //! Setting up the GLFW Error callback glfwSetErrorCallback(csX75::error_callback); //! Initialize GLFW if (!glfwInit()) return -1; //! Create a windowed mode window and its OpenGL context window = glfwCreateWindow(640, 480, "CS475/CS675 OpenGL Framework", NULL, NULL); if (!window) { glfwTerminate(); return -1; } //! Make the window's context current glfwMakeContextCurrent(window); //Initialize GLEW GLenum err = glewInit(); if (GLEW_OK != err) { //Problem: glewInit failed, something is seriously wrong. std::cerr<<"GLEW Init Failed : %s"<<std::endl; } //Print and see what context got enabled std::cout<<"Vendor: "<<glGetString (GL_VENDOR)<<std::endl; std::cout<<"Renderer: "<<glGetString (GL_RENDERER)<<std::endl; std::cout<<"Version: "<<glGetString (GL_VERSION)<<std::endl; std::cout<<"GLSL Version: "<<glGetString (GL_SHADING_LANGUAGE_VERSION)<<std::endl; //Keyboard Callback glfwSetKeyCallback(window, csX75::key_callback); //Framebuffer resize callback glfwSetFramebufferSizeCallback(window, csX75::framebuffer_size_callback); // Ensure we can capture the escape key being pressed below glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); //Initialize GL state csX75::initGL(); // Loop until the user closes the window while (glfwWindowShouldClose(window) == 0) { // Render here renderGL(); // Swap front and back buffers glfwSwapBuffers(window); // Poll for and process events glfwPollEvents(); } glfwTerminate(); return 0; }