Mercurial > hg > Game > Cerium
annotate Renderer/Engine/viewerSDL.cc @ 996:bac3b0afc3e8 draft
add sdl_test file
author | yutaka@charles.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Mon, 11 Oct 2010 18:56:51 +0900 |
parents | 56c3b9dd37a7 |
children | 78552463c06a |
rev | line source |
---|---|
539 | 1 #include "viewerSDL.h" |
2 #include "Func.h" | |
3 #include "TaskManager.h" | |
728 | 4 #include "viewer_types.h" |
993
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
5 #include "fb.h" |
539 | 6 |
984 | 7 #define UGA 1 |
8 | |
539 | 9 extern void post2runLoop(void *); |
10 | |
728 | 11 #define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK |
539 | 12 |
728 | 13 ViewerSDL::ViewerSDL() {} |
14 ViewerSDL::~ViewerSDL() {} | |
15 | |
993
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
16 #define DEVICE_NAME "/dev/fb0" |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
17 #define DIV_BYTE 8 |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
18 |
728 | 19 Uint32 * |
20 ViewerSDL::video_init(TaskManager *manager, int bpp, int width, int height) | |
539 | 21 { |
994 | 22 |
993
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
23 int fd_framebuffer ; |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
24 struct fb_var_screeninfo vinfo; |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
25 struct fb_fix_screeninfo finfo; |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
26 |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
27 int xres,yres,vbpp; |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
28 |
994 | 29 // 読み書き用にファイルを開く |
993
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
30 fd_framebuffer = open( DEVICE_NAME , O_RDWR); |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
31 if ( !fd_framebuffer ) { |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
32 send_current_error_msg("Framebuffer device open error !"); |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
33 exit(1); |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
34 } |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
35 send_current_information("The framebuffer device was opened !"); |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
36 |
994 | 37 // 固定スクリーン情報取得 |
993
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
38 if ( ioctl( fd_framebuffer , FBIOGET_FSCREENINFO , &finfo ) ) { |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
39 send_current_error_msg("Fixed information not gotton !"); |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
40 exit(2); |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
41 } |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
42 |
994 | 43 // 変動スクリーン情報取得 |
993
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
44 if ( ioctl( fd_framebuffer , FBIOGET_VSCREENINFO , &vinfo ) ) { |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
45 send_current_error_msg("Variable information not gotton !"); |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
46 exit(3); |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
47 } |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
48 |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
49 close(fd_framebuffer); |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
50 |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
51 xres = vinfo.xres; |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
52 yres = vinfo.yres; |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
53 vbpp = vinfo.bits_per_pixel; |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
54 |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
55 width = xres; |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
56 height = yres; |
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
57 bpp = vbpp; |
994 | 58 |
993
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
59 |
539 | 60 Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO; |
61 Uint32 *p; | |
993
d3b20d63057e
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
62 |
539 | 63 if (SDL_Init(sdl_flag) < 0) { |
64 fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError()); | |
65 exit(1); | |
66 } | |
67 | |
996 | 68 screen = SDL_SetVideoMode(width, height, bpp, SDL_HWSURFACE); |
539 | 69 if (screen == NULL) { |
994 | 70 fprintf(stderr, "Couldn't set SDL mode: %s\n", SDL_GetError()); |
539 | 71 SDL_Quit(); |
72 exit(1); | |
73 } | |
996 | 74 |
895
b662e9dd26b0
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
728
diff
changeset
|
75 this->width = screen->w; |
b662e9dd26b0
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
728
diff
changeset
|
76 this->height = screen->h; |
b662e9dd26b0
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
728
diff
changeset
|
77 this->bpp = screen->format->BitsPerPixel; |
539 | 78 |
79 p = (Uint32*)manager->allocate(screen->pitch*height); | |
80 | |
728 | 81 return p; |
539 | 82 } |
83 | |
84 void | |
85 ViewerSDL::clean_pixels() | |
86 { | |
87 //bzero(pixels, sizeof(int)*width*height); | |
996 | 88 |
994 | 89 //SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0)); |
539 | 90 } |
91 | |
92 void | |
728 | 93 ViewerSDL::clear_screen() |
539 | 94 { |
994 | 95 |
984 | 96 #if !UGA |
539 | 97 SDL_BlitSurface(bitmap, NULL, screen, NULL); |
98 SDL_UpdateRect(screen, 0, 0, 0, 0); | |
984 | 99 #endif |
994 | 100 |
984 | 101 } |
102 | |
103 uint32_t * | |
104 ViewerSDL::flip_screen(uint32_t *old) | |
105 { | |
106 #if UGA | |
994 | 107 |
108 bitmap = SDL_CreateRGBSurfaceFrom((void *)old, | |
109 screen->w, screen->h, | |
110 screen->format->BitsPerPixel, | |
111 screen->pitch, | |
112 //redMask, greenMask, blueMask, alphaMask); | |
113 redMask, greenMask, blueMask, 0); | |
114 | |
984 | 115 SDL_BlitSurface(bitmap,NULL,screen,NULL); |
116 SDL_UpdateRect(screen,0,0,0,0); | |
994 | 117 |
984 | 118 #endif |
994 | 119 |
984 | 120 return old; |
539 | 121 } |
122 | |
123 void | |
728 | 124 ViewerSDL::free_device() |
539 | 125 { |
126 free(bitmap->pixels); | |
127 SDL_FreeSurface(bitmap); | |
128 } |