Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 35 | chris | 1 | unit app_glscene_board; |
| 2 | |||
| 3 | interface |
||
| 4 | |||
| 5 | uses OpenGL, GLaux, glExt, sux_constant, sux_object, app_constant, |
||
| 6 | resource_texture, resource_shader, app_entity_main, |
||
| 7 | resource_list, app_glscene_board_monkey, app_particle_vertexbuffer; |
||
| 8 | |||
| 9 | type |
||
| 10 | TSettings=record |
||
| 11 | paddle:SRTexture; |
||
| 12 | ball:SRTexture; |
||
| 13 | board:SRTexture; |
||
| 14 | wallimpact:SRTexture; |
||
| 15 | paddleimpact:SRTexture; |
||
| 16 | trail:SRTexture; |
||
| 17 | warp:SRTexture; |
||
| 18 | monkey:SRTexture; |
||
| 19 | banana: SRTexture; |
||
| 20 | monkeyspeed:SXFloat; |
||
| 21 | crystal: SRTexture; |
||
| 22 | ballsparks: SRTexture; |
||
| 23 | shards: array[1..5] of SRTexture; |
||
| 24 | icon: SRTexture; |
||
| 25 | icon_pixel: SRTexture; |
||
| 26 | icon_flowers: SRTexture; |
||
| 27 | icon_slowmotion: SRTexture; |
||
| 28 | icon_createcrystals: SRTexture; |
||
| 29 | icon_concave: SRTexture; |
||
| 30 | icon_bomb: SRTexture; |
||
| 31 | flower: SRTexture; |
||
| 32 | flowerpower: SRTexture; |
||
| 33 | monkeycount: SXInt; |
||
| 34 | bananacount: SXInt; |
||
| 35 | vertexbuffermonkeys: SAPVertexBuffer; |
||
| 36 | vertexbufferbananas: SAPVertexBuffer; |
||
| 37 | end; |
||
| 38 | SAGLSBoard=class(SUXObject) |
||
| 39 | settings:TSettings; |
||
| 40 | monkeys:SRList; |
||
| 41 | |||
| 42 | procedure setMonkeyRotationSpeed(speed:SXFloat); |
||
| 43 | procedure createMonkeys; |
||
| 44 | |||
| 45 | procedure renderEntities; |
||
| 46 | procedure renderParticleSystems; |
||
| 47 | procedure renderBackGround; |
||
| 48 | procedure renderMonkeys; |
||
| 49 | |||
| 50 | procedure onTimer; |
||
| 51 | |||
| 52 | procedure initialize; |
||
| 53 | constructor Create(parent:TObject); |
||
| 54 | destructor Destroy; override; |
||
| 55 | end; |
||
| 56 | |||
| 57 | implementation |
||
| 58 | |||
| 59 | uses sux_main, gl_main, main; |
||
| 60 | |||
| 61 | |||
| 62 | // --- SAGLSBoard |
||
| 63 | |||
| 64 | |||
| 65 | procedure SAGLSBoard.setMonkeyRotationSpeed(speed:SXFloat); |
||
| 66 | begin |
||
| 67 | settings.monkeyspeed:=sx.timer.getTimer(speed*0.08); |
||
| 68 | end; |
||
| 69 | |||
| 70 | |||
| 71 | procedure SAGLSBoard.createMonkeys; |
||
| 72 | var x,y:SXInt; |
||
| 73 | monkey:SAGLSBMonkey; |
||
| 74 | pos:SXVertex2D; |
||
| 75 | interval:SXVertex2D; |
||
| 76 | i: SXInt; |
||
| 77 | begin |
||
| 78 | interval.x:=840/10; |
||
| 79 | interval.y:=680/8; |
||
| 80 | |||
| 81 | settings.monkeycount := 0; |
||
| 82 | settings.bananacount := 0; |
||
| 83 | |||
| 84 | for i := 0 to 1 do |
||
| 85 | for x := 0 to 9 do |
||
| 86 | for y := 0 to 7 do |
||
| 87 | if ((odd(x) = odd(y)) and (i = 0)) or ((odd(x) = not odd(y)) and (i = 1)) then |
||
| 88 | begin |
||
| 89 | pos.x := -100+interval.x*x+sx.math.random.getRandomFloat(0,interval.x); |
||
| 90 | pos.y := -100+interval.y*y+sx.math.random.getRandomFloat(0,interval.y); |
||
| 91 | |||
| 92 | monkey:=SAGLSBMonkey.Create(pos,sx.math.random.getRandomFloat(0,360), |
||
| 93 | sx.math.random.getRandomFloat(70,100),sx.math.random.getRandomFloat(0.7,1.0)); |
||
| 94 | case i of |
||
| 95 | |||
| 96 | 1 : monkey.setTexture(settings.banana); |
||
| 97 | end; |
||
| 98 | monkeys.addObject(monkey); |
||
| 99 | |||
| 100 | case i of |
||
| 101 | |||
| 102 | 1 : inc(settings.bananacount); |
||
| 103 | end; |
||
| 104 | end; |
||
| 105 | |||
| 106 | settings.vertexbuffermonkeys.setVertexCount(settings.monkeycount * 4); |
||
| 107 | settings.vertexbufferbananas.setVertexCount(settings.bananacount * 4); |
||
| 108 | end; |
||
| 109 | |||
| 110 | |||
| 111 | |||
| 112 | |||
| 113 | procedure SAGLSBoard.renderEntities; |
||
| 114 | var e:SXInt; |
||
| 115 | begin |
||
| 116 | // Set up a coordinate system for the entities where the center |
||
| 117 | // of the field is (0,0). |
||
| 118 | glPushMatrix; |
||
| 119 | glTranslatef(320,260,0); |
||
| 120 | |||
| 121 | with app.game do |
||
| 122 | begin |
||
| 123 | for e:=0 to entities.getMax do getEntity(e).onRender; |
||
| 124 | end; |
||
| 125 | |||
| 126 | glPopMatrix; |
||
| 127 | end; |
||
| 128 | |||
| 129 | |||
| 130 | procedure SAGLSBoard.renderParticleSystems; |
||
| 131 | var p:SXInt; |
||
| 132 | begin |
||
| 133 | // Set up a coordinate system for the entities where the center |
||
| 134 | // of the field is (0,0). |
||
| 135 | glPushMatrix; |
||
| 136 | glTranslatef(320,260,0); |
||
| 137 | |||
| 138 | with app.game do |
||
| 139 | begin |
||
| 140 | for p:=0 to particlesystems.getMax do getParticleSystem(p).onRender; |
||
| 141 | end; |
||
| 142 | |||
| 143 | glPopMatrix; |
||
| 144 | end; |
||
| 145 | |||
| 146 | |||
| 147 | procedure SAGLSBoard.renderBackGround; |
||
| 148 | var center,size:SXVertex2D; |
||
| 149 | begin |
||
| 150 | center:=sx.convert.Vertex2DOf(320, 260); |
||
| 151 | size:=sx.convert.Vertex2DOf(280, 280); |
||
| 152 | |||
| 153 | // Render black quads. |
||
| 154 | gl.gl2D.renderRectangle(0, 0, center.x - size.x, 480, SX_GL_BLEND_OPAQUE, |
||
| 155 | sx.convert.ColorRGBOf(0, 0, 0), 1); |
||
| 156 | gl.gl2D.renderRectangle(center.x + size.x, 0, 640, 480, SX_GL_BLEND_OPAQUE, |
||
| 157 | sx.convert.ColorRGBOf(0, 0, 0), 1); |
||
| 158 | gl.gl2D.renderRectangle(0, center.y + size.y - 80, 640, 700, SX_GL_BLEND_OPAQUE, |
||
| 159 | sx.convert.ColorRGBOf(0, 0, 0), 1); |
||
| 160 | |||
| 161 | gl.gl2D.renderRectangle(center.x-size.x,center.y-size.y,center.x+size.x,center.y+size.y,settings.board, |
||
| 162 | SX_GL_BLEND_AVERAGE,sx.convert.ColorRGBOf(1,1,1),1); |
||
| 163 | end; |
||
| 164 | |||
| 165 | |||
| 166 | procedure SAGLSBoard.renderMonkeys; |
||
| 167 | var m:SXInt; |
||
| 168 | monkey: SAGLSBMonkey; |
||
| 169 | flowermode: SXBool; |
||
| 170 | begin |
||
| 171 | flowermode := (app.game.settings.effects.flowers > 0); |
||
| 172 | |||
| 173 | gl.material.resetMaterial; |
||
| 174 | gl.material.setMaterial2D; |
||
| 175 | gl.material.setMaterialBlending(SX_GL_BLEND_ADDITIVE,sx.convert.ColorRGBOf(1,1,1),1); |
||
| 176 | gl.material.setMaterialShader(app.scene.scene.particle, nil); |
||
| 177 | gl.material.renderMaterial; |
||
| 178 | |||
| 179 | if (flowermode) then gl.texture.setTexture(settings.flower); |
||
| 180 | |||
| 181 | glPushMatrix; |
||
| 182 | |||
| 183 | if (not flowermode) then gl.texture.setTexture(settings.monkey); |
||
| 184 | for m := 0 to settings.monkeycount - 1 do |
||
| 185 | begin |
||
| 186 | monkey := SAGLSBMonkey(monkeys.getObject(m)); |
||
| 187 | monkey.renderMonkey(settings.vertexbuffermonkeys, m); |
||
| 188 | end; |
||
| 189 | settings.vertexbuffermonkeys.onRender; |
||
| 190 | |||
| 191 | if (not flowermode) then gl.texture.setTexture(settings.banana); |
||
| 192 | for m := settings.monkeycount to monkeys.getMax do |
||
| 193 | begin |
||
| 194 | monkey := SAGLSBMonkey(monkeys.getObject(m)); |
||
| 195 | monkey.renderMonkey(settings.vertexbufferbananas, m - settings.monkeycount); |
||
| 196 | end; |
||
| 197 | settings.vertexbufferbananas.onRender; |
||
| 198 | |||
| 199 | glPopMatrix; |
||
| 200 | |||
| 201 | if (not flowermode) then |
||
| 202 | begin |
||
| 203 | gl.gl2D.renderRectangle(0,0,640,480,SX_GL_BLEND_NEGATIVEINVERT,sx.convert.ColorRGBOf(1,1,1),0.13); |
||
| 204 | end else |
||
| 205 | begin |
||
| 206 | gl.gl2D.renderRectangle(0,0,640,480,SX_GL_BLEND_NEGATIVEINVERT,sx.convert.ColorRGBOf(1,1,1),0.25); |
||
| 207 | end; |
||
| 208 | end; |
||
| 209 | |||
| 210 | |||
| 211 | |||
| 212 | |||
| 213 | procedure SAGLSBoard.onTimer; |
||
| 214 | begin |
||
| 215 | renderMonkeys; |
||
| 216 | renderEntities; |
||
| 217 | renderParticleSystems; |
||
| 218 | renderBackGround; |
||
| 219 | app.scene.postprocess.onTimer; |
||
| 220 | end; |
||
| 221 | |||
| 222 | |||
| 223 | |||
| 224 | |||
| 225 | procedure SAGLSBoard.initialize; |
||
| 226 | var s: SXInt; |
||
| 227 | begin |
||
| 228 | settings.paddle:=SRTexture.Create('textures\objects\paddle',self); |
||
| 229 | settings.ball:=SRTexture.Create('textures\objects\ball',self); |
||
| 230 | settings.board:=SRTexture.Create('textures\objects\board',self); |
||
| 231 | settings.wallimpact:=SRTexture.Create('textures\objects\wallimpact',self); |
||
| 232 | settings.paddleimpact:=SRTexture.Create('textures\objects\paddleimpact',self); |
||
| 233 | settings.trail:=SRTexture.Create('textures\objects\trail',self); |
||
| 234 | settings.warp:=SRTexture.Create('textures\objects\warp',self); |
||
| 235 | settings.monkey:=SRTexture.Create('textures\objects\monkey',self); |
||
| 236 | settings.banana := SRTexture.Create('textures\objects\banana',self); |
||
| 237 | settings.crystal := SRTexture.Create('textures\objects\crystal', self); |
||
| 238 | settings.ballsparks := SRTexture.Create('textures\particles\ballsparks', self); |
||
| 239 | for s := 1 to 5 do settings.shards[s] := SRTexture.Create('textures\particles\shard' + sx.convert.intToStr(s), self); |
||
| 240 | settings.icon := SRTexture.Create('textures\objects\icon', self); |
||
| 241 | settings.icon_pixel := SRTexture.Create('textures\objects\icon_chess', self); |
||
| 242 | settings.icon_flowers := SRTexture.Create('textures\objects\icon_flower', self); |
||
| 243 | settings.icon_slowmotion := SRTexture.Create('textures\objects\icon_hourglass', self); |
||
| 244 | settings.icon_createcrystals := SRTexture.Create('textures\objects\icon_crystal', self); |
||
| 245 | settings.icon_concave := SRTexture.Create('textures\objects\icon_concave', self); |
||
| 246 | settings.icon_bomb := SRTexture.Create('textures\objects\icon_bomb', self); |
||
| 247 | settings.flower := SRTexture.Create('textures\objects\flower', self); |
||
| 248 | settings.flowerpower := SRTexture.Create('textures\objects\flowerpower', self); |
||
| 249 | |||
| 250 | settings.vertexbuffermonkeys := SAPVertexBuffer.Create; |
||
| 251 | settings.vertexbufferbananas := SAPVertexBuffer.Create; |
||
| 252 | |||
| 253 | createMonkeys; |
||
| 254 | end; |
||
| 255 | |||
| 256 | |||
| 257 | constructor SAGLSBoard.Create(parent:TObject); |
||
| 258 | begin |
||
| 259 | inherited Create(parent,'GL Board'); |
||
| 260 | |||
| 261 | monkeys:=SRList.Create(self,false,true,false); |
||
| 262 | setMonkeyRotationSpeed(0); |
||
| 263 | end; |
||
| 264 | |||
| 265 | |||
| 266 | destructor SAGLSBoard.Destroy; |
||
| 267 | var s: SXInt; |
||
| 268 | begin |
||
| 269 | monkeys.Free; |
||
| 270 | settings.paddle.Free; |
||
| 271 | settings.ball.Free; |
||
| 272 | settings.board.Free; |
||
| 273 | settings.wallimpact.Free; |
||
| 274 | settings.paddleimpact.Free; |
||
| 275 | settings.trail.Free; |
||
| 276 | settings.warp.Free; |
||
| 277 | settings.monkey.Free; |
||
| 278 | settings.banana.Free; |
||
| 279 | settings.crystal.Free; |
||
| 280 | settings.ballsparks.Free; |
||
| 281 | for s := 1 to 5 do settings.shards[s].Free; |
||
| 282 | settings.icon.Free; |
||
| 283 | settings.icon_pixel.Free; |
||
| 284 | settings.icon_flowers.Free; |
||
| 285 | settings.icon_slowmotion.Free; |
||
| 286 | settings.icon_createcrystals.Free; |
||
| 287 | settings.icon_concave.Free; |
||
| 288 | settings.icon_bomb.Free; |
||
| 289 | settings.flower.Free; |
||
| 290 | settings.flowerpower.Free; |
||
| 291 | settings.vertexbuffermonkeys.Free; |
||
| 292 | settings.vertexbufferbananas.Free; |
||
| 293 | |||
| 294 | inherited; |
||
| 295 | end; |
||
| 296 | |||
| 297 | |||
| 298 | end. |