Mercurial > hg > Members > kono > Cerium
comparison old/sdl_test/sdl_test.cc @ 998:ad5232ad4952
add fb_test, minor fix
author | yutaka@localhost.localdomain |
---|---|
date | Fri, 15 Oct 2010 02:13:55 +0900 |
parents | 78ebcdaae8bc |
children |
comparison
equal
deleted
inserted
replaced
997:625be5ca53ab | 998:ad5232ad4952 |
---|---|
10 void send_current_information(const char *ptr) | 10 void send_current_information(const char *ptr) |
11 { | 11 { |
12 fprintf( stdout , "%s\n" , ptr ); | 12 fprintf( stdout , "%s\n" , ptr ); |
13 } | 13 } |
14 | 14 |
15 | |
15 const int redMask = 0x00ff0000; | 16 const int redMask = 0x00ff0000; |
16 const int greenMask = 0x0000ff00; | 17 const int greenMask = 0x0000ff00; |
17 const int blueMask = 0x000000ff; | 18 const int blueMask = 0x000000ff; |
18 const int alphaMask = 0xff000000; | 19 const int alphaMask = 0xff000000; |
20 | |
19 | 21 |
20 fb_t | 22 fb_t |
21 get_fbdev_addr(void) | 23 get_fbdev_addr(void) |
22 { | 24 { |
23 int fd_framebuffer ; | 25 int fd_framebuffer ; |
61 send_current_information( tmp ); | 63 send_current_information( tmp ); |
62 | 64 |
63 /* バイト単位でのスクリーンのサイズを計算 */ | 65 /* バイト単位でのスクリーンのサイズを計算 */ |
64 screensize = xres * yres * vbpp / DIV_BYTE ; | 66 screensize = xres * yres * vbpp / DIV_BYTE ; |
65 | 67 |
66 /* デバイスをメモリにマップする */ | |
67 fbptr = (char *)mmap(0,screensize,PROT_READ | PROT_WRITE,MAP_SHARED,fd_framebuffer,0); | |
68 if ( (int)fbptr == -1 ) { | |
69 send_current_error_msg("Don't get framebuffer device to memory !"); | |
70 exit(4); | |
71 } | |
72 send_current_information("The framebuffer device was mapped !"); | |
73 | |
74 printf("fb: 0x%x \n", (unsigned int)fbptr); | |
75 | |
76 fb_t fb; | 68 fb_t fb; |
77 fb.pixels = fbptr; | |
78 fb.size = screensize; | 69 fb.size = screensize; |
79 fb.width = xres; | 70 fb.width = xres; |
80 fb.height = yres; | 71 fb.height = yres; |
81 fb.bpp = vbpp; | 72 fb.bpp = vbpp; |
82 fb.fd = fd_framebuffer; | 73 fb.fd = fd_framebuffer; |
86 } | 77 } |
87 | 78 |
88 int main() { | 79 int main() { |
89 | 80 |
90 fb_t fb = get_fbdev_addr(); | 81 fb_t fb = get_fbdev_addr(); |
82 | |
91 close(fb.fd); | 83 close(fb.fd); |
92 | 84 |
93 void *p; | 85 void *p; |
94 Uint32 *gUra; | 86 Uint32 *gUra; |
95 | 87 |
96 //posix_memalign((void**)&gUra, 16, fb.width*fb.height*4); | 88 //posix_memalign((void**)&gUra, 16, fb.width*fb.height*4); |
97 | 89 |
98 gUra = (Uint32*)malloc(fb.width*fb.height*4); | 90 gUra = (Uint32*)malloc(fb.width*fb.height*4); |
99 Uint32 *tmp = (Uint32*)malloc(fb.width*fb.height*4); | |
100 | 91 |
101 printf("fb.height %d \n", fb.height); | 92 printf("fb.height %d \n", fb.height); |
102 | 93 |
103 int i; | 94 int i; |
104 int color = 0x000000ff; | 95 int color = 0x000000ff; |
143 break; | 134 break; |
144 } | 135 } |
145 } | 136 } |
146 | 137 |
147 | 138 |
139 if (color == 0xffffffff) { | |
140 color = 0x000000ff; | |
141 } else { | |
142 | |
143 char r = ((color & redMask) >> 16) + 1; | |
144 char g = ((color & greenMask) >> 8) + 1; | |
145 char b = (color & blueMask) + 1; | |
146 | |
147 color = alphaMask + (r << 16) + (g << 8) + b; | |
148 | |
149 } | |
150 | |
151 for (i = 0; i < fb.width*fb.height; i++) { | |
152 gUra[i] = color; | |
153 } | |
154 | |
148 //ここに処理を追加して変化を見る | 155 //ここに処理を追加して変化を見る |
149 SDL_Surface *bitmap = SDL_CreateRGBSurfaceFrom((void *)gUra,fb.width,fb.height,fb.bpp,fb.width*4,redMask,greenMask,blueMask,alphaMask); | 156 SDL_Surface *bitmap = SDL_CreateRGBSurfaceFrom((void *)gUra,fb.width,fb.height,fb.bpp,fb.width*4,redMask,greenMask,blueMask,0); |
150 SDL_BlitSurface(bitmap,NULL,screen,NULL); | 157 SDL_BlitSurface(bitmap,NULL,screen,NULL); |
151 SDL_UpdateRect(screen,0,0,0,0); | 158 SDL_UpdateRect(screen,0,0,0,0); |
152 | 159 |
153 | 160 |
154 if (SDL_GetTicks() < t1 + 1000){ | 161 if (SDL_GetTicks() < t1 + 1000){ |