bool Gif::save(const char* filepath) { if(!frames.size()) { return false; } if(!palette_created) { createPalette(frames[0]->pixels); } FILE* fp; fp = fopen(filepath,"wb"); GIFEncodeHeader(fp, 1, width, height, 0, 8,(unsigned char*)palette[0].x); GIFEncodeCommentExt(fp,(char*) "Roxlu lib"); // write frames. Dither dither; int disposal = DISPOSE_COMBINE; //typedef enum GIFDisposeType {DISPOSE_UNSPECIFIED, DISPOSE_COMBINE, DISPOSE_REPLACE } GIFDisposeType; vector<GifFrame*>::iterator it = frames.begin(); while(it != frames.end()) { GifFrame& f = *(*it); dither.dither(width, height, f.pixels, f.data, palette); GIFEncodeGraphicControlExt(fp, (GIFDisposeType)disposal,f.delay, (f.delay) > 0 ? 1 : 0,-1); GIFEncodeImageData (fp, width, height, 8, 0, 0, f.data); ++it; } GIFEncodeLoopExt(fp, num_loops); GIFEncodeClose(fp); fclose(fp); return true; }
bool GdiPrintContext::createOffScreen() { if (NULL == printDC_) return false; // create an off-screen DC for double-buffering memDC_ = CreateCompatibleDC(printDC_); if (NULL == memDC_) return false; // isPaletteUsed_ = (GetDeviceCaps(memDC_, RASTERCAPS) & RC_PALETTE) == RC_PALETTE; assert(false == isPaletteUsed_); // caution: in case of monochrone printer, the number of color bits is 1 //const int colorBitCount = GetDeviceCaps(memDC_, BITSPIXEL); const int colorBitCount = GetDeviceCaps(memDC_, BITSPIXEL) <= 8 ? 32 : GetDeviceCaps(memDC_, BITSPIXEL); assert(colorBitCount > 8); const int colorPlaneCount = GetDeviceCaps(memDC_, PLANES); assert(1 == colorPlaneCount); // use palette: when using 256 color if (isPaletteUsed_) createPalette(memDC_, colorBitCount); if (createOffScreenBitmap(colorBitCount, colorPlaneCount)) return true; else { DeleteDC(memDC_); memDC_ = NULL; return false; } }
//**************************************** int main(int argc, char** argv){ glutInit(&argc, argv); createPalette(); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GLsizei windowX = (glutGet(GLUT_SCREEN_WIDTH)-width)/2; GLsizei windowY = (glutGet(GLUT_SCREEN_HEIGHT)-height)/2; glutInitWindowPosition(windowX, windowY); glutInitWindowSize(width, height); windowID = glutCreateWindow("Matrix Fractal Zoomer"); glViewport (0, 0, (GLsizei) width, (GLsizei) height); glMatrixMode (GL_PROJECTION); glLoadIdentity(); glOrtho(minX, maxX, minY, maxY, ((GLfloat)-1), (GLfloat)1); // set the event handling methods glutDisplayFunc(repaint); glutReshapeFunc(reshape); glutKeyboardFunc(keyFunction); glutSpecialFunc(specialKeyFunction); glutMouseFunc(mouseFunction); glutMainLoop(); return 0; }
bool PaletteIO::read(Palettes &palettes) const { if(!canRead()) { return false; } QByteArray palData = device()->read(12); if(palData.size() != 12) { qWarning() << "PaletteIO::read Pal size too short"; return false; } quint16 palH; memcpy(&palH, palData.constData() + 10, 2); palData = device()->read(palH * 512); if(palData.size() != palH * 512) { qWarning() << "PaletteIO::read Pal size too short 2"; return false; } for(quint32 i=0 ; i<palH ; ++i) { palettes.append(createPalette(palData.constData() + i*512)); } return readAfter(palettes); }
SurfaceSDL::SurfaceSDL(SDL_Surface* surface) : surface_(surface) { ASSERT_LOG(surface_ != nullptr, "Error creating surface: " << SDL_GetError()); auto pf = std::make_shared<SDLPixelFormat>(surface_->format->format); setPixelFormat(PixelFormatPtr(pf)); createPalette(); }
int main(int argc,char **argv){ int nproc; int rank; MPI_Status status; int err; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&nproc); MPI_Comm_rank(MPI_COMM_WORLD,&rank); printf("%d\n",nproc); if(nproc!=7){ printf("7 processes needed\n"); MPI_Abort(MPI_COMM_WORLD,err); } if(rank==0){ int i; int windowID; for(i=1;i<nproc;i++){ MPI_Recv(image[(i-1)*100],100*600,MPI_INT,i,0,MPI_COMM_WORLD,&status); printf("received message from proc %d\n",i); } glutInit(&argc,argv); createPalette(); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //居中放置 GLsizei windowX = (glutGet(GLUT_SCREEN_WIDTH)-width)/2; GLsizei windowY = (glutGet(GLUT_SCREEN_HEIGHT)-height)/2; glutInitWindowPosition(windowX, windowY); glutInitWindowSize(width, height); windowID = glutCreateWindow("FRAKTALE"); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glViewport (0, 0, (GLsizei) width, (GLsizei) height); glMatrixMode (GL_PROJECTION); glLoadIdentity(); //glOrtho(minX, maxX, minY, maxY, ((GLfloat)-1), (GLfloat)1); glOrtho(0, 600, 0, 600, ((GLfloat)-1), (GLfloat)1); glutDisplayFunc(repaint); glutMainLoop(); }else{ int limage[100][600]; int i,j; int k; for(j=0;j<100;j++){ k=(rank-1)*100+j; for(i=0;i<600;i++){ GLfloat x=minX+i*stepX; GLfloat y=minY+k*stepY; limage[j][i]=caldepth(x,y); } } MPI_Send(limage,100*600,MPI_INT,0,0,MPI_COMM_WORLD); } MPI_Finalize(); }
void StyleHelper::apply() { Preferences *preferences = Preferences::instance(); QString desiredStyle; QPalette desiredPalette; switch (preferences->applicationStyle()) { default: case Preferences::SystemDefaultStyle: desiredStyle = defaultStyle(); desiredPalette = defaultPalette(); break; case Preferences::FusionStyle: desiredStyle = QLatin1String("fusion"); desiredPalette = createPalette(preferences->baseColor(), preferences->selectionColor()); break; case Preferences::TiledStyle: desiredStyle = QLatin1String("tiled"); desiredPalette = createPalette(preferences->baseColor(), preferences->selectionColor()); break; } if (QApplication::style()->objectName() != desiredStyle) { QStyle *style; if (desiredStyle == QLatin1String("tiled")) { style = QStyleFactory::create(QLatin1String("fusion")); style = new TiledProxyStyle(style); } else { style = QStyleFactory::create(desiredStyle); } QApplication::setStyle(style); } if (QApplication::palette() != desiredPalette) QApplication::setPalette(desiredPalette); emit styleApplied(); }
SurfaceSDL::SurfaceSDL(int width, int height, PixelFormat::PF format) { int bpp; uint32_t rmask, gmask, bmask, amask; SDL_bool ret = SDL_PixelFormatEnumToMasks(get_sdl_pixel_format(format), &bpp, &rmask, &gmask, &bmask, &amask); ASSERT_LOG(ret != SDL_FALSE, "Unable to convert pixel format to masks: " << SDL_GetError()); surface_ = SDL_CreateRGBSurface(0, width, height, bpp, rmask, gmask, bmask, amask); ASSERT_LOG(surface_ != nullptr, "Error creating surface: " << SDL_GetError()); auto pf = std::make_shared<SDLPixelFormat>(surface_->format->format); setPixelFormat(PixelFormatPtr(pf)); createPalette(); }
int main(int argc, char * argv[]) { createPalette(); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE); glutInitWindowSize(sirina, visina); glutInitWindowPosition(200, 200); glutCreateWindow("Vjezba 8"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMouseFunc(mousePressedOrReleased); glutPassiveMotionFunc(mouseMoved); glutKeyboardFunc(keyPressed); glutMainLoop(); return 0; }
bool App::launch() { if (osc_recv_port_ == 0) if (verbose_) std::cout << "OSC receiving disabled." << std::endl; else startOSC(); // Poll OSC receiver only when we render a Clutter frame. if (stage_) { std::cerr << "cannot create stage twice" << std::endl; //return false; } stage_ = clutter_stage_get_default(); clutter_actor_set_size(stage_, 1024, 768); ClutterColor black = { 0x00, 0x00, 0x00, 0xff }; clutter_stage_set_color(CLUTTER_STAGE(stage_), &black); g_signal_connect(stage_, "destroy", G_CALLBACK(clutter_main_quit), NULL); clutter_actor_set_reactive(stage_, TRUE); // timeline to attach a callback for each frame that is rendered ClutterTimeline *timeline; timeline = clutter_timeline_new(60); // ms clutter_timeline_set_loop(timeline, TRUE); clutter_timeline_start(timeline); g_signal_connect(timeline, "new-frame", G_CALLBACK(on_frame_cb), this); g_signal_connect(stage_, "key-press-event", G_CALLBACK(key_event_cb), this); g_signal_connect(stage_, "button-press-event", G_CALLBACK(button_press_cb), this); g_signal_connect(stage_, "button-release-event", G_CALLBACK(button_released_cb), this); g_signal_connect(stage_, "motion-event", G_CALLBACK(motion_event_cb), this); if (fullscreen_) { fullscreen_ = false; toggleFullscreen(); } createPalette(); clutter_actor_show(stage_); return true; }
void Gif::addFrame(unsigned char* pixels, int delay, bool useForPalette) { if(!is_setup) { return; } // add a new frame to the queue. GifFrame* frame = new GifFrame(); frame->pixels = new unsigned char[width*height*3]; frame->data = new unsigned char[width*height]; memcpy(frame->pixels, pixels, width*height*3 * sizeof(unsigned char)); frame->delay = delay; // create palette when not yet created and when asked to do. if(useForPalette) { createPalette(pixels); } printf("Frames: %zu\n", frames.size()); frames.push_back(frame); }
bool GdiBitmapBufferedContext::createOffScreen() { if (NULL == hWnd_) return false; // get DC for window hDC_ = GetDC(hWnd_); if (NULL == hDC_) return false; // create an off-screen DC for double-buffering memDC_ = CreateCompatibleDC(hDC_); if (NULL == memDC_) { ReleaseDC(hWnd_, hDC_); hDC_ = NULL; return false; } // isPaletteUsed_ = (GetDeviceCaps(memDC_, RASTERCAPS) & RC_PALETTE) == RC_PALETTE; assert(false == isPaletteUsed_); const int colorBitCount = GetDeviceCaps(memDC_, BITSPIXEL); assert(colorBitCount > 8); const int colorPlaneCount = GetDeviceCaps(memDC_, PLANES); assert(1 == colorPlaneCount); // use palette: when using 256 color if (isPaletteUsed_) createPalette(memDC_, colorBitCount); if (createOffScreenBitmap(colorBitCount, colorPlaneCount)) return true; else { DeleteDC(memDC_); memDC_ = NULL; ReleaseDC(hWnd_, hDC_); hDC_ = NULL; return false; } }
geBitmap_Palette * createPaletteFromBitmap(const geBitmap * Bitmap,geBoolean Optimize) { geBitmap * Lock; geBitmap_Info Info; const void * Bits; geBitmap_Palette * Pal; if ( ! geBitmap_GetInfo(Bitmap,&Info,NULL) ) return NULL; if ( ! geBitmap_LockForRead((geBitmap *)Bitmap,&Lock,0,0,GE_PIXELFORMAT_24BIT_RGB,GE_FALSE,0) ) return NULL; if ( ! geBitmap_GetInfo(Lock,&Info,NULL) ) return NULL; Bits = (const void *) geBitmap_GetBits(Lock); Pal = createPalette(&Info,Bits); if ( Pal && Optimize ) { uint8 paldata[768]; if ( ! geBitmap_Palette_GetData(Pal,paldata,GE_PIXELFORMAT_24BIT_RGB,256) ) assert(0); paletteOptimize(&Info,Bits,paldata,256,0); if ( ! geBitmap_Palette_SetData(Pal,paldata,GE_PIXELFORMAT_24BIT_RGB,256) ) assert(0); } geBitmap_UnLock(Lock); return Pal; }
KstColorSequence::KstColorSequence() : _ptr(0), _mode(Color) { _pal = 0L; createPalette(); }
bool QKindleFb::connect(const QString &displaySpec) { d_ptr->displaySpec = displaySpec; const QStringList args = displaySpec.split(QLatin1Char(':')); d_ptr->doGraphicsMode = false; if (args.contains(QLatin1String("flashing"))) flashingUpdates = true ; else flashingUpdates = false ; if (args.contains(QLatin1String("debug"))) debugMode = true ; else debugMode = false ; if (args.contains(QLatin1String("cursor"))) hasCursor = true ; else hasCursor = false ; fullUpdateEvery = 1; const QStringList updateArg = args.filter(QLatin1String("update=")); if (updateArg.length() == 1) { fullUpdateEvery = updateArg.at(0).section(QLatin1Char('='), 1, 1).toInt(); } d_ptr->ttyDevice = EINK_FRAME_BUFFER ; QString dev = QLatin1String(EINK_FRAME_BUFFER); QString dev_alt = QLatin1String(EINK_FRAME_BUFFER_ALT_NAME); d_ptr->fd = open(dev.toLatin1().constData(), O_RDWR); /* try alt frame buffer name */ if (d_ptr->fd == -1) d_ptr->fd = open(dev_alt.toLatin1().constData(), O_RDWR); if (d_ptr->fd == -1) { if (QApplication::type() == QApplication::GuiServer) { perror("QKindleFb::connect"); qCritical("Error opening framebuffer device %s(%s)", qPrintable(dev), qPrintable(dev_alt)); return false; } } ::fb_fix_screeninfo finfo; ::fb_var_screeninfo vinfo; //####################### memset(&vinfo, 0, sizeof(vinfo)); memset(&finfo, 0, sizeof(finfo)); //####################### /* Get fixed screen information */ if (d_ptr->fd != -1 && ioctl(d_ptr->fd, FBIOGET_FSCREENINFO, &finfo)) { perror("QKindleFb::connect"); qWarning("Error reading fixed information"); return false; } d_ptr->driverType = strcmp(finfo.id, "eink_fb") ? GenericDriver : KindleEink ; /* Get variable screen information */ if (d_ptr->fd != -1 && ioctl(d_ptr->fd, FBIOGET_VSCREENINFO, &vinfo)) { perror("QKindleFb::connect"); qWarning("Error reading variable information"); return false; } #ifdef DEBUG_VINFO show_info(&finfo, &vinfo) ; #endif grayscale = vinfo.grayscale; d = vinfo.bits_per_pixel; lstep = finfo.line_length; int xoff = vinfo.xoffset; int yoff = vinfo.yoffset; const char* qwssize; if((qwssize=::getenv("QWS_SIZE")) && sscanf(qwssize,"%dx%d",&w,&h)==2) { if (d_ptr->fd != -1) { if ((uint)w > vinfo.xres) w = vinfo.xres; if ((uint)h > vinfo.yres) h = vinfo.yres; } dw=w; dh=h; int xxoff, yyoff; if (sscanf(qwssize, "%*dx%*d+%d+%d", &xxoff, &yyoff) == 2) { if (xxoff < 0 || xxoff + w > (int)vinfo.xres) xxoff = vinfo.xres - w; if (yyoff < 0 || yyoff + h > (int)vinfo.yres) yyoff = vinfo.yres - h; xoff += xxoff; yoff += yyoff; } else { xoff += (vinfo.xres - w)/2; yoff += (vinfo.yres - h)/2; } } else { dw=w=vinfo.xres; dh=h=vinfo.yres; if (debugMode) { qDebug(".. dw=%d, dh=%d, lstep=%d", dw, dh, lstep) ; } } if (w == 0 || h == 0) { qWarning("QKindleFb::connect(): Unable to find screen geometry, " "will use detected device values."); dw = w = Device::getWidth(); dh = h = Device::getHeight(); } // Handle display physical size spec. if (vinfo.width != 0 && vinfo.height != 0 && vinfo.width != UINT_MAX && vinfo.height != UINT_MAX) { physWidth = vinfo.width; physHeight = vinfo.height; } else { // the controller didn't report screen physical // dimensions. Set them manually: double dpi = Device::getDpi(); double mmperinch = 25.4 ; physWidth = qRound(dw*mmperinch/dpi) ; physHeight = qRound(dh*mmperinch/dpi) ; } if (debugMode) qDebug("physW=%d, physH=%d", physWidth, physHeight) ; dataoffset = yoff * lstep + xoff * d / 8; /* Figure out the size of the screen in bytes */ size = h * lstep; mapsize = finfo.smem_len; data = (unsigned char *)-1; if (d_ptr->fd != -1) data = (unsigned char *)mmap(0, mapsize, PROT_READ | PROT_WRITE, MAP_SHARED , d_ptr->fd, 0); if ((long)data == -1) { if (QApplication::type() == QApplication::GuiServer) { perror("QKindleFb::connect"); qWarning("Error: failed to map framebuffer device to memory."); return false; } data = 0; } else { data += dataoffset; } canaccel = false ; // Now read in palette if((vinfo.bits_per_pixel==8) || (vinfo.bits_per_pixel==4)) { screencols= (vinfo.bits_per_pixel==8) ? 256 : 16; // force screen colors to be 16 if it is K4 if (isKindle4 || isKindle5) { screencols = 16 ; } int loopc; ::fb_cmap startcmap; startcmap.start=0; startcmap.len=screencols; startcmap.red=(unsigned short int *) malloc(sizeof(unsigned short int)*screencols); startcmap.green=(unsigned short int *) malloc(sizeof(unsigned short int)*screencols); startcmap.blue=(unsigned short int *) malloc(sizeof(unsigned short int)*screencols); startcmap.transp=(unsigned short int *) malloc(sizeof(unsigned short int)*screencols); createPalette(startcmap, vinfo, finfo); int bits_used = 0; for(loopc=0;loopc<screencols;loopc++) { screenclut[loopc]=qRgb(startcmap.red[loopc] >> 8, startcmap.green[loopc] >> 8, startcmap.blue[loopc] >> 8); bits_used |= startcmap.red[loopc] | startcmap.green[loopc] | startcmap.blue[loopc]; } // WORKAROUND: Some framebuffer drivers only return 8 bit // color values, so we need to not bit shift them.. if ((bits_used & 0x00ff) && !(bits_used & 0xff00)) { for(loopc=0;loopc<screencols;loopc++) { screenclut[loopc] = qRgb(startcmap.red[loopc], startcmap.green[loopc], startcmap.blue[loopc]); } qWarning("8 bits cmap returned due to faulty FB driver, colors corrected"); } free(startcmap.red); free(startcmap.green); free(startcmap.blue); free(startcmap.transp); } else {
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow) { HWND hWnd; MSG msg; WNDCLASS wndClass; wndClass.style=CS_HREDRAW|CS_VREDRAW; wndClass.lpfnWndProc=WndProc; wndClass.cbClsExtra=0; wndClass.cbWndExtra=0; wndClass.hInstance=hInstance; wndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION); wndClass.hCursor=LoadCursor(NULL,IDC_ARROW); wndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); wndClass.lpszMenuName=NULL; wndClass.lpszClassName=szName; if(!RegisterClass(&wndClass)) { MessageBox(NULL,TEXT("Can not create!"),szName,MB_ICONERROR); return 0; } hWnd=CreateWindow(szName,TEXT("Soft Render"),WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT,SCREEN_WIDTH,SCREEN_HEIGHT, NULL,NULL,hInstance,NULL); hdc=GetDC(hWnd); checkDisplayMode(hdc); createPalette(hdc); dibDC=CreateCompatibleDC(hdc); swidth=SCREEN_WIDTH; sheight=SCREEN_HEIGHT; init(); ShowWindow(hWnd,iCmdShow); UpdateWindow(hWnd); willExit=false; memset(&msg,0,sizeof(MSG)); if(hPalette) { SelectPalette(hdc,hPalette,FALSE); RealizePalette(hdc); } while(!willExit) { if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if(msg.message==WM_QUIT) willExit=true; else { TranslateMessage(&msg); DispatchMessage(&msg); } } else { runWindow(); draw(); BitBlt(hdc,0,0,swidth,sheight,dibDC,0,0,SRCCOPY); } } releasePalette(); releaseDIB(dibDC); DeleteDC(dibDC); ReleaseDC(hWnd,hdc); killWindow(hWnd,hInstance,wndClass); return msg.wParam; }
///////////////////////////////////////////////////////////////////////////// // init ///////////////////////////////////////////////////////////////////////////// bool Vigasoco::init(std::string name) { // calls template method to perform platform specific initialization if (!platformSpecificInit()){ _errorMsg = "platformSpecificInit() failed"; return false; } // creates the game driver _driver = createGameDriver(name); if (!_driver){ _errorMsg = "unknown game " + name; return false; } // calls template method to create the palette createPalette(); if (!_palette){ _errorMsg = "createPalette() failed"; return false; } // inits the palette (the last 2 colors are used by the core to display information) int numColors = _driver->getVideoInfo()->colors; // TODO: VGA // Cambiar para no poner 256 a fuego _palette->init(256); // pruebas VGA // init the colors used by the core to display information /* _palette->setColor(numColors + 0, 0x00, 0x00, 0x00); _palette->setColor(numColors + 1, 0xff, 0xff, 0xff); */ // TODO: VGA6, mientras probamos con VGA, metemos esto a fuego en el color 253 y 254 _palette->setColor(253, 0x00, 0x00, 0x00); _palette->setColor(254, 0xff, 0xff, 0xff); // inits the fonts used by the core _fontManager = new FontManager(_palette, numColors/2); _fontManager->init(); // creates the FileLoader FileLoader *fl = new FileLoader(); // calls template method to add custom loaders addCustomLoaders(fl); // inits the game driver (load files, decode gfx, preprocessing, etc) if (!_driver->init(_palette)){ // calls template method to remove custom loaders removeCustomLoaders(fl); delete fl; _errorMsg = "driver->init() failed\n" + _driver->getError(); return false; } // calls template method to remove custom loaders removeCustomLoaders(fl); // deletes the FileLoader delete fl; // calls template method to get a DrawPlugin createDrawPlugin(); if (!_drawPlugin){ _errorMsg = "createDrawPlugin() failed"; return false; } // inits the DrawPlugin with the selected GameDriver if (!_drawPlugin->init(_driver->getVideoInfo(), _palette)){ _errorMsg = "drawPlugin->init() failed"; return false; } // notify the driver that the drawPlugin has been initialized _driver->videoInitialized(_drawPlugin); // creates the input handler _inputHandler = new InputHandler(); // calls template method to add input plugins addCustomInputPlugins(); // inits the input handler if (!_inputHandler->init(_driver)){ _errorMsg = "inputHandler->init() failed"; return false; } // calls template method to get a high resolution timer createTimer(); // creates the timing handler _timingHandler = new TimingHandler(); // inits the timing handler if (!_timingHandler->init(_timer, _driver->getNumInterruptsPerSecond(), _driver->getNumInterruptsPerVideoUpdate(), _driver->getnumInterruptsPerLogicUpdate())){ _errorMsg = "timerHandler->init() failed"; return false; } // calls template method to get a AudioPlugin createAudioPlugin(); if (!_audioPlugin){ _errorMsg = "createAudioPlugin() failed"; return false; } // inits the AudioPlugin with the selected GameDriver if (!_audioPlugin->init(/* TODO: _driver->getAudioInfo() */)){ _errorMsg = "audioPlugin->init() failed"; return false; } // notify the driver that the drawPlugin has been initialized _driver->audioInitialized(_audioPlugin); // creates the async thread createAsyncThread(); if (!_asyncThread){ _errorMsg = "createAsyncThread() failed"; return false; } // calls template method to perform specific actions after initialization has been completed initCompleted(); return true; }
bool init(osgAnimation::RigGeometry& geom) { osg::Vec3Array* pos = dynamic_cast<osg::Vec3Array*>(geom.getVertexArray()); if (!pos) { osg::notify(osg::WARN) << "RigTransformHardware no vertex array in the geometry " << geom.getName() << std::endl; return false; } if (!geom.getSkeleton()) { osg::notify(osg::WARN) << "RigTransformHardware no skeleting set in geometry " << geom.getName() << std::endl; return false; } osgAnimation::BoneMapVisitor mapVisitor; geom.getSkeleton()->accept(mapVisitor); osgAnimation::BoneMap bm = mapVisitor.getBoneMap(); if (!createPalette(pos->size(),bm, geom.getVertexInfluenceSet().getVertexToBoneList())) return false; int attribIndex = 11; int nbAttribs = getNumVertexAttrib(); // use a global program for all avatar if (!program.valid()) { program = new osg::Program; program->setName("HardwareSkinning"); if (!_shader.valid()) _shader = osg::Shader::readShaderFile(osg::Shader::VERTEX,"shaders/skinning.vert"); if (!_shader.valid()) { osg::notify(osg::WARN) << "RigTransformHardware can't load VertexShader" << std::endl; return false; } // replace max matrix by the value from uniform { std::string str = _shader->getShaderSource(); std::string toreplace = std::string("MAX_MATRIX"); std::size_t start = str.find(toreplace); std::stringstream ss; ss << getMatrixPaletteUniform()->getNumElements(); str.replace(start, toreplace.size(), ss.str()); _shader->setShaderSource(str); osg::notify(osg::INFO) << "Shader " << str << std::endl; } program->addShader(_shader.get()); for (int i = 0; i < nbAttribs; i++) { std::stringstream ss; ss << "boneWeight" << i; program->addBindAttribLocation(ss.str(), attribIndex + i); osg::notify(osg::INFO) << "set vertex attrib " << ss.str() << std::endl; } } for (int i = 0; i < nbAttribs; i++) { std::stringstream ss; ss << "boneWeight" << i; geom.setVertexAttribArray(attribIndex + i, getVertexAttrib(i)); } osg::ref_ptr<osg::StateSet> ss = new osg::StateSet; ss->addUniform(getMatrixPaletteUniform()); ss->addUniform(new osg::Uniform("nbBonesPerVertex", getNumBonesPerVertex())); ss->setAttributeAndModes(program.get()); geom.setStateSet(ss.get()); _needInit = false; return true; }
bool WglBitmapBufferedContext::createOffScreen() { if (NULL == hWnd_) return false; // get DC for window hDC_ = GetDC(hWnd_); if (NULL == hDC_) return false; // create an off-screen DC for double-buffering memDC_ = CreateCompatibleDC(hDC_); if (NULL == memDC_) { ReleaseDC(hWnd_, hDC_); hDC_ = NULL; return false; } // isPaletteUsed_ = (GetDeviceCaps(memDC_, RASTERCAPS) & RC_PALETTE) == RC_PALETTE; assert(false == isPaletteUsed_); // without this line, wglCreateContext will fail wglMakeCurrent(memDC_, 0); const int colorBitCount = GetDeviceCaps(memDC_, BITSPIXEL); assert(colorBitCount > 8); const int colorPlaneCount = GetDeviceCaps(memDC_, PLANES); assert(1 == colorPlaneCount); // create OpenGL pixel format descriptor PIXELFORMATDESCRIPTOR pfd; // clear OpenGL pixel format descriptor memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; pfd.iPixelType = PFD_TYPE_RGBA; pfd.iLayerType = PFD_MAIN_PLANE; // offscreen was requested pfd.dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI | PFD_STEREO_DONTCARE; pfd.cColorBits = colorBitCount; pfd.cRedBits = 8; pfd.cRedShift = 16; pfd.cGreenBits = 8; pfd.cGreenShift = 8; pfd.cBlueBits = 8; pfd.cBlueShift = 0; pfd.cAlphaBits = 0; pfd.cAlphaShift = 0; //pfd.cAccumBits = 64; // consider more flexible configuration //pfd.cAccumRedBits = 16; //pfd.cAccumGreenBits = 16; //pfd.cAccumBlueBits = 16; //pfd.cAccumAlphaBits = 0; pfd.cDepthBits = 32; pfd.cStencilBits = 16; pfd.cAuxBuffers = 0; pfd.bReserved = 0; pfd.dwLayerMask = 0; pfd.dwVisibleMask = 0; pfd.dwDamageMask = 0; // use palette: when using 256 color if (isPaletteUsed_) createPalette(memDC_, pfd, colorBitCount); // if (!createOffScreenBitmap(colorBitCount, colorPlaneCount)) { DeleteObject(memBmp_); memBmp_ = NULL; DeleteDC(memDC_); memDC_ = NULL; ReleaseDC(hWnd_, hDC_); hDC_ = NULL; return false; } // caution: // 1. OpenGL에서 PFD_DRAW_TO_BITMAP flag을 사용하여 bitmap에 drawing할 경우 // pixel format을 설정하기 전에 OpenGL RC와 연결된 DC에 bitmap이 선택되어져 있어야 한다. // 2. off-screen을 위한 bitmap은 CreateCompatibleBitmap()이 아닌 CreateDIBSection()으로 생성하여야 한다. // 그렇지 않을 경우, SetPixelFormat() 실행시 error가 발생한다. // choose pixel format int nPixelFormat = ChoosePixelFormat(memDC_, &pfd); if (0 == nPixelFormat) // choose default { nPixelFormat = 1; if (DescribePixelFormat(memDC_, nPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd) == 0) { deleteOffScreen(); return false; } } if (FALSE == SetPixelFormat(memDC_, nPixelFormat, &pfd)) { deleteOffScreen(); return false; } // create rendering context wglRC_ = wglCreateContext(memDC_); if (NULL == wglRC_) { deleteOffScreen(); return false; } return true; }
bool QLinuxFbScreen::connect(const QString &displaySpec) { d_ptr->displaySpec = displaySpec; const QStringList args = displaySpec.split(QLatin1Char(':')); if (args.contains(QLatin1String("nographicsmodeswitch"))) d_ptr->doGraphicsMode = false; #ifdef QT_QWS_DEPTH_GENERIC if (args.contains(QLatin1String("genericcolors"))) d_ptr->doGenericColors = true; #endif QRegExp ttyRegExp(QLatin1String("tty=(.*)")); if (args.indexOf(ttyRegExp) != -1) d_ptr->ttyDevice = ttyRegExp.cap(1); #if Q_BYTE_ORDER == Q_BIG_ENDIAN #ifndef QT_QWS_FRAMEBUFFER_LITTLE_ENDIAN if (args.contains(QLatin1String("littleendian"))) #endif QScreen::setFrameBufferLittleEndian(true); #endif QString dev = QLatin1String("/dev/fb0"); foreach(QString d, args) { if (d.startsWith(QLatin1Char('/'))) { dev = d; break; } } if (access(dev.toLatin1().constData(), R_OK|W_OK) == 0) d_ptr->fd = QT_OPEN(dev.toLatin1().constData(), O_RDWR); if (d_ptr->fd == -1) { if (QApplication::type() == QApplication::GuiServer) { perror("QScreenLinuxFb::connect"); qCritical("Error opening framebuffer device %s", qPrintable(dev)); return false; } if (access(dev.toLatin1().constData(), R_OK) == 0) d_ptr->fd = QT_OPEN(dev.toLatin1().constData(), O_RDONLY); } ::fb_fix_screeninfo finfo; ::fb_var_screeninfo vinfo; //####################### // Shut up Valgrind memset(&vinfo, 0, sizeof(vinfo)); memset(&finfo, 0, sizeof(finfo)); //####################### /* Get fixed screen information */ if (d_ptr->fd != -1 && ioctl(d_ptr->fd, FBIOGET_FSCREENINFO, &finfo)) { perror("QLinuxFbScreen::connect"); qWarning("Error reading fixed information"); return false; } d_ptr->driverType = strcmp(finfo.id, "8TRACKFB") ? GenericDriver : EInk8Track; if (finfo.type == FB_TYPE_VGA_PLANES) { qWarning("VGA16 video mode not supported"); return false; } /* Get variable screen information */ if (d_ptr->fd != -1 && ioctl(d_ptr->fd, FBIOGET_VSCREENINFO, &vinfo)) { perror("QLinuxFbScreen::connect"); qWarning("Error reading variable information"); return false; } fixupScreenInfo(finfo, vinfo); grayscale = vinfo.grayscale; d = vinfo.bits_per_pixel; if (d == 24) { d = vinfo.red.length + vinfo.green.length + vinfo.blue.length; if (d <= 0) d = 24; // reset if color component lengths are not reported } else if (d == 16) { d = vinfo.red.length + vinfo.green.length + vinfo.blue.length; if (d <= 0) d = 16; } lstep = finfo.line_length; int xoff = vinfo.xoffset; int yoff = vinfo.yoffset; const char* qwssize; if((qwssize=::getenv("QWS_SIZE")) && sscanf(qwssize,"%dx%d",&w,&h)==2) { if (d_ptr->fd != -1) { if ((uint)w > vinfo.xres) w = vinfo.xres; if ((uint)h > vinfo.yres) h = vinfo.yres; } dw=w; dh=h; int xxoff, yyoff; if (sscanf(qwssize, "%*dx%*d+%d+%d", &xxoff, &yyoff) == 2) { if (xxoff < 0 || xxoff + w > vinfo.xres) xxoff = vinfo.xres - w; if (yyoff < 0 || yyoff + h > vinfo.yres) yyoff = vinfo.yres - h; xoff += xxoff; yoff += yyoff; } else { xoff += (vinfo.xres - w)/2; yoff += (vinfo.yres - h)/2; } } else { dw=w=vinfo.xres; dh=h=vinfo.yres; } if (w == 0 || h == 0) { qWarning("QScreenLinuxFb::connect(): Unable to find screen geometry, " "will use 320x240."); dw = w = 320; dh = h = 240; } setPixelFormat(vinfo); // Handle display physical size spec. QStringList displayArgs = displaySpec.split(QLatin1Char(':')); QRegExp mmWidthRx(QLatin1String("mmWidth=?(\\d+)")); int dimIdxW = displayArgs.indexOf(mmWidthRx); QRegExp mmHeightRx(QLatin1String("mmHeight=?(\\d+)")); int dimIdxH = displayArgs.indexOf(mmHeightRx); if (dimIdxW >= 0) { mmWidthRx.exactMatch(displayArgs.at(dimIdxW)); physWidth = mmWidthRx.cap(1).toInt(); if (dimIdxH < 0) physHeight = dh*physWidth/dw; } if (dimIdxH >= 0) { mmHeightRx.exactMatch(displayArgs.at(dimIdxH)); physHeight = mmHeightRx.cap(1).toInt(); if (dimIdxW < 0) physWidth = dw*physHeight/dh; } if (dimIdxW < 0 && dimIdxH < 0) { if (vinfo.width != 0 && vinfo.height != 0 && vinfo.width != UINT_MAX && vinfo.height != UINT_MAX) { physWidth = vinfo.width; physHeight = vinfo.height; } else { const int dpi = 72; physWidth = qRound(dw * 25.4 / dpi); physHeight = qRound(dh * 25.4 / dpi); } } dataoffset = yoff * lstep + xoff * d / 8; //qDebug("Using %dx%dx%d screen",w,h,d); /* Figure out the size of the screen in bytes */ size = h * lstep; mapsize = finfo.smem_len; data = (unsigned char *)-1; if (d_ptr->fd != -1) data = (unsigned char *)mmap(0, mapsize, PROT_READ | PROT_WRITE, MAP_SHARED, d_ptr->fd, 0); if ((long)data == -1) { if (QApplication::type() == QApplication::GuiServer) { perror("QLinuxFbScreen::connect"); qWarning("Error: failed to map framebuffer device to memory."); return false; } data = 0; } else { data += dataoffset; } canaccel = useOffscreen(); if(canaccel) setupOffScreen(); // Now read in palette if((vinfo.bits_per_pixel==8) || (vinfo.bits_per_pixel==4)) { screencols= (vinfo.bits_per_pixel==8) ? 256 : 16; int loopc; ::fb_cmap startcmap; startcmap.start=0; startcmap.len=screencols; startcmap.red=(unsigned short int *) malloc(sizeof(unsigned short int)*screencols); startcmap.green=(unsigned short int *) malloc(sizeof(unsigned short int)*screencols); startcmap.blue=(unsigned short int *) malloc(sizeof(unsigned short int)*screencols); startcmap.transp=(unsigned short int *) malloc(sizeof(unsigned short int)*screencols); if (d_ptr->fd == -1 || ioctl(d_ptr->fd, FBIOGETCMAP, &startcmap)) { perror("QLinuxFbScreen::connect"); qWarning("Error reading palette from framebuffer, using default palette"); createPalette(startcmap, vinfo, finfo); } int bits_used = 0; for(loopc=0;loopc<screencols;loopc++) { screenclut[loopc]=qRgb(startcmap.red[loopc] >> 8, startcmap.green[loopc] >> 8, startcmap.blue[loopc] >> 8); bits_used |= startcmap.red[loopc] | startcmap.green[loopc] | startcmap.blue[loopc]; } // WORKAROUND: Some framebuffer drivers only return 8 bit // color values, so we need to not bit shift them.. if ((bits_used & 0x00ff) && !(bits_used & 0xff00)) { for(loopc=0;loopc<screencols;loopc++) { screenclut[loopc] = qRgb(startcmap.red[loopc], startcmap.green[loopc], startcmap.blue[loopc]); } qWarning("8 bits cmap returned due to faulty FB driver, colors corrected"); } free(startcmap.red); free(startcmap.green); free(startcmap.blue); free(startcmap.transp); } else {