root/trunk/game.d

Revision 5, 2.8 kB (checked in by aliloko, 8 months ago)

First commit

  • Property svn:executable set to *
Line 
1 module game;
2
3 import util.sdlapp;
4
5 import util.gl.shaders;
6 import util.gl.texture;
7 import util.gl.framebuffer;
8 import util.gl.buffer;
9 import std.math;
10 import std.string;
11 import util.common;
12 import util.complexes;
13
14 import util.geometry;
15 //import util.al.source;
16 //import util.al.buffer;
17 import util.sceneobject;
18 import sound;
19
20
21 scope class Game : SDLApp {
22    
23
24     private {
25    
26         Texture2D tex = null;
27         Program p = null;           
28         SoundManager sm = null;
29            
30         SceneObject scene = null; // root of the scene
31            
32         float[] data;           
33            
34     }
35        
36     public {
37    
38    
39         this(int width, int height, bit fullscreen)
40         {
41             super(width, height, fullscreen);
42            
43             data.length = 256 * 256 * 4;
44            
45             // scene = new SceneObject(null);
46    
47     /*     
48             p = new Program("vertex.glsl","fragment.glsl");             
49             
50             sm = new SoundManager(44100);
51             
52             for (int i = 0; i < 128; i++) {
53                 for (int j = 0; j < 128; j++) {
54                     
55                     data[i][j][0] = (i / 128.0) * (j/ 128.0); 
56                     data[i][j][1] = (i / 128.0) * (1-j/ 128.0); 
57                     data[i][j][2] = (1-i / 128.0) * (j/ 128.0); 
58                     data[i][j][3] = 1.0;
59                     
60                                     
61                 }
62             }           
63             
64             tex = new Texture2D(Texture.IFormat.RGBA8);         
65             tex.setImage(0, 128, 128, Texture.Format.RGBA, Texture.Type.FLOAT, new CPUBuffer(data.ptr));           
66             tex.getImage(0, Texture.Format.RGBA, Texture.Type.FLOAT, data.ptr);         
67             assert(glCheck());         
68             p.setSampler("tex1", tex);         
69             assert(glCheck());
70     */
71            
72            
73         }
74        
75         ~this() {
76        
77             if (scene !is null) delete scene;
78             if (p !is null) delete p;
79             if (tex !is null) delete tex;           
80             if (sm !is null) delete sm;             
81            
82         }
83        
84        
85         void render() {
86            
87            
88             // draw to the screen
89            
90            
91             //root.render();       
92            
93             FrameBuffer fb = FrameBuffer.getDefault();
94             fb.clear(true,false,false);
95             fb.setBlendState(new BlendState(
96                     true,
97                     BlendState.Operation.ADD,
98                     BlendState.Factor.SRC_ALPHA,
99                     BlendState.Factor.ONE_MINUS_SRC_ALPHA,
100                     BlendState.Operation.MAX,
101                     BlendState.Factor.ONE,
102                     BlendState.Factor.ONE)
103             );         
104             fb.use();
105            
106     //      disp("render");
107            
108             Program.noProgram();
109            
110             float dx = 2.0 / 256.0;
111             float dy = 2.0 / 256.0;
112             float y = -1.0;
113            
114             float * p = &data[0];           
115            
116             for (int j = 0; j < 256; j++) {
117                
118                 float x = -1.0;
119            
120                 for (int i = 0; i < 256; i++) {
121                    
122                     cfloat z = x + y * 1.0i;
123                    
124                     *(p++) = z.re;
125                     *(p++) = z.im;
126                     *(p++) = 0.0;
127                     *(p++) = 1.0;
128                    
129                     x += dx;
130                 }
131                
132                 y += dy;
133                
134             }
135            
136             glDrawPixels( 256, 256, GL_RGBA, GL_FLOAT, &data[0]);
137            
138            
139            
140            
141         }
142
143         void keyUp(int key) {
144
145         }
146        
147         void keyDown(int key) {
148
149         }
150        
151         void mouseMove(Vec2i mousePosition, Vec2i mouseMovement) {
152
153         }
154        
155     }
156    
157 }
Note: See TracBrowser for help on using the browser.