#include #include #include #include #define WIN32_LEAN_AND_MEAN 1 #include #include #include #include int width=800; int height=600; int pheight=512; int pwidth=512; //int nb_buffers=4; #define nb_buffers 12 #define nb_quadsperbuffer 1 int running=TRUE; int wireframe=FALSE; int vsync=FALSE; int blur=TRUE; //int fullscreen=FALSE; int fullscreen=FALSE; double blur_duration = 0.5; // 0.0 = pas de blur, full blur à 1.0, style cinema à 0.5 int GLOBAL_COUNTER =0; GLuint pbuffers_tex_id; HDC hpbufdc[nb_buffers]; HGLRC hpbufglrc[nb_buffers]; HPBUFFERARB pbuffer[nb_buffers]; PFNWGLCREATEPBUFFERARBPROC wglCreatePbufferARB; PFNWGLGETPBUFFERDCARBPROC wglGetPbufferDCARB; PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB; PFNWGLBINDTEXIMAGEARBPROC wglBindTexImageARB; PFNWGLRELEASETEXIMAGEARBPROC wglReleaseTexImageARB; PFNWGLRELEASEPBUFFERDCARBPROC wglReleasePbufferDCARB; PFNWGLDESTROYPBUFFERARBPROC wglDestroyPbufferARB; PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT; HDC hDC; HGLRC hRC; double FPS_time_elapsed = 0.0; unsigned int FPS_number_of_frames = 0; //======================================================================== // PrintGetLastError() //======================================================================== void PrintGetLastError(void ) { DWORD j ; LPVOID lpMsgBuf; j = GetLastError() ;//& 0x0000FFFF; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS , NULL, j, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL); printf("yop : %s",lpMsgBuf); } //======================================================================== // Resize() - GLFW window resize callback function //======================================================================== void Resize( int x, int y ) { width = x; height = y > 0 ? y : 1; // Prevent division by zero in aspect calc. // Setup viewport glViewport( 0, 0, width,height ); } //======================================================================== // Input cllback functions //======================================================================== void KeyFun( int key, int action ) { if( action == GLFW_PRESS ) { switch( key ) { case GLFW_KEY_ESC: running = FALSE; break; case 'W': wireframe = !wireframe; glPolygonMode( GL_FRONT_AND_BACK, wireframe ? GL_LINE : GL_FILL ); break; case 'V': vsync = !vsync; (vsync) ? glfwSwapInterval( 1 ) : glfwSwapInterval( 0 ); glFinish(); break; case 'B': blur = !blur; (blur) ? glEnable(GL_BLEND): glDisable(GL_BLEND); break; default: break; } } } void initGL(void) { int i; // Initialize GLFW glfwInit(); // Open OpenGL fullscreen window if (fullscreen) { if( !glfwOpenWindow( width, height, 8,8,8,8, 24,8, GLFW_FULLSCREEN ) ) { glfwTerminate(); exit( 0 ); } } else { if( !glfwOpenWindow( width, height, 8,8,8,8, 24,8, GLFW_WINDOW ) ) { glfwTerminate(); exit( 0 ); } } // Set window title glfwSetWindowTitle( "True Motion Blur" ); // Disable VSync (we want to get as high FPS as possible!) // well, it depends... if (vsync) glfwSwapInterval( 1 ); else glfwSwapInterval( 0 ); // wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) glfwGetProcAddress("wglSwapIntervalEXT"); // if (wglSwapIntervalEXT == NULL) exit(-3); // wglSwapIntervalEXT(1); // Window resize callback function glfwSetWindowSizeCallback( Resize ); // Set keyboard input callback function glfwSetKeyCallback( KeyFun ); // sometimes extensions are present but not advertised so the line below is disabled // if (glfwExtensionSupported("WGL_ARB_pbuffer")==GL_TRUE) {} else exit(-2); // init des pointeurs de fonction des extensions GL 1.4 ou 1.5 wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC) wglGetProcAddress( "wglCreatePbufferARB" ); if (wglCreatePbufferARB == NULL) exit(-3); wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC) wglGetProcAddress( "wglGetPbufferDCARB" ); if (wglGetPbufferDCARB == NULL) exit(-3); wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC) wglGetProcAddress( "wglChoosePixelFormatARB" ); if (wglChoosePixelFormatARB == NULL) exit(-3); wglBindTexImageARB = (PFNWGLBINDTEXIMAGEARBPROC) wglGetProcAddress( "wglBindTexImageARB" ); if (wglBindTexImageARB == NULL) exit(-3); wglReleaseTexImageARB = (PFNWGLRELEASETEXIMAGEARBPROC) wglGetProcAddress( "wglReleaseTexImageARB" ); if (wglReleaseTexImageARB == NULL) exit(-3); wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC) wglGetProcAddress( "wglReleasePbufferDCARB" ); if (wglReleasePbufferDCARB == NULL) exit(-3); wglDestroyPbufferARB = (PFNWGLDESTROYPBUFFERARBPROC) wglGetProcAddress( "wglDestroyPbufferARB" ); if (wglDestroyPbufferARB == NULL) exit(-3); hDC = wglGetCurrentDC(); hRC = wglGetCurrentContext(); UINT nbformats=0; const int hdcAttributes [30]={ WGL_SUPPORT_OPENGL_ARB, TRUE, // pbuffer will be used with gl WGL_BIND_TO_TEXTURE_RGB_ARB ,TRUE, WGL_DRAW_TO_PBUFFER_ARB ,TRUE, // WGL_DRAW_TO_WINDOW_ARB ,TRUE, WGL_COLOR_BITS_ARB , 24, // WGL_ALPHA_BITS_ARB , 8, WGL_DEPTH_BITS_ARB ,24, // WGL_STENCIL_BITS_ARB ,8, WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB, 0 }; int *pixelformats=(int*)calloc(256,4); wglChoosePixelFormatARB(hDC, hdcAttributes, NULL, 256, pixelformats, &nbformats ); printf("nbformats:%d\n",nbformats); const int pbufferAttributes [50] = { // WGL_TEXTURE_FORMAT_ARB,WGL_TEXTURE_RGBA_ARB, WGL_TEXTURE_FORMAT_ARB,WGL_TEXTURE_RGB_ARB, // use it only for RenderToTexture, not ctsi WGL_TEXTURE_TARGET_ARB,WGL_TEXTURE_2D_ARB , // use it only for RenderToTexture, not ctsi // WGL_MIPMAP_TEXTURE_ARB,TRUE, // to have nice and fast mipmaps 0 }; for (i=0;i=1.0) { printf("FPS:%6.2f\n",FPS_number_of_frames/FPS_time_elapsed); FPS_time_elapsed=0.0; FPS_number_of_frames=0; } // Check if window was closed running = running && glfwGetWindowParam( GLFW_OPENED ); } for (i=0;i