void X11OpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) { m_data->m_dpy = XOpenDisplay(NULL); if(m_data->m_dpy == NULL) { printf("\n\tcannot connect to X server\n\n"); exit(0); } m_data->m_root = DefaultRootWindow(m_data->m_dpy); m_data->m_vi = glXChooseVisual(m_data->m_dpy, 0, att); if(m_data->m_vi == NULL) { printf("\n\tno appropriate visual found\n\n"); exit(0); } else { printf("\n\tvisual %p selected\n", (void *)m_data->m_vi->visualid); /* %p creates hexadecimal output like in glxinfo */ } m_data->m_cmap = XCreateColormap(m_data->m_dpy, m_data->m_root, m_data->m_vi->visual, AllocNone); m_data->m_swa.colormap = m_data->m_cmap; m_data->m_swa.event_mask = ExposureMask | KeyReleaseMask | KeyPressMask |ButtonPressMask | ButtonReleaseMask |PointerMotionMask|StructureNotifyMask; m_data->m_win = XCreateWindow(m_data->m_dpy, m_data->m_root, 0, 0, ci.m_width, ci.m_height, 0, m_data->m_vi->depth, InputOutput, m_data->m_vi->visual, CWColormap | CWEventMask, &m_data->m_swa); XMapWindow(m_data->m_dpy, m_data->m_win); XStoreName(m_data->m_dpy, m_data->m_win, "VERY SIMPLE APPLICATION"); enableOpenGL(); }
void Win32OpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) { Win32Window::createWindow(ci); //VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, this); enableOpenGL(); }
void Win32OpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) { Win32Window::createWindow(ci); //VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, this); enableOpenGL(); if (!gladLoaderLoadGL()) { printf("gladLoaderLoadGL failed!\n"); exit(-1); } }
void Win32OpenGLWindow::init(int width,int height, bool fullscreen,int colorBitsPerPixel, void* windowHandle) { // get handle to exe file HINSTANCE hInstance = GetModuleHandle(0); // create the window if we need to and we do not use the null device if (!windowHandle) { const char* ClassName = "DeviceWin32"; // Register Class WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon( NULL, IDI_APPLICATION ); //(HICON)LoadImage(hInstance, "bullet_ico.ico", IMAGE_ICON, 0,0, LR_LOADTRANSPARENT);//LR_LOADFROMFILE); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = 0; wcex.lpszClassName = ClassName; wcex.hIconSm = 0; // if there is an icon, load it wcex.hIcon = (HICON)LoadImage(hInstance, "irrlicht.ico", IMAGE_ICON, 0,0, LR_LOADFROMFILE); RegisterClassEx(&wcex); // calculate client size RECT clientSize; clientSize.top = 0; clientSize.left = 0; clientSize.right = width; clientSize.bottom = height; DWORD style = WS_POPUP; if (!fullscreen) style = WS_SYSMENU | WS_BORDER | WS_CAPTION | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SIZEBOX; AdjustWindowRect(&clientSize, style, FALSE); m_data->m_width = clientSize.right - clientSize.left; m_data->m_height = clientSize.bottom - clientSize.top; int windowLeft = (GetSystemMetrics(SM_CXSCREEN) - m_data->m_width) / 2; int windowTop = (GetSystemMetrics(SM_CYSCREEN) - m_data->m_height) / 2; if (fullscreen) { windowLeft = 0; windowTop = 0; } // create window m_data->m_hWnd = CreateWindow( ClassName, "", style, windowLeft, windowTop, m_data->m_width, m_data->m_height, NULL, NULL, hInstance, NULL); ShowWindow(m_data->m_hWnd, SW_SHOW); UpdateWindow(m_data->m_hWnd); MoveWindow(m_data->m_hWnd, windowLeft, windowTop, m_data->m_width, m_data->m_height, TRUE); } else if (windowHandle) { // attach external window m_data->m_hWnd = static_cast<HWND>(windowHandle); RECT r; GetWindowRect(m_data->m_hWnd, &r); m_data->m_width = r.right - r.left; m_data->m_height = r.bottom - r.top; //sFullScreen = false; //sExternalWindow = true; } if (fullscreen) { DEVMODE dm; memset(&dm, 0, sizeof(dm)); dm.dmSize = sizeof(dm); // use default values from current setting EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm); m_data->m_oldScreenWidth = dm.dmPelsWidth; m_data->m_oldHeight = dm.dmPelsHeight; m_data->m_oldBitsPerPel = dm.dmBitsPerPel; dm.dmPelsWidth = width; dm.dmPelsHeight = height; if (colorBitsPerPixel) { dm.dmBitsPerPel = colorBitsPerPixel; } dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY; LONG res = ChangeDisplaySettings(&dm, CDS_FULLSCREEN); if (res != DISP_CHANGE_SUCCESSFUL) { // try again without forcing display frequency dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; res = ChangeDisplaySettings(&dm, CDS_FULLSCREEN); } } //VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, this); enableOpenGL(); const wchar_t* text= L"OpenCL rigid body demo"; DWORD dwResult; #ifdef _WIN64 SetWindowTextW(m_data->m_hWnd, text); #else SendMessageTimeoutW(m_data->m_hWnd, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(text), SMTO_ABORTIFHUNG, 2000, &dwResult); #endif }
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { WNDCLASSEX wcex; HWND hwnd; HDC hDC; HGLRC hRC; MSG msg; BOOL bQuit = FALSE; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_OWNDC; wcex.lpfnWndProc = WindowProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wcex.lpszMenuName = NULL; wcex.lpszClassName = WINDOW_CLASS; wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);; if( !RegisterClassEx( &wcex )) { return 0; } hwnd = CreateWindowEx( 0, WINDOW_CLASS, WINDOW_TITLE, //WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, WS_OVERLAPPEDWINDOW, 30, 20, screen_w + GetSystemMetrics( SM_CYFRAME ) * 2, screen_h + GetSystemMetrics( SM_CYFRAME ) * 2 + GetSystemMetrics( SM_CYCAPTION ), NULL, NULL, hInstance, NULL ); ShowWindow( hwnd, nCmdShow ); enableOpenGL( hwnd, &hDC, &hRC ); enableOpenAL(); resizeScene( screen_w, screen_h ); glEnable( GL_TEXTURE_2D ); glClearColor( 0.1f, 0.1f, 0.1f, 0.0f ); glClearDepth( 1.0f ); glEnable( GL_DEPTH_TEST ); glDepthFunc( GL_LEQUAL ); glShadeModel( GL_SMOOTH ); glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); // FIXME NOPE...audio en video out of sync, packet queue is wel goed //char *file = "C:/Users/vin777/Documents/Dump/Films/Monsters.Vs.Aliens.DVDRiP.XviD-JUMANJi/jmj-mona.avi"; // FIXME NOPE...geen audio codec gevonden //char *file = "C:/Users/vin777/Documents/Dump/Films/Monsters.Vs.Aliens.2009.1080p.BluRay.x264-CiNEFiLE.mkv"; // FIXME OK...foutje in begin van de file maar voor de rest gaat het uitstekend //char *file = "C:/Users/vin777/Documents/Dump/Films/Transformers Revenge of the Fallen[2009]DvDrip[Eng]-FXG/Transformers Revenge of the Fallen[2009]DvDrip[Eng]-FXG.avi"; // De avi file is ook niet helemaal perfect, loopt goed. // FIXME NOPE...foutje in begin file en video packet queue buffer altijd leeg? //char *file = "../stuff/video.avi"; // FIXME UPDATE...OK! Stream had een pFormatCtx->start_time, werkt nu! Maar waarom is de audio packet queue nog vol aan het einde? // NOPE...audio en beeld out of sync, packet queue is wel goed //char *file = "../stuff/video.wmv"; //char media[] = "C:/Users/vin777/Documents/Dump/Encode/fulco/howtotrainyourdragon-tlr2_h720p_fulco.mp4"; //char media2[] = "C:/Users/vin777/Documents/Dump/Encode/fulco/julieandjulia-tlr1_h720p_fulco.mp4"; //char media[] = "http://scfire-mtc-aa03.stream.aol.com:80/stream/1025"; //char media[] = "http://72.26.204.18:6256#.aac"; //char media[] = "../DUMP/image.png"; //char media[] = "./stuff/video.gif"; //char media2[] = "../DUMP/image.jpg"; //char media[] = "http://tweakimg.net/g/if/v2/breadcrumb/award_2009_transparent.png"; //char media2[] = "http://ccms.e-billboard.eu/webcam/?id=19#.jpg"; //char media[] = "./stuff/music.mp3"; int i; int num_vid = 5; char *media[] = { "C:/Users/vin777/Documents/Dump/Encode/fulco/howtotrainyourdragon-tlr2_h720p_fulco.mp4", "C:/Users/vin777/Documents/Dump/Encode/fulco/julieandjulia-tlr1_h720p_fulco.mp4", "C:/Users/vin777/Documents/Dump/Encode/fulco/aliceinwonderland-tsr1_h720p_fulco.mp4", "E:/vincent/data/snapshot_0/vincent/films/wake_up/Vincent_van_Ingen-Wake_Up-H264-AAC-720p.mov", "http://ccms.e-billboard.eu/webcam/?id=19#.jpg", }; Vineo v[num_vid]; for( i = 0; i < num_vid; i++ ) { vineoInit( &v[i] ); glBindTexture( GL_TEXTURE_2D, v[i].tex_gl ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); vineoOpenAndDecodeThread( &v[i], media[i] ); } float r = 0.0f; float x = 0.0f; float x_space = 3.0f; int num_box = 15; int64_t time = av_gettime(); int64_t ptime = time; int64_t ctime = 0; int count = 0; int max_count = 200; while( !bQuit ) { if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { if( msg.message == WM_QUIT ) { bQuit = 1; } else { TranslateMessage( &msg ); DispatchMessage( &msg ); } } else { ptime = time; time = av_gettime(); ctime += time - ptime; if( ++count == max_count ) { float fps = (float)AV_TIME_BASE / (float)ctime * (float)max_count; char title[64]; //printf( "fps: %f\n", fps ); sprintf( title, "Vineo = OpenGL / OpenAL / FFmpeg, fps: %f", fps ); SetWindowText( hwnd, title ); ctime = 0; count = 0; } if( keys[VK_ESCAPE] ) { bQuit = 1; } if( keys[VK_ESCAPE] ) { PostQuitMessage( 0 ); } if( keys['R'] ) { for( i = 0; i < num_vid; i++ ) { vineoClose( &v[i] ); //v[i] = vineoNew(); vineoInit( &v[i] ); glBindTexture( GL_TEXTURE_2D, v[i].tex_gl ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); //vineoOpen( v[i], media[i] ); //vineoPlay( v[i] ); vineoOpenAndDecodeThread( &v[i], media[i] ); } } x += (float)( time - ptime ) / 1000000.0f; if( x > num_vid * x_space ) { x -= num_vid * x_space; } r += (float)( time - ptime ) / 100000.0f; for( i = 0; i < num_vid; i++ ) { vineoFlush( &v[i] ); } glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); // camera glRotatef( 45.0f, 0.0f, 1.0f, 0.0f ); glTranslatef( -x, -0.8f, -8.0f ); // spiegel reflectie for( i = 0; i < num_box; i++ ) { if( !v[i%num_vid].is_frame_flushed ) { continue; } glPushMatrix(); glBindTexture( GL_TEXTURE_2D, v[i%num_vid].tex_gl ); glColor3f( 1.0f, 1.0f, 1.0f ); glTranslatef( i * x_space, -1.2f, 0.0f ); glRotatef( r, 0.0f, 1.0f, 0.0f ); glScalef( 1.0f, -1.0f, 1.0f ); texCube(); glPopMatrix(); } // vloer glPushMatrix(); glBindTexture( GL_TEXTURE_2D, 0 ); glColor4f( 0.0f, 0.0f, 0.0f, 0.8f ); glBegin( GL_QUADS ); glVertex3f( 100.0f, 0.0f,-100.0f ); glVertex3f(-100.0f, 0.0f,-100.0f ); glVertex3f(-100.0f, 0.0f, 100.0f ); glVertex3f( 100.0f, 0.0f, 100.0f ); glEnd(); glPopMatrix(); // top for( i = 0; i < num_box; i++ ) { if( !v[i%num_vid].is_frame_flushed ) { continue; } glPushMatrix(); glBindTexture( GL_TEXTURE_2D, v[i%num_vid].tex_gl ); glColor3f( 1.0f, 1.0f, 1.0f ); glTranslatef( i * x_space, 1.2f, 0.0f ); glRotatef( r, 0.0f, 1.0f, 0.0f ); texCube(); glPopMatrix(); } SwapBuffers( hDC ); PrintMemoryInfo( GetCurrentProcessId() ); } } for( i = 0; i < num_vid; i++ ) { vineoClose( &v[i] ); }; disableOpenAL(); disableOpenGL( hwnd, hDC, hRC ); DestroyWindow( hwnd ); return msg.wParam; }
void X11OpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) { m_data->m_dpy = MyXOpenDisplay(NULL); m_data->m_glWidth = ci.m_width; m_data->m_glHeight = ci.m_height; if(m_data->m_dpy == NULL) { printf("\n\tcannot connect to X server\n\n"); exit(0); } m_data->m_root = DefaultRootWindow(m_data->m_dpy); #ifdef GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS GLboolean res = glewXInit(); if (res==0) { printf("glewXInit OK\n"); } else { printf("glewXInit failed, exit\n"); exit(0); } #endif //GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS if (ci.m_openglVersion < 3) { forceOpenGL3 = false; } if (forceOpenGL3) { int glxMinor, glxMajor; if (!glXQueryVersion(m_data->m_dpy,&glxMajor,&glxMinor) || (((glxMajor==1)&&(glxMinor<3)) || (glxMajor<1))) { printf("Invalid GLX version: major %d, minor %d\n",glxMajor,glxMinor); exit(0); } static int visual_attribs[] = { GLX_X_RENDERABLE , True, GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT, GLX_RENDER_TYPE , GLX_RGBA_BIT, GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR, GLX_RED_SIZE , 8, GLX_GREEN_SIZE , 8, GLX_BLUE_SIZE , 8, GLX_ALPHA_SIZE , 8, GLX_DEPTH_SIZE , 24, GLX_STENCIL_SIZE , 8, GLX_DOUBLEBUFFER , True, None }; int fbcount; GLXFBConfig* fbc = glXChooseFBConfig(m_data->m_dpy, DefaultScreen(m_data->m_dpy), visual_attribs, &fbcount); if (!fbc) { printf( "Failed to retrieve a framebuffer config\n" ); exit(1); } ///don't use highest samples, it is really slow on some NVIDIA Quadro cards #ifdef USE_HIGHEST_SAMPLES int best_fbc = -1, worst_fbc = -1, best_num_samp = -1, worst_num_samp = 999; int i; for (i=0; i<fbcount; ++i) { XVisualInfo *vi = glXGetVisualFromFBConfig( m_data->m_dpy, fbc[i] ); if ( vi ) { int samp_buf, samples; glXGetFBConfigAttrib( m_data->m_dpy, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf ); glXGetFBConfigAttrib( m_data->m_dpy, fbc[i], GLX_SAMPLES , &samples ); //printf( " Matching fbconfig %d, visual ID 0x%2x: SAMPLE_BUFFERS = %d," // " SAMPLES = %d\n", // i, vi -> visualid, samp_buf, samples ); if ( best_fbc < 0 || (samp_buf && (samples > best_num_samp)) ) best_fbc = i, best_num_samp = samples; if ( worst_fbc < 0 || (!samp_buf || (samples < worst_num_samp)) ) worst_fbc = i, worst_num_samp = samples; } MyXFree( vi ); } m_data->m_bestFbc = fbc[ best_fbc ]; #else m_data->m_bestFbc = *fbc; #endif // Be sure to free the FBConfig list allocated by glXChooseFBConfig() MyXFree( fbc ); m_data->m_vi = glXGetVisualFromFBConfig( m_data->m_dpy, m_data->m_bestFbc ); m_data->m_swa.colormap = m_data->m_cmap = MyXCreateColormap( m_data->m_dpy, RootWindow( m_data->m_dpy, m_data->m_vi->screen ), m_data->m_vi->visual, AllocNone ); m_data->m_swa.background_pixmap = None ; m_data->m_swa.border_pixel = 0; m_data->m_swa.event_mask = ExposureMask | KeyReleaseMask | KeyPressMask |ButtonPressMask | ButtonReleaseMask |PointerMotionMask|StructureNotifyMask; ; m_data->m_root = RootWindow( m_data->m_dpy, m_data->m_vi->screen ); m_data->m_win = MyXCreateWindow( m_data->m_dpy, m_data->m_root, 0, 0, ci.m_width, ci.m_height, 0, m_data->m_vi->depth, InputOutput, m_data->m_vi->visual, CWBorderPixel|CWColormap|CWEventMask, &m_data->m_swa ); //m_data->m_win = m_data->m_x11_XCreateWindow(m_data->m_dpy, m_data->m_root, 0, 0, ci.m_width, ci.m_height, 0, m_data->m_vi->depth, InputOutput, m_data->m_vi->visual, CWColormap | CWEventMask, &m_data->m_swa); if (!m_data->m_win) { printf("Cannot create window\n"); exit(0); } MyXMapWindow(m_data->m_dpy, m_data->m_win); MyXStoreName(m_data->m_dpy, m_data->m_win, "OpenGL3 Window"); } else { m_data->m_vi = glXChooseVisual(m_data->m_dpy, 0, att); printf("4\n"); if(m_data->m_vi == NULL) { printf("\n\tno appropriate visual found\n\n"); exit(0); } else { printf("\n\tvisual %p selected\n", (void *)m_data->m_vi->visualid); /* %p creates hexadecimal output like in glxinfo */ } m_data->m_cmap = MyXCreateColormap(m_data->m_dpy, m_data->m_root, m_data->m_vi->visual, AllocNone); m_data->m_swa.colormap = m_data->m_cmap; m_data->m_swa.event_mask = ExposureMask | KeyReleaseMask | KeyPressMask |ButtonPressMask | ButtonReleaseMask |PointerMotionMask|StructureNotifyMask; m_data->m_win = MyXCreateWindow(m_data->m_dpy, m_data->m_root, 0, 0, ci.m_width, ci.m_height, 0, m_data->m_vi->depth, InputOutput, m_data->m_vi->visual, CWColormap | CWEventMask, &m_data->m_swa); MyXMapWindow(m_data->m_dpy, m_data->m_win); MyXStoreName(m_data->m_dpy, m_data->m_win, "OpenGL2 Window"); } enableOpenGL(); }