int _glfwPlatformInit(void) { XInitThreads(); _glfw.x11.display = XOpenDisplay(NULL); if (!_glfw.x11.display) { _glfwInputError(GLFW_API_UNAVAILABLE, "X11: Failed to open X display"); return GL_FALSE; } _glfw.x11.screen = DefaultScreen(_glfw.x11.display); _glfw.x11.root = RootWindow(_glfw.x11.display, _glfw.x11.screen); _glfw.x11.context = XUniqueContext(); if (!initExtensions()) return GL_FALSE; _glfw.x11.cursor = createNULLCursor(); if (!_glfwInitContextAPI()) return GL_FALSE; _glfwInitTimer(); _glfwInitJoysticks(); _glfwInitGammaRamp(); return GL_TRUE; }
Caches::Caches(): Singleton<Caches>(), mInitialized(false) { init(); initFont(); initExtensions(); initConstraints(); initProperties(); mDebugLevel = readDebugLevel(); ALOGD("Enabling debug mode %d", mDebugLevel); }
void MainWindow::initializeGL() { initExtensions(); glClearColor(0.2,0.6,0.9,1.0); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); scene.initializeGL(); }
bool loadExtensions() { // Check that we support the minimum version required if(!checkVersion(GLELP_GL_MAJOR_VERSION, GLELP_GL_MINOR_VERSION)) return false; // load hard coded windows extensions needed if(!loadHardcodedWindowsExtension()) return false; return initExtensions(); }
int _glfwPlatformInit(void) { // HACK: If the current locale is C, apply the environment's locale // This is done because the C locale breaks character input if (strcmp(setlocale(LC_CTYPE, NULL), "C") == 0) setlocale(LC_CTYPE, ""); XInitThreads(); _glfw.x11.display = XOpenDisplay(NULL); if (!_glfw.x11.display) { _glfwInputError(GLFW_PLATFORM_ERROR, "X11: Failed to open X display"); return GL_FALSE; } _glfw.x11.screen = DefaultScreen(_glfw.x11.display); _glfw.x11.root = RootWindow(_glfw.x11.display, _glfw.x11.screen); _glfw.x11.context = XUniqueContext(); if (!initExtensions()) return GL_FALSE; _glfw.x11.cursor = createNULLCursor(); if (XSupportsLocale()) { XSetLocaleModifiers(""); _glfw.x11.im = XOpenIM(_glfw.x11.display, 0, 0, 0); if (_glfw.x11.im) { if (!hasUsableInputMethodStyle()) { XCloseIM(_glfw.x11.im); _glfw.x11.im = NULL; } } } if (!_glfwInitContextAPI()) return GL_FALSE; if (!_glfwInitJoysticks()) return GL_FALSE; _glfwInitTimer(); return GL_TRUE; }
void initEntryPoints(HWND hwnd, const PIXELFORMATDESCRIPTOR &pfd){ HDC hdc = GetDC(hwnd); int nPixelFormat = ChoosePixelFormat(hdc, &pfd); SetPixelFormat(hdc, nPixelFormat, &pfd); HGLRC hglrc = wglCreateContext(hdc); wglMakeCurrent(hdc, hglrc); initExtensions(hdc); wglMakeCurrent(NULL, NULL); wglDeleteContext(hglrc); ReleaseDC(hwnd, hdc); }
void Video::init(int xres, int yres, bool fullscreen) { SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO); flags = SDL_OPENGL | SDL_HWSURFACE | SDL_ANYFORMAT | SDL_DOUBLEBUF | SDL_RESIZABLE; if (fullscreen) flags |= SDL_FULLSCREEN; //else // flags |= SDL_RESIZABLE; // 32 bits ffs SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); #ifdef _WIN32 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32); primary = SDL_SetVideoMode(xres, yres, 32, flags); #else //nvidia dont support 32bpp on my linux :( SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); primary = SDL_SetVideoMode(xres, yres, 24, flags); #endif if(!primary) { printf("SDL Error: %s\n", SDL_GetError()); exit(1); } initExtensions(); origX = xres; origY = yres; this->xres = xres; this->yres = yres; this->ratio = ((float)xres)/((float)yres); glViewport(0, 0, xres, yres); glMatrixMode(GL_PROJECTION); glLoadIdentity(); //gluPerspective(45.0f, (GLfloat)xres/(GLfloat)yres, 0.01f, 1024.0f); gluPerspective(45.0f, (GLfloat)xres/(GLfloat)yres, 1.0f, 1024.0f); // hmmm... glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); SDL_WM_SetCaption(APP_TITLE " : " APP_VERSION, NULL); }
void ProfileDialog::login(const QString &password) { QVariant variant = ui->profileList->currentItem()->data(Qt::UserRole + 1); Config config = variant.value<Config>(); JsonFile file(profilesConfigPath()); QVariant var; QVariantMap varMap; file.load(var); varMap = var.toMap(); varMap["current"] = varMap.value("id").toString(); file.save(varMap); if (acceptProfileInfo(config, password)) { QTimer::singleShot(0, m_manager, SLOT(initExtensions())); deleteLater(); } }
const char * getPlatformExtensions () { initExtensions (); // since we will need it for platform-specific extensions #ifdef _WIN32 // check Windoze extensions if ( wglGetExtensionsStringARB == NULL ) return ""; return wglGetExtensionsStringARB ( wglGetCurrentDC () ); #else // check GLX extensions Display * display = glXGetCurrentDisplay (); int screen = DefaultScreen ( display ); return glXQueryExtensionsString ( display, screen ); #endif }
ModuleManagerImpl::ModuleManagerImpl() { ModuleManager::loadPlugins(); Config config = ProfileDialog::profilesInfo(); #ifdef QUTIM_SINGLE_PROFILE bool singleProfile = true; #else bool singleProfile = false; #endif singleProfile = config.value("singleProfile", singleProfile); QWizard *wizard = 0; StatisticsHelper *helper = 0; if (singleProfile) { if (!config.hasChildGroup("profile")) { wizard = new ProfileCreationWizard(this, QString(), QString(), true); } else { config.beginGroup("profile"); helper = new StatisticsHelper(); if (helper->action() == StatisticsHelper::NeedToAskInit || helper->action() == StatisticsHelper::NeedToAskUpdate) { wizard = new QWizard(); wizard->addPage(new SubmitPage(helper, wizard)); } if(ProfileDialog::acceptProfileInfo(config, QString())) { QTimer::singleShot(0, this, SLOT(initExtensions())); } else { qWarning("Can't login"); QDialog *dialog = new ProfileDialog(config, this); SystemIntegration::show(dialog); } config.endGroup(); } } else { QDialog *dialog = new ProfileDialog(config, this); SystemIntegration::show(dialog); } if (wizard) { wizard->setAttribute(Qt::WA_DeleteOnClose, true); wizard->setAttribute(Qt::WA_QuitOnClose, false); SystemIntegration::show(wizard); } }
bool isExtensionSupported ( const char * ext ) { initExtensions (); // since we will need it for platform-specific extensions const char * extensions = (const char *) glGetString ( GL_EXTENSIONS ); if ( isExtensionSupported ( ext, extensions ) ) return true; #ifdef _WIN32 // check Windoze extensions if ( wglGetExtensionsStringARB == NULL ) return false; return isExtensionSupported ( ext, wglGetExtensionsStringARB ( wglGetCurrentDC () ) ); #else // check GLX extensions Display * display = glXGetCurrentDisplay (); int screen = DefaultScreen ( display ); return isExtensionSupported ( ext, glXQueryExtensionsString ( display, screen ) ); #endif }
int main(int argc, char* argv[]) { // GLUT initialization glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); int screenWidth = glutGet(GLUT_SCREEN_WIDTH); int screenHeight = glutGet(GLUT_SCREEN_HEIGHT); windowWidth = 1280; windowHeight = 720; glutInitWindowSize(windowWidth, windowHeight); glutInitWindowPosition((screenWidth - windowWidth) / 2, (screenHeight - windowHeight) / 2); glutCreateWindow("Solar System"); // Register callbacks glutDisplayFunc(display); glutReshapeFunc(reshape); // callback when the window is resized glutKeyboardFunc(keyboard); glutSpecialFunc(move); glutMouseFunc(mouse); glutPassiveMotionFunc(motion); // callback when the mouse is moving glutIdleFunc(idle); // idle-time callback // init and check GLEW, version, extensions if (!initExtensions()){ printf("Failed to init extensions.\n"); return 0; } // create and compile shaders/program if (!initShaders("shaders/trackball.vert", "shaders/trackball.frag")){ printf("Failed to init program and shaders\n"); return 0; } // user initialization if (!userInit()){ printf("Failed to userInit()\n"); return 0; } // Start rendering loop //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glutMainLoop(); return 0; }
void initGraphics() { glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glShadeModel(GL_SMOOTH); initExtensions(); Display* display = glXGetCurrentDisplay(); GLXDrawable drawable = glXGetCurrentDrawable(); int screen = DefaultScreen(display); GLuint max_groups, max_barriers; mGlxFuncs.glXQueryMaxSwapGroupsNV(display, screen, &max_groups, &max_barriers); std::cout << "Screen: " << screen << std::endl << " Max groups: " << max_groups << " Max Barriers:" << max_barriers << std::endl; std::cout << "Setting up NV swap group and barrier group. Group: 1, Barrier: 1\n"; // For now, just assume both groups are group 1 mGlxFuncs.glXJoinSwapGroupNV(display, drawable, 1); mGlxFuncs.glXBindSwapBarrierNV(display, 1, 1); }
void initSaver(HWND hwnd){ RECT rect; // Window initialization hdc = GetDC(hwnd); setBestPixelFormat(hdc); hglrc = wglCreateContext(hdc); GetClientRect(hwnd, &rect); wglMakeCurrent(hdc, hglrc); // setup viewport //viewport[0] = rect.left; //viewport[1] = rect.top; //viewport[2] = rect.right - rect.left; //viewport[3] = rect.bottom - rect.top; // initialize extensions if(!initExtensions()) dShaders = 0; reshape(rect.right, rect.bottom); #endif //#ifdef RS_XSCREENSAVER void initSaver(HyperspaceSaverSettings *inSettings){ //#endif // Seed random number generator srand((unsigned)time(NULL)); // Limit memory consumption because the Windows previewer is just too darn slow /*if(doingPreview){ dResolution = 6; if(dDepth > 3) dDepth = 3; };*/ // Set up some other inSettings defaults... inSettings->camPos[0] = 0.0f; inSettings->camPos[1] = 0.0f; inSettings->camPos[2] = 0.0f; inSettings->numAnimTexFrames = 20; inSettings->whichTexture = 0; glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); initFlares(inSettings); inSettings->thePath = new splinePath((inSettings->dDepth * 2) + 6); if(inSettings->dUseTunnels) inSettings->theTunnel = new tunnel(inSettings->thePath, 20); // To avoid popping, depth, which will be used for fogging, is set to // dDepth * goo grid size - size of one goo cubelet inSettings->depth = float(inSettings->dDepth) * 2.0f - 2.0f / float(inSettings->dResolution); if(inSettings->dUseGoo) inSettings->theGoo = new goo(inSettings->dResolution, inSettings->depth); inSettings->stars = new stretchedParticle*[inSettings->dStars]; for(int i=0; i<inSettings->dStars; i++){ inSettings->stars[i] = new stretchedParticle; inSettings->stars[i]->radius = rsRandf(float(inSettings->dStarSize) * 0.0005f) + float(inSettings->dStarSize) * 0.0005f; if(i % 10){ // usually bland stars inSettings->stars[i]->color[0] = 0.8f + rsRandf(0.2f); inSettings->stars[i]->color[1] = 0.8f + rsRandf(0.2f); inSettings->stars[i]->color[2] = 0.8f + rsRandf(0.2f); } else{ // occasionally a colorful one inSettings->stars[i]->color[0] = 0.3f + rsRandf(0.7f); inSettings->stars[i]->color[1] = 0.3f + rsRandf(0.7f); inSettings->stars[i]->color[2] = 0.3f + rsRandf(0.7f); inSettings->stars[i]->color[rsRandi(3)] = 1.0f; } inSettings->stars[i]->color[rsRandi(3)] = 1.0f; inSettings->stars[i]->pos[0] = rsRandf(2.0f * inSettings->depth) - inSettings->depth; inSettings->stars[i]->pos[1] = rsRandf(4.0f) - 2.0f; inSettings->stars[i]->pos[2] = rsRandf(2.0f * inSettings->depth) - inSettings->depth; inSettings->stars[i]->fov = float(inSettings->dFov); } inSettings->sunStar = new stretchedParticle; inSettings->sunStar->radius = float(inSettings->dStarSize) * 0.004f; inSettings->sunStar->pos[0] = 0.0f; inSettings->sunStar->pos[1] = 2.0f; inSettings->sunStar->pos[2] = 0.0f; inSettings->sunStar->fov = float(inSettings->dFov); inSettings->theStarBurst = new starBurst; for(int i=0; i<SB_NUM_STARS; i++) inSettings->theStarBurst->stars[i]->radius = rsRandf(float(inSettings->dStarSize) * 0.001f) + float(inSettings->dStarSize) * 0.001f; glGenTextures(1, &inSettings->nebulatex); if(inSettings->dShaders){ initShaders(); inSettings->numAnimTexFrames = 20; glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, inSettings->nebulatex); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap); gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap); gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap); gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap); gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap); gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap); } else{ //unsigned char spheremap[NEBULAMAPSIZE][NEBULAMAPSIZE][3] = nebulamap; inSettings->numAnimTexFrames = 60; float x, y, temp; const int halfsize(NEBULAMAPSIZE / 2); for(int i=0; i<NEBULAMAPSIZE; ++i){ for(int j=0; j<NEBULAMAPSIZE; ++j){ x = float(i - halfsize) / float(halfsize); y = float(j - halfsize) / float(halfsize); temp = (x * x) + (y * y); if(temp > 1.0f) temp = 1.0f; if(temp < 0.0f) temp = 0.0f; temp = temp * temp; temp = temp * temp; nebulamap[i][j][0] = GLubyte(float(nebulamap[i][j][0]) * temp); nebulamap[i][j][1] = GLubyte(float(nebulamap[i][j][1]) * temp); nebulamap[i][j][2] = GLubyte(float(nebulamap[i][j][2]) * temp); } } glEnable(GL_NORMALIZE); glBindTexture(GL_TEXTURE_2D, inSettings->nebulatex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap); } glEnable(GL_FOG); float fog_color[4] = {0.0f, 0.0f, 0.0f, 1.0f}; glFogfv(GL_FOG_COLOR, fog_color); glFogf(GL_FOG_MODE, GL_LINEAR); glFogf(GL_FOG_START, inSettings->depth * 0.7f); glFogf(GL_FOG_END, inSettings->depth); // Initialize text inSettings->textwriter = new rsText; //outfile.open("outfile"); inSettings->readyToDraw = 1; }
//=========================================================================== // DG_Init // 'mode' is either DGL_MODE_WINDOW or DGL_MODE_FULLSCREEN. If 'bpp' is // zero, the current display color depth is used. //=========================================================================== int DG_Init(int width, int height, int bpp, int mode) { boolean fullscreen = (mode == DGL_MODE_FULLSCREEN); char *token, *extbuf; const SDL_VideoInfo *info = NULL; Con_Message("DG_Init: OpenGL.\n"); // Are we in range here? /* if(!fullscreen) { if(width > GetSystemMetrics(SM_CXSCREEN)) width = GetSystemMetrics(SM_CXSCREEN); if(height > GetSystemMetrics(SM_CYSCREEN)) height = GetSystemMetrics(SM_CYSCREEN); } */ info = SDL_GetVideoInfo(); screenBits = info->vfmt->BitsPerPixel; screenWidth = width; screenHeight = height; windowed = !fullscreen; allowCompression = true; verbose = ArgExists("-verbose"); // Set GL attributes. We want at least 5 bits per color and a 16 // bit depth buffer. Plus double buffering, of course. SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); /* if(fullscreen) { if(!fullscreenMode(screenWidth, screenHeight, bpp)) { Con_Error("drOpenGL.Init: Resolution change failed (%d x %d).\n", screenWidth, screenHeight); } } else { windowedMode(screenWidth, screenHeight); } */ if(!initOpenGL()) { Con_Error("drOpenGL.Init: OpenGL init failed.\n"); } // Clear the buffers. DG_Clear(DGL_COLOR_BUFFER_BIT | DGL_DEPTH_BUFFER_BIT); token = (char *) glGetString(GL_EXTENSIONS); extbuf = malloc(strlen(token) + 1); strcpy(extbuf, token); // Check the maximum texture size. glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize); initExtensions(); if(firstTimeInit) { firstTimeInit = DGL_FALSE; // Print some OpenGL information (console must be initialized by now). Con_Message("OpenGL information:\n"); Con_Message(" Vendor: %s\n", glGetString(GL_VENDOR)); Con_Message(" Renderer: %s\n", glGetString(GL_RENDERER)); Con_Message(" Version: %s\n", glGetString(GL_VERSION)); Con_Message(" Extensions:\n"); // Show the list of GL extensions. token = strtok(extbuf, " "); while(token) { Con_Message(" "); // Indent. if(verbose) { // Show full names. Con_Message("%s\n", token); } else { // Two on one line, clamp to 30 characters. Con_Message("%-30.30s", token); token = strtok(NULL, " "); if(token) Con_Message(" %-30.30s", token); Con_Message("\n"); } token = strtok(NULL, " "); } Con_Message(" GLU Version: %s\n", gluGetString(GLU_VERSION)); glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTexUnits); #ifndef USE_MULTITEXTURE maxTexUnits = 1; #endif // But sir, we are simple people; two units is enough. if(maxTexUnits > 2) maxTexUnits = 2; Con_Message(" Texture units: %i\n", maxTexUnits); Con_Message(" Maximum texture size: %i\n", maxTexSize); if(extAniso) { glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAniso); Con_Message(" Maximum anisotropy: %g\n", maxAniso); } //if(!noArrays) Con_Message(" Using vertex arrays.\n"); } free(extbuf); // Decide whether vertex arrays should be done manually or with real // OpenGL calls. InitArrays(); if(ArgCheck("-dumptextures")) { dumpTextures = DGL_TRUE; Con_Message(" Dumping textures (mipmap level zero).\n"); } if(extAniso && ArgExists("-anifilter")) { useAnisotropic = DGL_TRUE; Con_Message(" Using anisotropic texture filtering.\n"); } return DGL_OK; }
int _glfwPlatformInit(void) { #if !defined(X_HAVE_UTF8_STRING) // HACK: If the current locale is "C" and the Xlib UTF-8 functions are // unavailable, apply the environment's locale in the hope that it's // both available and not "C" // This is done because the "C" locale breaks wide character input, // which is what we fall back on when UTF-8 support is missing if (strcmp(setlocale(LC_CTYPE, NULL), "C") == 0) setlocale(LC_CTYPE, ""); #endif XInitThreads(); XrmInitialize(); _glfw.x11.display = XOpenDisplay(NULL); if (!_glfw.x11.display) { const char* display = getenv("DISPLAY"); if (display) { _glfwInputError(GLFW_PLATFORM_ERROR, "X11: Failed to open display %s", display); } else { _glfwInputError(GLFW_PLATFORM_ERROR, "X11: The DISPLAY environment variable is missing"); } return GLFW_FALSE; } _glfw.x11.screen = DefaultScreen(_glfw.x11.display); _glfw.x11.root = RootWindow(_glfw.x11.display, _glfw.x11.screen); _glfw.x11.context = XUniqueContext(); getSystemContentScale(&_glfw.x11.contentScaleX, &_glfw.x11.contentScaleY); if (!initExtensions()) return GLFW_FALSE; _glfw.x11.helperWindowHandle = createHelperWindow(); _glfw.x11.hiddenCursorHandle = createHiddenCursor(); if (XSupportsLocale()) { XSetLocaleModifiers(""); _glfw.x11.im = XOpenIM(_glfw.x11.display, 0, NULL, NULL); if (_glfw.x11.im) { if (!hasUsableInputMethodStyle()) { XCloseIM(_glfw.x11.im); _glfw.x11.im = NULL; } } } #if defined(__linux__) if (!_glfwInitJoysticksLinux()) return GLFW_FALSE; #endif _glfwInitTimerPOSIX(); _glfwPollMonitorsX11(); return GLFW_TRUE; }
bool OpenGLApp::initAPI(){ PixelFormat pf; initPixelFormat(pf); selectPixelFormat(pf); int bpp = pf.alphaBits > 0? 32 : 24; wa = (pf.accumBits > 0); static PIXELFORMATDESCRIPTOR pfd = { sizeof (PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, bpp, 0, 0, 0, 0, 0, 0, 0, 0, pf.accumBits, pf.accumBits / 4, pf.accumBits / 4, pf.accumBits / 4, pf.accumBits / 4, pf.depthBits, pf.stencilBits, pf.alphaBits, PFD_MAIN_PLANE, 0, 0, 0, 0 }; WNDCLASS wincl; HINSTANCE hInst = (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE); wincl.hInstance = hInst; wincl.lpszClassName = "PFrmt"; wincl.lpfnWndProc = PFWinProc; wincl.style = 0; wincl.hIcon = NULL; wincl.hCursor = NULL; wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = NULL; RegisterClass(&wincl); HWND hPFwnd = CreateWindow("PFrmt", "PFormat", WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 8, 8, HWND_DESKTOP, NULL, hInst, NULL); initEntryPoints(hPFwnd, pfd); SendMessage(hPFwnd, WM_CLOSE, 0, 0); hdc = GetDC(hwnd); int pixelFormat; float fAttribs[256]; int iAttribs[256] = { WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, WGL_DOUBLE_BUFFER_ARB, GL_TRUE, WGL_RED_BITS_ARB, pf.redBits, WGL_GREEN_BITS_ARB, pf.greenBits, WGL_BLUE_BITS_ARB, pf.blueBits, WGL_ALPHA_BITS_ARB, pf.alphaBits, WGL_DEPTH_BITS_ARB, pf.depthBits, WGL_STENCIL_BITS_ARB, pf.stencilBits, WGL_ACCUM_BITS_ARB, pf.accumBits, }; while (true){ int *iAtt = iAttribs + 20; float *fAtt = fAttribs; if (WGL_ARB_multisample_supported && pf.fsaaLevel > 0){ *iAtt++ = WGL_SAMPLE_BUFFERS_ARB; *iAtt++ = GL_TRUE; *iAtt++ = WGL_SAMPLES_ARB; *iAtt++ = pf.fsaaLevel; } *iAtt++ = 0; *fAtt++ = 0; unsigned int nMatchingPixelFormats; if (!WGL_ARB_pixel_format_supported || !wglChoosePixelFormatARB(hdc, iAttribs, fAttribs, 1, &pixelFormat, &nMatchingPixelFormats) || nMatchingPixelFormats == 0){ if (pf.fsaaLevel > 0){ pf.fsaaLevel -= 2; } else { pixelFormat = ChoosePixelFormat(hdc, &pfd); break; } } else break; } SetPixelFormat(hdc, pixelFormat, &pfd); hglrc = wglCreateContext(hdc); wglMakeCurrent(hdc, hglrc); initExtensions(hdc); if (WGL_ARB_multisample_supported && pf.fsaaLevel > 0){ glEnable(GL_MULTISAMPLE_ARB); } renderer = new OpenGLRenderer(hdc, hglrc); return true; }
NS_CC_BEGIN EGLView::EGLView() { initExtensions(); }
GLView::GLView() { initExtensions(); }
} QT_CATCH(...) { } config.beginGroup("profile"); config.setValue("name", user); config.setValue("id", user); config.setValue("crypto",cryptoService->metaObject()->className()); config.setValue("config", QLatin1String(configBackends.first()->metaObject()->className())); config.setValue("portable", false); config.setValue("configDir", SystemInfo::getPath(SystemInfo::ConfigDir)); config.setValue("historyDir", SystemInfo::getPath(SystemInfo::HistoryDir)); config.setValue("shareDir", SystemInfo::getPath(SystemInfo::ShareDir)); config.endGroup(); } QTimer::singleShot(0, this, SLOT(initExtensions())); } ExtensionInfoList ModuleManagerImpl::coreExtensions() const { return ExtensionInfoList(); } void ModuleManagerImpl::initExtensions() { QString path = SystemInfo::getPath(SystemInfo::SystemShareDir); path += QLatin1String("/ca-certs/*.pem"); QSslSocket::addDefaultCaCertificates(path, QSsl::Pem, QRegExp::Wildcard); ModuleManager::initExtensions();
GLViewImpl::GLViewImpl() { initExtensions(); }
bool OpenGLApp::initAPI(){ if (screen >= GetSystemMetrics(SM_CMONITORS)) screen = 0; int monitorCounter = screen; EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, (LPARAM) &monitorCounter); DWORD flags = WS_CLIPCHILDREN | WS_CLIPSIBLINGS; int x, y; x = monInfo.rcMonitor.left; y = monInfo.rcMonitor.top; device.cb = sizeof(device); EnumDisplayDevices(NULL, screen, &device, 0); DEVMODE dm, tdm; memset(&dm, 0, sizeof(dm)); dm.dmSize = sizeof(dm); dm.dmBitsPerPel = colorBits; dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY; dm.dmPelsWidth = fullscreenWidth; dm.dmPelsHeight = fullscreenHeight; dm.dmDisplayFrequency = 60; // Find a suitable fullscreen format int i = 0; int targetHz = 85; char str[128]; resolution->clear(); while (EnumDisplaySettings((const char *) device.DeviceName, i, &tdm)){ if (int(tdm.dmBitsPerPel) == colorBits && tdm.dmPelsWidth >= 640 && tdm.dmPelsHeight >= 480){ sprintf(str, "%dx%d", tdm.dmPelsWidth, tdm.dmPelsHeight); int index = resolution->addItemUnique(str); if (int(tdm.dmPelsWidth) == fullscreenWidth && int(tdm.dmPelsHeight) == fullscreenHeight){ if (abs(int(tdm.dmDisplayFrequency) - targetHz) < abs(int(dm.dmDisplayFrequency) - targetHz)){ dm = tdm; } resolution->selectItem(index); } } i++; } if (fullscreen){ if (ChangeDisplaySettingsEx((const char *) device.DeviceName, &dm, NULL, CDS_FULLSCREEN, NULL) == DISP_CHANGE_SUCCESSFUL){ flags |= WS_POPUP; captureMouse(!configDialog->isVisible()); } else { ErrorMsg("Couldn't set fullscreen mode"); fullscreen = false; } } sprintf(str, "%s (%dx%d)", getTitle(), width, height); if (!fullscreen){ flags |= WS_OVERLAPPEDWINDOW; RECT wRect; wRect.left = 0; wRect.right = width; wRect.top = 0; wRect.bottom = height; AdjustWindowRect(&wRect, flags, FALSE); width = min(wRect.right - wRect.left, monInfo.rcWork.right - monInfo.rcWork.left); height = min(wRect.bottom - wRect.top, monInfo.rcWork.bottom - monInfo.rcWork.top); x = (monInfo.rcWork.left + monInfo.rcWork.right - width ) / 2; y = (monInfo.rcWork.top + monInfo.rcWork.bottom - height) / 2; } hwnd = CreateWindow("Humus", str, flags, x, y, width, height, HWND_DESKTOP, NULL, hInstance, NULL); PIXELFORMATDESCRIPTOR pfd = { sizeof (PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, colorBits, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, depthBits, stencilBits, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; hdc = GetDC(hwnd); int iAttribs[] = { WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, WGL_DOUBLE_BUFFER_ARB, GL_TRUE, WGL_RED_BITS_ARB, 8, WGL_GREEN_BITS_ARB, 8, WGL_BLUE_BITS_ARB, 8, WGL_ALPHA_BITS_ARB, (colorBits > 24)? 8 : 0, WGL_DEPTH_BITS_ARB, depthBits, WGL_STENCIL_BITS_ARB, stencilBits, 0 }; int pixelFormats[256]; int bestFormat = 0; int bestSamples = 0; uint nPFormats; if (WGL_ARB_pixel_format_supported && wglChoosePixelFormatARB(hdc, iAttribs, NULL, elementsOf(pixelFormats), pixelFormats, &nPFormats) && nPFormats > 0){ int minDiff = 0x7FFFFFFF; int attrib = WGL_SAMPLES_ARB; int samples; // Find a multisample format as close as possible to the requested for (uint i = 0; i < nPFormats; i++){ wglGetPixelFormatAttribivARB(hdc, pixelFormats[i], 0, 1, &attrib, &samples); int diff = abs(antiAliasSamples - samples); if (diff < minDiff){ minDiff = diff; bestFormat = i; bestSamples = samples; } } } else { pixelFormats[0] = ChoosePixelFormat(hdc, &pfd); } antiAliasSamples = bestSamples; SetPixelFormat(hdc, pixelFormats[bestFormat], &pfd); glContext = wglCreateContext(hdc); wglMakeCurrent(hdc, glContext); initExtensions(hdc); if (WGL_ARB_multisample_supported && GL_ARB_multisample_supported && antiAliasSamples > 0){ glEnable(GL_MULTISAMPLE_ARB); } if (fullscreen) captureMouse(!configDialog->isVisible()); renderer = new OpenGLRenderer(hdc, glContext); renderer->setViewport(width, height); antiAlias->selectItem(antiAliasSamples / 2); linearClamp = renderer->addSamplerState(LINEAR, CLAMP, CLAMP, CLAMP); defaultFont = renderer->addFont("../Textures/Fonts/Future.dds", "../Textures/Fonts/Future.font", linearClamp); blendSrcAlpha = renderer->addBlendState(SRC_ALPHA, ONE_MINUS_SRC_ALPHA); noDepthTest = renderer->addDepthState(false, false); noDepthWrite = renderer->addDepthState(true, false); cullNone = renderer->addRasterizerState(CULL_NONE); cullBack = renderer->addRasterizerState(CULL_BACK); cullFront = renderer->addRasterizerState(CULL_FRONT); return true; }
const char * getGeneralExtensions () { initExtensions (); return (const char *) glGetString ( GL_EXTENSIONS ); }
bool OpenGLApp::initAPI(){ screen = DefaultScreen(display); int nModes; XF86VidModeGetAllModeLines(display, screen, &nModes, &dmodes); Array <DispRes> modes; char str[64]; int foundMode = -1; for (int i = 0; i < nModes; i++){ if (dmodes[i]->hdisplay >= 640 && dmodes[i]->vdisplay >= 480){ modes.add(newRes(dmodes[i]->hdisplay, dmodes[i]->vdisplay, i)); if (dmodes[i]->hdisplay == fullscreenWidth && dmodes[i]->vdisplay == fullscreenHeight){ foundMode = i; } } } resolution->clear(); modes.sort(dComp); for (uint i = 0; i < modes.getCount(); i++){ sprintf(str, "%dx%d", modes[i].w, modes[i].h); int index = resolution->addItemUnique(str); if (modes[i].index == foundMode) resolution->selectItem(index); } if (fullscreen){ if (foundMode >= 0 && XF86VidModeSwitchToMode(display, screen, dmodes[foundMode])){ XF86VidModeSetViewPort(display, screen, 0, 0); } else { char str[128]; sprintf(str, "Couldn't set fullscreen at %dx%d.", fullscreenWidth, fullscreenHeight); ErrorMsg(str); fullscreen = false; } } XVisualInfo *vi; while (true){ int attribs[] = { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, (colorBits > 24)? 8 : 0, GLX_DEPTH_SIZE, depthBits, GLX_STENCIL_SIZE, stencilBits, GLX_SAMPLE_BUFFERS_ARB, (antiAliasSamples > 0), GLX_SAMPLES_ARB, antiAliasSamples, None, }; vi = glXChooseVisual(display, screen, attribs); if (vi != NULL) break; antiAliasSamples -= 2; if (antiAliasSamples < 0){ char str[256]; sprintf(str, "No Visual matching colorBits=%d, depthBits=%d and stencilBits=%d", colorBits, depthBits, stencilBits); ErrorMsg(str); return false; } } //printf("Selected visual = 0x%x\n",(unsigned int) (vi->visualid)); glContext = glXCreateContext(display, vi, None, True); XSetWindowAttributes attr; attr.colormap = XCreateColormap(display, RootWindow(display, screen), vi->visual, AllocNone); attr.border_pixel = 0; attr.override_redirect = fullscreen; attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask; window = XCreateWindow(display, RootWindow(display, vi->screen), 0, 0, width, height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, &attr); if (!fullscreen){ Atom wmDelete; wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", True); XSetWMProtocols(display, window, &wmDelete, 1); char *title = "OpenGL"; XSetStandardProperties(display, window, title, title, None, NULL, 0, NULL); } XMapRaised(display, window); // Create a blank cursor for cursor hiding XColor dummy; char data = 0; Pixmap blank = XCreateBitmapFromData(display, window, &data, 1, 1); blankCursor = XCreatePixmapCursor(display, blank, blank, &dummy, &dummy, 0, 0); XFreePixmap(display, blank); XGrabKeyboard(display, window, True, GrabModeAsync, GrabModeAsync, CurrentTime); glXMakeCurrent(display, window, glContext); initExtensions(display); if (antiAliasSamples > 0){ glEnable(GL_MULTISAMPLE_ARB); } if (fullscreen) captureMouse(!configDialog->isVisible()); renderer = new OpenGLRenderer(window, glContext, display, screen); renderer->setViewport(width, height); antiAlias->selectItem(antiAliasSamples / 2); linearClamp = renderer->addSamplerState(LINEAR, CLAMP, CLAMP, CLAMP); defaultFont = renderer->addFont("../Textures/Fonts/Future.dds", "../Textures/Fonts/Future.font", linearClamp); blendSrcAlpha = renderer->addBlendState(SRC_ALPHA, ONE_MINUS_SRC_ALPHA); noDepthTest = renderer->addDepthState(false, false); noDepthWrite = renderer->addDepthState(true, false); cullNone = renderer->addRasterizerState(CULL_NONE); cullBack = renderer->addRasterizerState(CULL_BACK); cullFront = renderer->addRasterizerState(CULL_FRONT); return true; }
int _glfwPlatformInit(void) { #if !defined(X_HAVE_UTF8_STRING) // HACK: If the current locale is C, apply the environment's locale // This is done because the C locale breaks wide character input if (strcmp(setlocale(LC_CTYPE, NULL), "C") == 0) setlocale(LC_CTYPE, ""); #endif XInitThreads(); _glfw.x11.display = XOpenDisplay(NULL); if (!_glfw.x11.display) { const char* display = getenv("DISPLAY"); if (display) { _glfwInputError(GLFW_PLATFORM_ERROR, "X11: Failed to open display %s", display); } else { _glfwInputError(GLFW_PLATFORM_ERROR, "X11: The DISPLAY environment variable is missing"); } return GLFW_FALSE; } _glfw.x11.screen = DefaultScreen(_glfw.x11.display); _glfw.x11.root = RootWindow(_glfw.x11.display, _glfw.x11.screen); _glfw.x11.context = XUniqueContext(); if (!initExtensions()) return GLFW_FALSE; _glfw.x11.cursor = createNULLCursor(); if (XSupportsLocale()) { XSetLocaleModifiers(""); _glfw.x11.im = XOpenIM(_glfw.x11.display, 0, NULL, NULL); if (_glfw.x11.im) { if (!hasUsableInputMethodStyle()) { XCloseIM(_glfw.x11.im); _glfw.x11.im = NULL; } } } if (!_glfwInitContextAPI()) return GLFW_FALSE; if (!_glfwInitJoysticks()) return GLFW_FALSE; _glfwInitTimer(); return GLFW_TRUE; }
bool OpenGLApp::initAPI(){ initialMode = CGDisplayCurrentMode(kCGDirectMainDisplay); dmodes = CGDisplayAvailableModes(kCGDirectMainDisplay); int count = CFArrayGetCount(dmodes); Array <DispRes> modes; int foundMode = -1; for (int i = 0; i < count; i++){ CFDictionaryRef mode = (CFDictionaryRef) CFArrayGetValueAtIndex(dmodes, i); long bitsPerPixel = GetDictionaryLong(mode, kCGDisplayBitsPerPixel); Boolean safeForHardware = GetDictionaryBoolean(mode, kCGDisplayModeIsSafeForHardware); Boolean stretched = GetDictionaryBoolean(mode, kCGDisplayModeIsStretched); if (bitsPerPixel < colorBits || !safeForHardware || stretched) continue; long width = GetDictionaryLong(mode, kCGDisplayWidth); long height = GetDictionaryLong(mode, kCGDisplayHeight); long refreshRate = GetDictionaryLong(mode, kCGDisplayRefreshRate); // printf("Mode: %dx%dx%d @ %d\n", width, height, bitsPerPixel, refreshRate); if (width >= 640 && height >= 480){ modes.add(newRes(width, height, i)); if (width == fullscreenWidth && height == fullscreenHeight){ foundMode = i; } } } resolution->clear(); modes.sort(dComp); char str[64]; for (uint i = 0; i < modes.getCount(); i++){ sprintf(str, "%dx%d", modes[i].w, modes[i].h); int index = resolution->addItemUnique(str); if (modes[i].index == foundMode) resolution->selectItem(index); } if (fullscreen){ if (foundMode < 0 || CGDisplaySwitchToMode(kCGDirectMainDisplay, (CFDictionaryRef) CFArrayGetValueAtIndex(dmodes, foundMode)) != kCGErrorSuccess){ sprintf(str, "Couldn't set fullscreen to %dx%d.", fullscreenWidth, fullscreenHeight); ErrorMsg(str); fullscreen = false; } } Rect rect; if (fullscreen){ rect.left = 0; rect.top = 0; } else { long w = GetDictionaryLong(initialMode, kCGDisplayWidth); long h = GetDictionaryLong(initialMode, kCGDisplayHeight); rect.left = (w - width) / 2; rect.top = (h - height) / 2; } rect.right = rect.left + width; rect.bottom = rect.top + height; WindowAttributes attributes = fullscreen? (kWindowNoTitleBarAttribute | kWindowNoShadowAttribute) : (kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute); OSStatus error = CreateNewWindow(kDocumentWindowClass, attributes, &rect, &window); if (error != noErr || window == NULL){ ErrorMsg("Couldn't create window"); return false; } GDHandle screen = GetGWorldDevice(GetWindowPort(window)); if (screen == NULL){ ErrorMsg("Couldn't get device"); ReleaseWindow(window); return false; } AGLPixelFormat pixelFormat; while (true){ GLint attributes[] = { fullscreen? AGL_FULLSCREEN : AGL_WINDOW, AGL_RGBA, AGL_DOUBLEBUFFER, AGL_RED_SIZE, 8, AGL_GREEN_SIZE, 8, AGL_BLUE_SIZE, 8, AGL_ALPHA_SIZE, (colorBits > 24)? 8 : 0, AGL_DEPTH_SIZE, depthBits, AGL_STENCIL_SIZE, stencilBits, AGL_SAMPLE_BUFFERS_ARB, (antiAliasSamples > 0), AGL_SAMPLES_ARB, antiAliasSamples, AGL_NONE }; pixelFormat = aglChoosePixelFormat(&screen, 1, attributes); if (pixelFormat != NULL) break; antiAliasSamples -= 2; if (antiAliasSamples < 0){ ErrorMsg("No suitable pixel format"); ReleaseWindow(window); return false; } } glContext = aglCreateContext(pixelFormat, NULL); aglDestroyPixelFormat(pixelFormat); if (glContext == NULL){ ErrorMsg("Couldn't create context"); ReleaseWindow(window); return false; } if (fullscreen){ CGCaptureAllDisplays(); aglSetFullScreen(glContext, 0, 0, 0, 0); } else { if (!aglSetDrawable(glContext, GetWindowPort(window))){ ErrorMsg("Couldn't set drawable"); aglDestroyContext(glContext); ReleaseWindow(window); return false; } } if (!aglSetCurrentContext(glContext)){ ErrorMsg("Couldn't make context current"); aglDestroyContext(glContext); ReleaseWindow(window); return false; } setWindowTitle(getTitle()); ShowWindow(window); initExtensions(); if (antiAliasSamples > 0){ glEnable(GL_MULTISAMPLE_ARB); } if (fullscreen) captureMouse(!configDialog->isVisible()); renderer = new OpenGLRenderer(glContext); renderer->setViewport(width, height); antiAlias->selectItem(antiAliasSamples / 2); linearClamp = renderer->addSamplerState(LINEAR, CLAMP, CLAMP, CLAMP); defaultFont = renderer->addFont("../Textures/Fonts/Future.dds", "../Textures/Fonts/Future.font", linearClamp); blendSrcAlpha = renderer->addBlendState(SRC_ALPHA, ONE_MINUS_SRC_ALPHA); noDepthTest = renderer->addDepthState(false, false); noDepthWrite = renderer->addDepthState(true, false); cullNone = renderer->addRasterizerState(CULL_NONE); cullBack = renderer->addRasterizerState(CULL_BACK); cullFront = renderer->addRasterizerState(CULL_FRONT); return true; }
NS_CC_BEGIN CCEGLView::CCEGLView() { initExtensions(); }
void CCEGLView::setFrameSize(float width, float height) { bool eResult = false; int u32GLFWFlags = GLFW_WINDOW; //create the window by glfw. //check CCAssert(width!=0&&height!=0, "invalid window's size equal 0"); //Inits GLFW eResult = glfwInit() != GL_FALSE; if (!eResult) { CCAssert(0, "fail to init the glfw"); } /* Updates window hint */ glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE); int iDepth = 16; // set default value /* Depending on video depth */ switch(iDepth) { /* 16-bit */ case 16: { /* Updates video mode */ eResult = (glfwOpenWindow(width, height, 5, 6, 5, 0, 16, 8, (int)u32GLFWFlags) != false) ? true : false; break; } /* 24-bit */ case 24: { /* Updates video mode */ eResult = (glfwOpenWindow(width, height, 8, 8, 8, 0, 16, 8, (int)u32GLFWFlags) != false) ? true : false; break; } /* 32-bit */ default: case 32: { /* Updates video mode */ eResult = (glfwOpenWindow(width, height, 8, 8, 8, 8, 16, 8, (int)u32GLFWFlags) != GL_FALSE) ? true :false; break; } } /* Success? */ if(eResult) { /* Updates actual size */ // glfwGetWindowSize(&width, &height); CCEGLViewProtocol::setFrameSize(width, height); /* Updates its title */ glfwSetWindowTitle("Cocos2dx-Linux"); //set the init flag bIsInit = true; //register the glfw key event glfwSetKeyCallback(keyEventHandle); //register the glfw char event glfwSetCharCallback(charEventHandle); //register the glfw mouse event glfwSetMouseButtonCallback(mouseButtonEventHandle); //register the glfw mouse pos event glfwSetMousePosCallback(mousePosEventHandle); glfwSetWindowCloseCallback(closeEventHandle); //Inits extensions eResult = initExtensions(); if (!eResult) { CCAssert(0, "fail to init the extensions of opengl"); } initGL(); } }
bool CCEGLView::Create(const char* pTitle, int iPixelWidth, int iPixelHeight, int iWidth, int iHeight, int iDepth) { bool eResult; int u32GLFWFlags = GLFW_WINDOW; //create the window by glfw. //check CCAssert(iPixelWidth!=0&&iPixelHeight!=0, "invalid window's size equal 0"); CCAssert(iWidth!=0&&iHeight!=0, "invalid the size in points equal 0"); //Inits GLFW eResult = glfwInit() != GL_FALSE; if (!eResult) { CCAssert(0, "fail to init the glfw"); } /* Updates window hint */ glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE); /* Depending on video depth */ switch(iDepth) { /* 16-bit */ case 16: { /* Updates video mode */ eResult = (glfwOpenWindow(iPixelWidth, iPixelHeight, 5, 6, 5, 0, 16, 0, (int)u32GLFWFlags) != false) ? true : false; break; } /* 24-bit */ case 24: { /* Updates video mode */ eResult = (glfwOpenWindow(iPixelWidth, iPixelHeight, 8, 8, 8, 0, 16, 0, (int)u32GLFWFlags) != false) ? true : false; break; } /* 32-bit */ default: case 32: { /* Updates video mode */ eResult = (glfwOpenWindow(iPixelWidth, iPixelHeight, 8, 8, 8, 8, 16, 0, (int)u32GLFWFlags) != GL_FALSE) ? true :false; break; } } /* Success? */ if(eResult) { /* Updates actual size */ glfwGetWindowSize(&iPixelWidth, &iPixelHeight); //assign screen size and point's size m_sSizeInPixel.width = iPixelWidth; m_sSizeInPixel.height = iPixelHeight; m_sSizeInPoint.width = iWidth; m_sSizeInPoint.height = iHeight; // calculate the factor and the rect of viewport m_fScreenScaleFactor = MIN((float)m_sSizeInPixel.width / m_sSizeInPoint.width, (float)m_sSizeInPixel.height / m_sSizeInPoint.height); int viewPortW = (int)(m_sSizeInPoint.width * m_fScreenScaleFactor); int viewPortH = (int)(m_sSizeInPoint.height * m_fScreenScaleFactor); m_rcViewPort.origin.x = (m_sSizeInPixel.width - viewPortW) / 2; m_rcViewPort.origin.y = (m_sSizeInPixel.height - viewPortH) / 2; m_rcViewPort.size.width = viewPortW; m_rcViewPort.size.height = viewPortH; /* Updates its title */ glfwSetWindowTitle(pTitle); //set the init flag bIsInit = true; s_pMainWindow = this; //register the glfw key event glfwSetKeyCallback(keyEventHandle); //register the glfw char event glfwSetCharCallback(charEventHandle); //register the glfw mouse event glfwSetMouseButtonCallback(mouseButtonEventHandle); //register the glfw mouse pos event glfwSetMousePosCallback(mousePosEventHandle); //Inits extensions eResult = initExtensions(); if (!eResult) { CCAssert(0, "fail to init the extensions of opengl"); } } return true; }
bool OpenGLApp::initAPI(){ PixelFormat pf; initPixelFormat(pf); selectPixelFormat(pf); int iAttribs[256] = { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, pf.redBits, GLX_GREEN_SIZE, pf.greenBits, GLX_BLUE_SIZE, pf.blueBits, GLX_ALPHA_SIZE, pf.alphaBits, GLX_DEPTH_SIZE, pf.depthBits, GLX_STENCIL_SIZE, pf.stencilBits, GLX_ACCUM_RED_SIZE, pf.accumBits / 4, GLX_ACCUM_GREEN_SIZE, pf.accumBits / 4, GLX_ACCUM_BLUE_SIZE, pf.accumBits / 4, GLX_ACCUM_ALPHA_SIZE, pf.accumBits / 4, }; XVisualInfo *vi; while (true){ int *iAtt = iAttribs + 22; if (/*GLX_ARB_multisample_supported && */pf.fsaaLevel > 0){ *iAtt++ = 100000; *iAtt++ = GL_TRUE; *iAtt++ = 100001; *iAtt++ = pf.fsaaLevel; } *iAtt++ = None; vi = glXChooseVisual(display, screen, iAttribs); if (vi == NULL){ if (pf.fsaaLevel > 0){ pf.fsaaLevel -= 2; } else { printf("Error: Couldn't set visual\n"); return false; } } else break; } int x, y, w, h; if (fullscreen){ x = 0; y = 0; w = fullscreenWidth; h = fullscreenHeight; } else { x = windowedLeft; y = windowedTop; w = windowedRight - windowedLeft; h = windowedBottom - windowedTop; } middleX = w / 2; middleY = h / 2; ctx = glXCreateContext(display, vi, 0, GL_TRUE); XSetWindowAttributes attr; attr.colormap = XCreateColormap(display, RootWindow(display, screen), vi->visual, AllocNone); attr.border_pixel = 0; attr.override_redirect = fullscreen; attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask; window = XCreateWindow(display, RootWindow(display, vi->screen), x, y, w, h, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, &attr); if (!fullscreen){ Atom wmDelete; wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", True); XSetWMProtocols(display, window, &wmDelete, 1); char *title = "OpenGL"; XSetStandardProperties(display, window, title, title, None, NULL, 0, NULL); } XMapRaised(display, window); Pixmap blank; XColor dummy; char data = 0; // Create a blank cursor for cursor hiding blank = XCreateBitmapFromData(display, window, &data, 1, 1); blankCursor = XCreatePixmapCursor(display, blank, blank, &dummy, &dummy, 0, 0); XFreePixmap(display, blank); XGrabKeyboard(display, window, True, GrabModeAsync, GrabModeAsync, CurrentTime); //if (captureMouse) showCursor(false);//XGrabPointer(display, window, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, window, blankCursor, CurrentTime); cursorVisible = true; glXMakeCurrent(display, window, ctx); //printf((char *) glXGetClientString(display, GLX_EXTENSIONS)); initExtensions(display, screen); // Set some of my preferred defaults glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glFrontFace(GL_CW); if (/*GLX_ARB_multisample_supported && */pf.fsaaLevel > 0){ glEnable(GL_MULTISAMPLE_ARB); } renderer = new OpenGLRenderer(ctx, display, screen); // renderer->setAnisotropic(anisotropic); return true; }