comparison Renderer/Engine/viewerSDL.cc @ 994:33616b2789de

SDL mode fix
author yutaka@charles.cr.ie.u-ryukyu.ac.jp
date Mon, 11 Oct 2010 14:21:02 +0900
parents 8024a3a44832
children 78ebcdaae8bc
comparison
equal deleted inserted replaced
993:8024a3a44832 994:33616b2789de
17 #define DIV_BYTE 8 17 #define DIV_BYTE 8
18 18
19 Uint32 * 19 Uint32 *
20 ViewerSDL::video_init(TaskManager *manager, int bpp, int width, int height) 20 ViewerSDL::video_init(TaskManager *manager, int bpp, int width, int height)
21 { 21 {
22 22
23 int fd_framebuffer ; 23 int fd_framebuffer ;
24 struct fb_var_screeninfo vinfo; 24 struct fb_var_screeninfo vinfo;
25 struct fb_fix_screeninfo finfo; 25 struct fb_fix_screeninfo finfo;
26 26
27 int xres,yres,vbpp; 27 int xres,yres,vbpp;
28 28
29 /* 読み書き用にファイルを開く */ 29 // 読み書き用にファイルを開く
30 fd_framebuffer = open( DEVICE_NAME , O_RDWR); 30 fd_framebuffer = open( DEVICE_NAME , O_RDWR);
31 if ( !fd_framebuffer ) { 31 if ( !fd_framebuffer ) {
32 send_current_error_msg("Framebuffer device open error !"); 32 send_current_error_msg("Framebuffer device open error !");
33 exit(1); 33 exit(1);
34 } 34 }
35 send_current_information("The framebuffer device was opened !"); 35 send_current_information("The framebuffer device was opened !");
36 36
37 /* 固定スクリーン情報取得 */ 37 // 固定スクリーン情報取得
38 if ( ioctl( fd_framebuffer , FBIOGET_FSCREENINFO , &finfo ) ) { 38 if ( ioctl( fd_framebuffer , FBIOGET_FSCREENINFO , &finfo ) ) {
39 send_current_error_msg("Fixed information not gotton !"); 39 send_current_error_msg("Fixed information not gotton !");
40 exit(2); 40 exit(2);
41 } 41 }
42 42
43 /* 変動スクリーン情報取得 */ 43 // 変動スクリーン情報取得
44 if ( ioctl( fd_framebuffer , FBIOGET_VSCREENINFO , &vinfo ) ) { 44 if ( ioctl( fd_framebuffer , FBIOGET_VSCREENINFO , &vinfo ) ) {
45 send_current_error_msg("Variable information not gotton !"); 45 send_current_error_msg("Variable information not gotton !");
46 exit(3); 46 exit(3);
47 } 47 }
48 48
53 vbpp = vinfo.bits_per_pixel; 53 vbpp = vinfo.bits_per_pixel;
54 54
55 width = xres; 55 width = xres;
56 height = yres; 56 height = yres;
57 bpp = vbpp; 57 bpp = vbpp;
58
58 59
59 Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO; 60 Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO;
60 Uint32 *p; 61 Uint32 *p;
61 62
62 if (SDL_Init(sdl_flag) < 0) { 63 if (SDL_Init(sdl_flag) < 0) {
63 fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError()); 64 fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError());
64 exit(1); 65 exit(1);
65 } 66 }
66 67
67 screen = SDL_SetVideoMode(width, height, bpp, SDL_HWSURFACE); 68 screen = SDL_SetVideoMode(width, height, bpp, SDL_SWSURFACE);
68 if (screen == NULL) { 69 if (screen == NULL) {
69 fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError()); 70 fprintf(stderr, "Couldn't set SDL mode: %s\n", SDL_GetError());
70 SDL_Quit(); 71 SDL_Quit();
71 exit(1); 72 exit(1);
72 } 73 }
73 this->width = screen->w; 74 this->width = screen->w;
74 this->height = screen->h; 75 this->height = screen->h;
75 this->bpp = screen->format->BitsPerPixel; 76 this->bpp = screen->format->BitsPerPixel;
76 77
77 p = (Uint32*)manager->allocate(screen->pitch*height); 78 p = (Uint32*)manager->allocate(screen->pitch*height);
78 bitmap = SDL_CreateRGBSurfaceFrom((void *)p,
79 screen->w, screen->h,
80 screen->format->BitsPerPixel,
81 screen->pitch,
82 redMask, greenMask, blueMask, alphaMask);
83 79
84 return p; 80 return p;
85 } 81 }
86 82
87 void 83 void
88 ViewerSDL::clean_pixels() 84 ViewerSDL::clean_pixels()
89 { 85 {
90 //bzero(pixels, sizeof(int)*width*height); 86 //bzero(pixels, sizeof(int)*width*height);
91 SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0)); 87 //SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0));
92 } 88 }
93 89
94 void 90 void
95 ViewerSDL::clear_screen() 91 ViewerSDL::clear_screen()
96 { 92 {
93
97 #if !UGA 94 #if !UGA
98 SDL_BlitSurface(bitmap, NULL, screen, NULL); 95 SDL_BlitSurface(bitmap, NULL, screen, NULL);
99 SDL_UpdateRect(screen, 0, 0, 0, 0); 96 SDL_UpdateRect(screen, 0, 0, 0, 0);
100 #endif 97 #endif
98
101 } 99 }
102 100
103 uint32_t * 101 uint32_t *
104 ViewerSDL::flip_screen(uint32_t *old) 102 ViewerSDL::flip_screen(uint32_t *old)
105 { 103 {
106 #if UGA 104 #if UGA
105
106 bitmap = SDL_CreateRGBSurfaceFrom((void *)old,
107 screen->w, screen->h,
108 screen->format->BitsPerPixel,
109 screen->pitch,
110 //redMask, greenMask, blueMask, alphaMask);
111 redMask, greenMask, blueMask, 0);
112
107 SDL_BlitSurface(bitmap,NULL,screen,NULL); 113 SDL_BlitSurface(bitmap,NULL,screen,NULL);
108 SDL_UpdateRect(screen,0,0,0,0); 114 SDL_UpdateRect(screen,0,0,0,0);
115
109 #endif 116 #endif
117
110 return old; 118 return old;
111 } 119 }
112 120
113 void 121 void
114 ViewerSDL::free_device() 122 ViewerSDL::free_device()