#include #include #include #include #define WIN32_LEAN_AND_MEAN 1 #include #include #include #include #include "types.h" int width=800; int height=600; int pheight=512; int pwidth=512; //int nb_buffers=4; #define nb_buffers 12 int running=TRUE; int wireframe=FALSE; int vsync=TRUE; int blur=TRUE; GLuint pbuffer_tex_id[nb_buffers]; HDC hpbufdc_; HGLRC hpbufglrc_; HPBUFFERARB pbuffer_; PFNWGLCREATEPBUFFERARBPROC wglCreatePbufferARB; PFNWGLGETPBUFFERDCARBPROC wglGetPbufferDCARB; PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB; PFNWGLBINDTEXIMAGEARBPROC wglBindTexImageARB; PFNWGLRELEASETEXIMAGEARBPROC wglReleaseTexImageARB; PFNWGLRELEASEPBUFFERDCARBPROC wglReleasePbufferDCARB; PFNWGLDESTROYPBUFFERARBPROC wglDestroyPbufferARB; 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( !glfwOpenWindow( WIDTH, HEIGHT, 5,6,5,0, 16,0, GLFW_FULLSCREEN ) ) if( !glfwOpenWindow( width, height, 8,8,8,8, 24,8, GLFW_WINDOW ) ) // XXX // if( !glfwOpenWindow( width, height, 5,6,5,0, 16,0, GLFW_FULLSCREEN ) ) // XXX { glfwTerminate(); exit( 0 ); } // Set window title glfwSetWindowTitle( "True Motion Blur" ); // Disable VSync (we want to get as high FPS as possible!) // euh non ... // glfwSwapInterval( 1 ); // vsync=FALSE; glfwSwapInterval( 0 ); vsync=FALSE; // Window resize callback function glfwSetWindowSizeCallback( Resize ); // Set keyboard input callback function glfwSetKeyCallback( KeyFun ); // 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) glfwGetProcAddress( "wglCreatePbufferARB" ); if (wglCreatePbufferARB == NULL) exit(-3); wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC) glfwGetProcAddress( "wglGetPbufferDCARB" ); if (wglGetPbufferDCARB == NULL) exit(-3); wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC) glfwGetProcAddress( "wglChoosePixelFormatARB" ); if (wglChoosePixelFormatARB == NULL) exit(-3); wglBindTexImageARB = (PFNWGLBINDTEXIMAGEARBPROC) glfwGetProcAddress( "wglBindTexImageARB" ); if (wglBindTexImageARB == NULL) exit(-3); wglReleaseTexImageARB = (PFNWGLRELEASETEXIMAGEARBPROC) glfwGetProcAddress( "wglReleaseTexImageARB" ); if (wglReleaseTexImageARB == NULL) exit(-3); wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC) glfwGetProcAddress( "wglReleasePbufferDCARB" ); if (wglReleasePbufferDCARB == NULL) exit(-3); wglDestroyPbufferARB = (PFNWGLDESTROYPBUFFERARBPROC) glfwGetProcAddress( "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); // PrintGetLastError(); // ????????????????????????????? //PrintGetLastError(); const int pbufferAttributes [50] = { // WGL_TEXTURE_FORMAT_ARB,WGL_TEXTURE_RGBA_ARB, //**** slows down to a crawl any Geforce with glCopyTexSub // WGL_TEXTURE_FORMAT_ARB,WGL_TEXTURE_RGB_ARB, //**** slows down to a crawl any Geforce with glCopyTexSub // WGL_TEXTURE_TARGET_ARB,WGL_TEXTURE_2D_ARB, //**** slows down to a crawl any Geforce with glCopyTexSub // WGL_MIPMAP_TEXTURE_ARB,TRUE, // pour avoir des beaux mipmaps faits par la carte ! // WGL_DEPTH_TEXTURE_FORMAT_NV, WGL_TEXTURE_DEPTH_COMPONENT_NV, //**** slows down to a crawl any Geforce with glCopyTexSub 0 }; i=0; //for (i=0;i mmh, c'est pas grave. /* wglMakeCurrent( hDC, // device context of device that OpenGL calls are to be drawn on hRC // OpenGL rendering context to be made the calling thread's current rendering context ); *//////////////// } wglMakeCurrent( hDC, // device context of device that OpenGL calls are to be drawn on hRC // OpenGL rendering context to be made the calling thread's current rendering context ); if (!wglShareLists(hRC, // OpenGL rendering context with which to share // display lists hpbufglrc_ // OpenGL rendering context to share display lists )) exit(-4); glGenTextures( nb_buffers, pbuffer_tex_id ); 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 ); } wglDeleteContext( hpbufglrc_ ); wglReleasePbufferDCARB( pbuffer_, hpbufdc_ ); wglDestroyPbufferARB( pbuffer_ ); // Terminate OpenGL glfwTerminate(); return 0; }