annotate TaskManager/Test/simple_render/viewer.cpp @ 29:e949a536a68d

*** empty log message ***
author gongo
date Mon, 11 Feb 2008 17:33:38 +0900
parents 243ee0a1fe6f
children 6a77b5e755ab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
1 #include <iostream>
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
2 #include <SDL.h>
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
3 #include <SDL_opengl.h>
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
4 #include <math.h>
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
5 #include "polygon.h"
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
6 //#include "demonstration.h"
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
7 //#include "scene.h"
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
8 #include "viewer.h"
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
9 #include "sys.h"
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
10 using namespace std;
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
11
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
12 #define redMask 0x00ff0000
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
13 #define greenMask 0x0000ff00
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
14 #define blueMask 0x000000ff
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
15 #define alphaMask 0
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
16
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
17 extern int create_sgp(SceneGraphPack *sgp, Polygon *sg);
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
18 extern int update_sgp(SceneGraphPack *sgp, SceneGraphPack *_sgp);
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
19 extern int create_pp(PolygonPack *pp, SceneGraphPack *sgp);
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
20
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
21 Viewer::Viewer(int b, int w, int h)
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
22 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
23 bpp = b;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
24 width = w;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
25 height = h;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
26 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
27
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
28
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
29 void Viewer::sdl_init()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
30 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
31 if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
32 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
33 fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError());
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
34 exit( 1 );
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
35 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
36 screen = SDL_SetVideoMode( width, height, bpp, SDL_HWSURFACE );
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
37
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
38 //manager = new TaskManager(1);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
39 //manager->init();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
40
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
41 manager->set_symbol("CreateSGP", (void*)create_sgp);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
42 manager->set_symbol("UpdateSGP", (void*)update_sgp);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
43 manager->set_symbol("CreatePP", (void*)create_pp);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
44 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
45
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
46
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
47 void Viewer::init()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
48 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
49 if(SDL_Init( SDL_INIT_VIDEO ) < 0)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
50 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
51 cout << "Couldn't initialize SDL:" << SDL_GetError() << endl;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
52 exit(1);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
53 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
54
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
55 /* See if we should detect the display depth */
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
56 if(bpp == 0)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
57 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
58 if (SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
59 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
60 bpp = 8;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
61 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
62 else
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
63 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
64 bpp = 16; /* More doesn't seem to work */
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
65 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
66 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
67
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
68 //video_flags = SDL_OPENGL;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
69 video_flags = SDL_HWSURFACE;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
70
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
71 /* Initialize the display */
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
72 switch (bpp)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
73 {
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
74 case 8:
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
75 rgb_size[0] = 3;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
76 rgb_size[1] = 3;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
77 rgb_size[2] = 2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
78 break;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
79 case 15:
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
80 case 16:
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
81 rgb_size[0] = 5;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
82 rgb_size[1] = 5;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
83 rgb_size[2] = 5;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
84 break;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
85 default:
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
86 rgb_size[0] = 8;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
87 rgb_size[1] = 8;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
88 rgb_size[2] = 8;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
89 break;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
90 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
91
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
92 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, rgb_size[0]);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
93 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, rgb_size[1]);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
94 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, rgb_size[2]);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
95 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
96 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
97
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
98 SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
99
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
100 screen = SDL_SetVideoMode(width, height, bpp, video_flags);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
101
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
102 if(screen == NULL)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
103 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
104 cout << "Couldn't set GL mode: " << SDL_GetError() << endl;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
105 SDL_Quit();
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
106 exit(1);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
107 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
108
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
109 SDL_WM_SetCaption("SDL GL test", "testgl");
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
110
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
111 glViewport(0, 0, width, height);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
112
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
113 glMatrixMode(GL_PROJECTION);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
114 glLoadIdentity();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
115
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
116 glOrtho(-width/10, width/10, -height/10, height/10, -40.0, 400.0);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
117
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
118 glMatrixMode(GL_MODELVIEW);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
119 glLoadIdentity();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
120
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
121 glEnable(GL_DEPTH_TEST);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
122
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
123 glDepthFunc(GL_LESS);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
124
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
125 glShadeModel(GL_SMOOTH);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
126 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
127
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
128 int Viewer::get_ticks()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
129 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
130 int time;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
131 time = SDL_GetTicks();
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
132 return time;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
133 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
134
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
135 bool Viewer::quit_check()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
136 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
137 bool quit = false;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
138 SDL_Event event;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
139 while(SDL_PollEvent(&event))
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
140 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
141 if(event.type==SDL_QUIT)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
142 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
143 quit = true;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
144 return quit;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
145 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
146 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
147 return quit;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
148 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
149
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
150 void Viewer::quit()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
151 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
152 SDL_Quit();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
153 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
154
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
155
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
156 void Viewer::swap_buffers()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
157 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
158 SDL_GL_SwapBuffers();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
159 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
160
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
161
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
162 void Viewer::write_pixel(int x, int y,float z, Uint32 rgb) {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
163 SDL_PixelFormat *pf;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
164 pf = screen->format;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
165 //printf("x:%d y:%d z:%d\n",x,y,z);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
166
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
167 //cout << "write_pixel" << endl;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
168 //cout << x << " " << y << endl;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
169
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
170 //cout << SDL_MapRGB(pf,0,0,150) << endl;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
171
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
172 x += width/2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
173 y += height/2;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
174
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
175 static int diffz,diffz1;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
176 diffz1 = diffz;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
177 diffz = (zRow[x][y]>z);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
178 if(diffz != diffz1) {
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
179 //printf("diffz :%d zRow[%d][%d] = %f z = %f\n",diffz,x,y,zRow[x][y],z);
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
180 }
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
181 //printf("x:%d,y:%d,z:%f,zRow:%f\n",x,y,z,zRow[x][y]);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
182 if(z < zRow[x][y]) {
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
183 // printf("x:%d,y:%d,z:%d\n",x,y,z,zRow);
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
184 if(x < width && x > 0 && y > 0 && y < height)
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
185 {
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
186 //pixels[width*y + x] = SDL_MapRGB(pf,70,70,71);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
187 zRow[x][y] = z;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
188 y = height - y;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
189 pixels[width*y + x] = rgb;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
190 }
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
191 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
192 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
193
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
194 void Viewer::write_line(float x1, float y1, float x2, float y2, Uint32 rgb)
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
195 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
196 //cout << "write_line("<< x1 << "," << y1 << "," << x2 << "," << y2 << ")"<< endl;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
197
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
198 //Uint32 rgb = 9830400;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
199
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
200 if(x1 > x2)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
201 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
202 float x=0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
203 float y=0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
204 x=x1;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
205 y=y1;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
206 x1 = x2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
207 y1 = y2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
208 x2 = x;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
209 y2 = y;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
210 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
211 float s = y1;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
212
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
213 if((int)x1 == (int)x2)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
214 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
215 if(y1 > y2)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
216 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
217 float y=0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
218 y = y1;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
219 y1 = y2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
220 y2 = y;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
221 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
222 for(float i=y1; i<y2; i++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
223 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
224 //write_pixel((int)x1,(int)i);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
225 write_pixel((int)x1,(int)i,0,rgb);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
226 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
227 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
228 else
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
229 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
230 float t = (y2 - y1)/(x2 - x1);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
231 if(t < -1)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
232 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
233 float f = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
234 for(float i=x1; i<x2; i++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
235 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
236 for(float a=(int)t; a<0; a++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
237 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
238 //write_pixel((int)i,(int)s);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
239 write_pixel((int)i,(int)s,0,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
240 s--;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
241 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
242 f += t-(int)t;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
243 if(f <= -1)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
244 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
245 //write_pixel((int)i,(int)s);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
246 write_pixel((int)i,(int)s,0,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
247 f = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
248 s--;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
249 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
250 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
251 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
252 else if(t <= 1)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
253 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
254 for(float i=x1; i<x2; i++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
255 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
256 //write_pixel((int)i,(int)s);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
257 write_pixel((int)i,(int)s,0,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
258 s += t;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
259 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
260 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
261 else
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
262 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
263 float f = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
264 for(float i=x1; i<x2; i++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
265 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
266 for(float a=0; a<(int)t; a++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
267 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
268 //write_pixel((int)i,(int)s);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
269 write_pixel((int)i,(int)s,0,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
270 s++;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
271 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
272 f += t-(int)t;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
273 if(f >= 1)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
274 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
275 //write_pixel((int)i,(int)s);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
276 write_pixel((int)i,(int)s,0,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
277 f = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
278 s++;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
279 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
280 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
281 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
282 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
283 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
284
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
285 void Viewer::write_triangle(float x1, float y1, float x2, float y2, float x3, float y3, Uint32 rgb)
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
286 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
287 write_line(x1,y1,x2,y2,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
288 write_line(x2,y2,x3,y3,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
289 write_line(x3,y3,x1,y1,rgb);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
290 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
291
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
292 void Viewer::clean_pixels()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
293 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
294 for(int i=0; i<width*height; i++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
295 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
296 pixels[i] = 0x00;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
297 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
298 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
299
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
300 void Viewer::graph_line()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
301 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
302 int xl = width*height/2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
303 int yl = width/2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
304 for(int i=0; i<width; i++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
305 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
306 for(int t=0; t<height; t+=20)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
307 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
308 pixels[width*t+i] = 0x5a;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
309 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
310 pixels[xl +i] = 0xff;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
311 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
312 for(int i=0; i<height; i++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
313 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
314 for(int t=0; t<width; t+=20)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
315 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
316 pixels[i*width+t] = 0x5a;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
317 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
318 pixels[i*width+yl] = 0xff;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
319 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
320 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
321
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
322
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
323 void Viewer::run()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
324 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
325 int frames = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
326 int start_time, this_time;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
327
29
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
328 HTaskPtr task_create_sgp = NULL;
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
329 HTaskPtr task_update_sgp = NULL;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
330 HTaskPtr task_create_pp = NULL;
29
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
331 int fd_create_sgp;
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
332 int fd_update_sgp;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
333 int fd_create_pp;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
334
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
335 start_time = get_ticks();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
336
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
337 SDL_Surface *bitmap = NULL;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
338 SDL_PixelFormat *pf;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
339 pf = screen->format;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
340
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
341 Uint32 background;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
342 background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
343
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
344 pixels = new Uint32[width*height];
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
345
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
346 Polygon *p = new Polygon;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
347 p->set_data("cube.xml");
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
348 //p->set_data("cube-p.xml");
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
349
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
350 p->viewer = this;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
351 //p->screen = screen;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
352 /*
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
353 p->next->viewer = this;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
354 p->next->next->viewer = this;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
355 p->next->next->next->viewer = this;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
356 p->next->next->next->next->viewer = this;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
357 p->next->next->next->next->next->viewer = this;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
358 p->next->next->next->next->next->next->viewer = this;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
359 p->next->next->next->next->next->next->next->viewer = this;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
360 p->next->next->next->next->next->next->next->next->viewer = this;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
361 p->next->next->next->next->next->next->next->next->next->viewer = this;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
362 */
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
363
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
364 SceneGraphPack *sgp = new SceneGraphPack;
29
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
365 //create_sgp(sgp,p);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
366
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
367 PolygonPack *pp = new PolygonPack;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
368
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
369 graph_line();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
370
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
371 float r = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
372 float x = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
373 float y = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
374 float z = 0;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
375
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
376 // Loop until done.
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
377 while(1)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
378 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
379 // Destroy our GL context, etc.
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
380 //if(quit_check() || scene->action_scene==NULL)
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
381 if(quit_check())
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
382 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
383 this_time = get_ticks();
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
384 if (this_time != start_time)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
385 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
386 cout<<((float)frames/(this_time-start_time))*1000.0<<" FPS\n";
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
387 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
388 SDL_FreeSurface(bitmap);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
389 delete pixels;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
390 p->delete_data();
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
391 delete p;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
392 delete sgp;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
393 delete pp;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
394 quit();
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
395 break;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
396 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
397 /////////////////////
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
398 clean_pixels();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
399
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
400 this->zRow_init();
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
401 graph_line();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
402
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
403 if(r > 360) r = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
404 r+= 1.0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
405 // r= 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
406 p->angle[0] = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
407 p->angle[1] = r;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
408 p->angle[2] = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
409 //p->child->angle[1] = r*2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
410 //p->child->brother->angle[1] = r*3;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
411 //p->child->brother->child->angle[1] = r*4;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
412 x += 0.5;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
413 y += 0.5;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
414 z += 0.5;
29
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
415 p->xyz[0] = x;
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
416 p->xyz[1] = y;
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
417 p->xyz[2] = z;
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
418 p->tree_draw();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
419
29
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
420 #if 1
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
421 create_sgp(sgp, p);
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
422 update_sgp(sgp, sgp);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
423 create_pp(pp, sgp);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
424 #else
29
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
425 fd_create_sgp = manager->open("CreateSGP");
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
426 fd_update_sgp = manager->open("UpdateSGP");
29
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
427 fd_create_pp = manager->open("CreatePP");
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
428
29
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
429 task_create_sgp =
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
430 manager->create_task(fd_create_sgp,
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
431 sizeof(Polygon),
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
432 (unsigned int)p,
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
433 (unsigned int)sgp,
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
434 NULL);
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
435 task_update_sgp =
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
436 manager->create_task(fd_update_sgp,
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
437 sizeof(SceneGraphPack),
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
438 (unsigned int)sgp,
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
439 (unsigned int)sgp,
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
440 NULL);
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
441 task_create_pp =
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
442 manager->create_task(fd_create_pp,
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
443 sizeof(SceneGraphPack),
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
444 (unsigned int)sgp,
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
445 (unsigned int)pp,
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
446 NULL);
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
447
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
448 manager->set_task_depend(task_create_sgp, task_update_sgp);
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
449 manager->set_task_depend(task_create_sgp, task_create_pp);
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
450 manager->spawn_task(task_create_sgp);
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
451 manager->spawn_task(task_update_sgp);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
452 manager->spawn_task(task_create_pp);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
453
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
454 manager->run();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
455 #endif
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
456 //p->draw(sgp);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
457 p->draw(pp);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
458
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
459 bitmap =
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
460 SDL_CreateRGBSurfaceFrom((void *)pixels, width, height, 32, width*4,
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
461 redMask, greenMask, blueMask, alphaMask);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
462 SDL_FillRect(screen, NULL, background);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
463 SDL_BlitSurface(bitmap, NULL, screen, NULL);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
464 SDL_UpdateRect(screen, 0, 0, 0, 0);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
465
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
466
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
467 /////////////////////
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
468
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
469 //swap_buffers();
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
470 ++frames;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
471 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
472 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
473
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
474 void
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
475 Viewer::zRow_init()
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
476 {
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
477 for (int i = 0; i < width; i++) {
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
478 for (int j = 0; j < height; j++) {
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
479 zRow[i][j] = 65535;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
480 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
481 }
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
482 }