90
|
1 #include <iostream>
|
|
2 #include <SDL.h>
|
|
3 #include <math.h>
|
|
4 #include <unistd.h>
|
|
5 #include "viewer.h"
|
|
6 #include "polygon.h"
|
|
7 using namespace std;
|
|
8
|
|
9 Polygon *polygon;
|
|
10
|
|
11 #define redMask 0x00ff0000
|
|
12 #define greenMask 0x0000ff00
|
|
13 #define blueMask 0x000000ff
|
|
14 #define alphaMask 0
|
|
15
|
|
16 Viewer::Viewer(int b, int w, int h) {
|
|
17 bpp = b;
|
|
18 width = w;
|
|
19 height = h;
|
|
20 }
|
|
21
|
|
22 void Viewer::sdl_init() {
|
|
23 if( SDL_Init( SDL_INIT_VIDEO ) < 0) {
|
|
24 fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError());
|
|
25 exit(1);
|
|
26 }
|
|
27 #if 0
|
|
28 screen = SDL_SetVideoMode( width, height, bpp, SDL_HWSURFACE);
|
|
29 if(screen == NULL) {
|
|
30 fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
|
|
31 SDL_Quit();
|
|
32 exit(1);
|
|
33 }
|
|
34 #else
|
|
35 void *_pixels = new Uint32[width*height*32/8];
|
|
36 screen = SDL_CreateRGBSurfaceFrom(_pixels, width, height, 32,
|
|
37 width*4, redMask, greenMask,
|
|
38 blueMask,alphaMask);
|
|
39 #endif
|
|
40 }
|
|
41
|
|
42 void Viewer::run_init() {
|
|
43 polygon = new Polygon;
|
|
44 polygon->set_data("cube.xml");
|
|
45 polygon->viewer = this;
|
|
46 }
|
|
47
|