/******************************************************************* ** OpenGLの初期化 *******************************************************************/ bool OpenGL::InitOpenGL(HWND hWnd) { if ( !::IsWindow(hWnd) ) { fprintf(stderr, "OpenGL::CreateOpenGL Invalid Window Handle"); return false; } m_hWnd = hWnd; m_hDC = ::GetDC(hWnd); if ( !SetWindowPixelFormat() ) { fprintf(stderr, "OpenGL::SetWindowPixelFormat Error"); return false; } if ( !CreateGLContext() ) { fprintf(stderr, "OpenGL::CreateGLContext Error"); return false; } return (true); }
WebView::WebView(WebWindow* window, QObject* parent) : QOpenGLWebPage(parent) , window_(window) { setWindow(window_); connect(this, SIGNAL(requestGLContext()), this, SLOT(CreateGLContext()), Qt::DirectConnection); initialize(); LoadFrameScripts(this); }
int COpenGLView::InitOpenGL() { // Формируем контекст рабочей области m_pDC = new CClientDC(this); ASSERT(m_pDC != NULL); // Получаем дескриптор контекста устройства HDC hdc = m_pDC->GetSafeHdc(); // Устанавливаем формат пикселей if (SetPixelFormat(hdc)==FALSE) return -1; // Создаем и делаем текущим контекст воспроизведения if (CreateGLContext(hdc)==FALSE) return -1; return 0; }
void CRenderManager::StartUp() { CCoreEngine::Instance().GetLogManager().LogOutput( LOG_INFO, LOGSUB_VIDEO,"Starting Up! (LOADING VIDEO XML CONFIG)"); CXMLParserPUGI Parser(VIDEO_CONFIG_XML_PATH); int l_WinWidth = Parser.GetIntAttributeValue("WINDOW","WinWidth"); int l_WinHeight = Parser.GetIntAttributeValue("WINDOW","WinHeight"); int l_WinPosX = Parser.GetIntAttributeValue("WINDOW","WinPosX"); int l_WinPosY = Parser.GetIntAttributeValue("WINDOW","WindPosY"); int l_fullscreen = Parser.GetIntAttributeValue("WINDOW","Fullscreen"); int l_multisample_buffers = Parser.GetIntAttributeValue("GL_ATTRIBUTES","MultisampleBuffers"); int l_multisample_samples = Parser.GetIntAttributeValue("GL_ATTRIBUTES","MultisampleSamples"); std::string l_WindowCaption = Parser.GetStringAttributeValue("WINDOW","WindowCaption"); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); /* Turn on double buffering with a 24bit Z buffer. * You may need to change this to 16 or 32 for your system */ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); //MULTISAMPLE! (ANTIALIASING) SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, l_multisample_buffers); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, l_multisample_samples); SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); m_Window = new CWindow(SDL_WINDOW_OPENGL,l_WindowCaption, l_WinPosX, l_WinPosY, l_WinWidth, l_WinHeight, l_fullscreen != 0 ? true: false ); CreateGLContext(); InitGL(); }
void xlGLCanvas::SetCurrentGLContext() { glGetError(); if (m_context == nullptr) { LOG_GL_ERRORV(CreateGLContext()); } LOG_GL_ERRORV(m_context->SetCurrent(*this)); if (!functionsLoaded) { LOG_GL_ERRORV(DrawGLUtils::LoadGLFunctions()); functionsLoaded = true; } if (cache == nullptr) { wxConfigBase* config = wxConfigBase::Get(); int ver = 99; config->Read("ForceOpenGLVer", &ver, 99); static log4cpp::Category &logger_opengl = log4cpp::Category::getInstance(std::string("log_opengl")); const GLubyte* str = glGetString(GL_VERSION); const GLubyte* rend = glGetString(GL_RENDERER); const GLubyte* vend = glGetString(GL_VENDOR); wxString configs = wxString::Format("%s - glVer: %s (%s)(%s)", (const char *)GetName().c_str(), (const char *)str, (const char *)rend, (const char *)vend); if (wxString(rend) == "GDI Generic" || wxString(vend).Contains("Microsoft")) { bool warned; config->Read("GDI-Warned", &warned, false); if (!warned) { config->Write("GDI-Warned", true); wxString msg = wxString::Format("Generic non-accelerated graphics driver detected (%s - %s). Performance will be poor. " "Please install updated video drivers for your video card.", vend, rend); CallAfter(&xlGLCanvas::DisplayWarning, msg); } //need to use 1.x ver = 1; } logger_opengl.info(std::string(configs.c_str())); printf("%s\n", (const char *)configs.c_str()); if (ver >= 3 && (str[0] > '3' || (str[0] == '3' && str[2] >= '3'))) { if (logger_opengl.isDebugEnabled()) { AddDebugLog(this); } logger_opengl.info("Try creating 3.3 Cache"); LOG_GL_ERRORV(cache = Create33Cache(UsesVertexTextureAccumulator(), UsesVertexColorAccumulator(), UsesVertexAccumulator(), UsesAddVertex())); } if (cache == nullptr && ver >=2 && ((str[0] > '2') || (str[0] == '2' && str[2] >= '1'))) { logger_opengl.info("Try creating 2.1 Cache"); LOG_GL_ERRORV(cache = Create21Cache()); } if (cache == nullptr) { logger_opengl.info("Try creating 1.1 Cache"); LOG_GL_ERRORV(cache = Create11Cache()); } if (cache == nullptr) { logger_opengl.error("All attempts at cache creation have failed."); } } LOG_GL_ERRORV(DrawGLUtils::SetCurrentCache(cache)); }
// Simple, generic window init // int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int iCmdShow) { WNDCLASS wc; MSG msg; bool Quit = FALSE; DWORD dwExStyle; // Window Extended Style DWORD dwStyle; // Window Style // register window class wc.style = CS_OWNDC; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = L"BMFontGL"; RegisterClass(&wc); dwExStyle = WS_EX_APPWINDOW; // Window Extended Style dwStyle = WS_OVERLAPPEDWINDOW | WS_THICKFRAME; // Windows Style RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values WindowRect.left = (long)0; // Set Left Value To 0 WindowRect.right = (long)WinWidth; // Set Right Value To Requested Width WindowRect.top = (long)0; // Set Top Value To 0 WindowRect.bottom = (long)WinHeight; // Set Bottom Value To Requested Height AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size // Create The Window if (!(hWnd = CreateWindowEx(dwExStyle, // Extended Style For The Window L"BMFontGL", // Class Name L"OpenGL BMFont Sample Implementation", // Window Title dwStyle | // Defined Window Style WS_CLIPSIBLINGS | // Required Window Style WS_CLIPCHILDREN, // Required Window Style CW_USEDEFAULT, 0, // Window Position WindowRect.right - WindowRect.left, // Calculate Window Width WindowRect.bottom - WindowRect.top, // Calculate Window Height NULL, // No Parent Window NULL, // No Menu hInstance, // Instance NULL))) // Dont Pass Anything To WM_CREATE { // Reset The Display MessageBox(NULL, L"Window Creation Error.", L"ERROR", MB_OK | MB_ICONEXCLAMATION); return FALSE; // Return FALSE } //********** Program Initializations ************* //Enable Logging LogOpen("glfonttest.log"); // enable OpenGL for the window CreateGLContext(); //Basic Window Init WRLOG("Starting Program"); ShowWindow(hWnd, SW_SHOW); // Show The Window SetForegroundWindow(hWnd); // Slightly Higher Priority SetFocus(hWnd); // Sets Keyboard Focus To The Window ReSizeGLScene(WinWidth, WinHeight); // Set Up Our Perspective GL Screen //Get the Supported OpenGl Version CheckGLVersionSupport(); //Fill in the Window Rect; GetClientRect(hWnd, &MyWindow); //Set the OpenGl View ViewOrtho(WinWidth, WinHeight); //Load and Initialize the Fonts wrlog("Starting to parse fonts."); Lucida = new BMFont(WinWidth, WinHeight); if (!Lucida->LoadFont("lucida.fnt")) { MessageBox(NULL, L"Error, font file not found, exiting", L"File Not Found", MB_ICONERROR | MB_OK); Quit = TRUE; //PostQuitMessage(-1); } LOG_DEBUG("Font Loaded Sucessfully"); Snap = new BMFont(WinWidth, WinHeight); if (!Snap->LoadFont("snap.fnt")) { MessageBox(NULL, L"Error, font file not found, exiting", L"File Not Found", MB_ICONERROR | MB_OK); Quit = TRUE; //PostQuitMessage(-1); } LOG_DEBUG("Font Loaded Sucessfully"); Times = new BMFont(WinWidth, WinHeight); if (!Times->LoadFont("times.fnt")) { MessageBox(NULL, L"Error, font file not found, exiting", L"File Not Found", MB_ICONERROR | MB_OK); Quit = TRUE; // PostQuitMessage(-1); } LOG_DEBUG("Font Loaded Sucessfully"); // ********** Program Main Loop ********** while (!Quit) { // check for messages if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { // handle or dispatch messages if (msg.message == WM_QUIT) { Quit = TRUE; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } else { // ********** OpenGL drawing code, very simple, just to show off the font. ********** glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); // setup texture mapping glEnable(GL_TEXTURE_2D); glLoadIdentity(); Times->SetAlign(BMFont::AlignCenter); Times->SetScale(1.5f); Times->SetColor(250, 251, 252, 255); Times->Print(0, 280, "A different font, centered. Kerning: To Ti"); /* Lucida->setColor(250,250,55,254); Lucida->PrintCenter(240,"This is another font."); Snap->setColor(255,255,255,255); Snap->setScale(1.0f); Snap->Print(0, 0, "This is standard printing."); */ Snap->SetColor(RGB_WHITE); Snap->SetAngle(0); Snap->SetScale(2.0f); Snap->SetAlign(BMFont::AlignNear); Snap->Print(40.0, 180, "Scaling makes it Big!"); Snap->SetColor(RGB_WHITE); Snap->SetScale(1.0f); Snap->SetAngle(90); Snap->Print(130.0, 100, "The next line is right here."); Snap->SetAngle(0); Snap->Print(130.0, 350, "Another long line here."); /* Snap->setScale(1.0f); Snap->Print(2, Snap->getHeight()*4, "Or it can make it smaller!"); Snap->setScale(1.0f); Snap->setColor(25,155,255,255); Snap->PrintCenter(320, "Centered printing: To Ti"); */ Times->Render(); Snap->Render(); GlSwap(); } } // ********** Cleanup and exit gracefully. ********** // shutdown OpenGL delete Lucida; delete Snap; delete Times; DeleteGLContext(); LogClose(); // destroy the window DestroyWindow(hWnd); return (int)msg.wParam; }