Rev 1789 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1789 | Rev 5098 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | iadn |
2 | iadn |
3 | http://www.iadn.narod.ru |
3 | http://www.iadn.narod.ru |
4 | iadn@bk.ru |
4 | iadn@bk.ru |
5 | */ |
5 | */ |
6 | #include |
6 | #include |
7 | #include |
7 | #include |
8 | #include |
8 | #include |
9 | 9 | ||
10 | #include "SysCall.h" |
10 | #include "SysCall.h" |
11 | #include "ProcessTab.h" |
11 | #include "ProcessTab.h" |
12 | #include "bmp.h" |
12 | #include "bmp.h" |
13 | 13 | ||
14 | 14 | ||
15 | int Fps (long x, long y); |
15 | int Fps (long x, long y); |
16 | extern "C"{ |
16 | extern "C"{ |
17 | void app_main(void); |
17 | int main(void); |
18 | } |
18 | } |
19 | 19 | ||
20 | struct { |
20 | struct { |
21 | int x,y; |
21 | int x,y; |
22 | int dx,dy; |
22 | int dx,dy; |
23 | } win; |
23 | } win; |
24 | 24 | ||
25 | #define KEY_ESC 1 |
25 | #define KEY_ESC 1 |
26 | #define KEY_F 33 |
26 | #define KEY_F 33 |
27 | 27 | ||
28 | char *title1 = "TinyGL in KolibriOS"; |
28 | char *title1 = "TinyGL in KolibriOS"; |
29 | char *title2 = "F full screen"; |
29 | char *title2 = "F full screen"; |
30 | char *title3 = "ESC - exit"; |
30 | char *title3 = "ESC - exit"; |
31 | char *fps = "FPS:"; |
31 | char *fps = "FPS:"; |
32 | 32 | ||
33 | unsigned char FullScreen = 0; |
33 | unsigned char FullScreen = 0; |
34 | unsigned char skin = 3; |
34 | unsigned char skin = 3; |
35 | 35 | ||
36 | static GLuint* TexObj; |
36 | static GLuint* TexObj; |
37 | 37 | ||
38 | float angle = 0.0; |
38 | float angle = 0.0; |
39 | process_table_entry_* pri; |
39 | process_table_entry_* pri; |
40 | KOSGLContext cgl; |
40 | KOSGLContext cgl; |
41 | 41 | ||
42 | struct V3{ |
42 | struct V3{ |
43 | float v1; |
43 | float v1; |
44 | float v2; |
44 | float v2; |
45 | float v3; |
45 | float v3; |
46 | } ptrv[8] = {{-1.0,1.0,1.0}, |
46 | } ptrv[8] = {{-1.0,1.0,1.0}, |
47 | {-1.0,-1.0,1.0}, |
47 | {-1.0,-1.0,1.0}, |
48 | {1.0,-1.0,1.0}, |
48 | {1.0,-1.0,1.0}, |
49 | {1.0,1.0,1.0}, |
49 | {1.0,1.0,1.0}, |
50 | {-1.0,1.0,-1.0}, |
50 | {-1.0,1.0,-1.0}, |
51 | {-1.0,-1.0,-1.0}, |
51 | {-1.0,-1.0,-1.0}, |
52 | {1.0,-1.0,-1.0}, |
52 | {1.0,-1.0,-1.0}, |
53 | {1.0,1.0,-1.0}}; |
53 | {1.0,1.0,-1.0}}; |
54 | 54 | ||
55 | struct T2{ |
55 | struct T2{ |
56 | float t1; |
56 | float t1; |
57 | float t2; |
57 | float t2; |
58 | } ptrt[4] = { |
58 | } ptrt[4] = { |
59 | {0.0, 0.0}, |
59 | {0.0, 0.0}, |
60 | {1.0, 0.0}, |
60 | {1.0, 0.0}, |
61 | {1.0, 1.0}, |
61 | {1.0, 1.0}, |
62 | {0.0, 1.0} |
62 | {0.0, 1.0} |
63 | }; |
63 | }; |
64 | 64 | ||
65 | void DrawQUADS(V3* ptr, int iv1, int iv2, int iv3, int iv4, T2* ptrt, int it1, int it2, int it3, int it4) |
65 | void DrawQUADS(V3* ptr, int iv1, int iv2, int iv3, int iv4, T2* ptrt, int it1, int it2, int it3, int it4) |
66 | { |
66 | { |
67 | glBegin(GL_QUADS); |
67 | glBegin(GL_QUADS); |
68 | glTexCoord2fv((float*)&ptrt[it1]); |
68 | glTexCoord2fv((float*)&ptrt[it1]); |
69 | glVertex3fv((float*)&ptr[iv1]); |
69 | glVertex3fv((float*)&ptr[iv1]); |
70 | glTexCoord2fv((float*)&ptrt[it2]); |
70 | glTexCoord2fv((float*)&ptrt[it2]); |
71 | glVertex3fv((float*)&ptr[iv2]); |
71 | glVertex3fv((float*)&ptr[iv2]); |
72 | glTexCoord2fv((float*)&ptrt[it3]); |
72 | glTexCoord2fv((float*)&ptrt[it3]); |
73 | glVertex3fv((float*)&ptr[iv3]); |
73 | glVertex3fv((float*)&ptr[iv3]); |
74 | glTexCoord2fv((float*)&ptrt[it4]); |
74 | glTexCoord2fv((float*)&ptrt[it4]); |
75 | glVertex3fv((float*)&ptr[iv4]); |
75 | glVertex3fv((float*)&ptr[iv4]); |
76 | glEnd(); |
76 | glEnd(); |
77 | } |
77 | } |
78 | void DrawGL() |
78 | void DrawGL() |
79 | { |
79 | { |
80 | glLoadIdentity(); // óñòàíàâëèâàåì åäåíè÷íóþ ìàòðèöó |
80 | glLoadIdentity(); // óñòàíàâëèâàåì åäåíè÷íóþ ìàòðèöó |
81 | glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
81 | glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
82 | 82 | ||
83 | glTranslatef(0.0, 0.0, -6.0); |
83 | glTranslatef(0.0, 0.0, -6.0); |
84 | glRotatef(angle, 1.0, 0.0, 0.0); |
84 | glRotatef(angle, 1.0, 0.0, 0.0); |
85 | glRotatef(2.0*angle, 0.0, 1.0, 0.0); |
85 | glRotatef(2.0*angle, 0.0, 1.0, 0.0); |
86 | glRotatef(3.0*angle, 0.0, 0.0, 1.0); |
86 | glRotatef(3.0*angle, 0.0, 0.0, 1.0); |
87 | 87 | ||
88 | DrawQUADS((V3*)&ptrv,0,1,2,3,(T2*)&ptrt,3,0,1,2); |
88 | DrawQUADS((V3*)&ptrv,0,1,2,3,(T2*)&ptrt,3,0,1,2); |
89 | DrawQUADS((V3*)&ptrv,0,3,7,4,(T2*)&ptrt,1,2,3,0); |
89 | DrawQUADS((V3*)&ptrv,0,3,7,4,(T2*)&ptrt,1,2,3,0); |
90 | DrawQUADS((V3*)&ptrv,4,7,6,5,(T2*)&ptrt,2,3,0,1); |
90 | DrawQUADS((V3*)&ptrv,4,7,6,5,(T2*)&ptrt,2,3,0,1); |
91 | DrawQUADS((V3*)&ptrv,5,6,2,1,(T2*)&ptrt,3,0,1,2); |
91 | DrawQUADS((V3*)&ptrv,5,6,2,1,(T2*)&ptrt,3,0,1,2); |
92 | DrawQUADS((V3*)&ptrv,7,3,2,6,(T2*)&ptrt,3,0,1,2); |
92 | DrawQUADS((V3*)&ptrv,7,3,2,6,(T2*)&ptrt,3,0,1,2); |
93 | DrawQUADS((V3*)&ptrv,5,1,0,4,(T2*)&ptrt,3,0,1,2); |
93 | DrawQUADS((V3*)&ptrv,5,1,0,4,(T2*)&ptrt,3,0,1,2); |
94 | 94 | ||
95 | kosglSwapBuffers(); |
95 | kosglSwapBuffers(); |
96 | } |
96 | } |
97 | 97 | ||
98 | void reshape() |
98 | void reshape() |
99 | { |
99 | { |
100 | __menuet__get_process_table((process_table_entry*)pri,-1); |
100 | __menuet__get_process_table((process_table_entry*)pri,-1); |
101 | glViewport(0, 0, pri->winx_size, pri->winy_size-20); |
101 | glViewport(0, 0, pri->winx_size, pri->winy_size-20); |
102 | glMatrixMode(GL_PROJECTION); |
102 | glMatrixMode(GL_PROJECTION); |
103 | glLoadIdentity(); |
103 | glLoadIdentity(); |
104 | gluPerspective(50.0, (GLfloat)pri->winx_size/pri->winy_size, 1.0, 300.0); |
104 | gluPerspective(50.0, (GLfloat)pri->winx_size/pri->winy_size, 1.0, 300.0); |
105 | glMatrixMode(GL_MODELVIEW); |
105 | glMatrixMode(GL_MODELVIEW); |
106 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); |
106 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); |
107 | } |
107 | } |
108 | 108 | ||
109 | void disabletgl() |
109 | void disabletgl() |
110 | { |
110 | { |
111 | kosglDestroyContext(cgl); |
111 | kosglDestroyContext(cgl); |
112 | delete pri; |
112 | delete pri; |
113 | } |
113 | } |
114 | 114 | ||
115 | void Title() |
115 | void Title() |
116 | { |
116 | { |
117 | __menuet__write_text(300,8,0x10ffffff,fps,strlen(fps)); |
117 | __menuet__write_text(300,8,0x10ffffff,fps,strlen(fps)); |
118 | __menuet__write_text(8,8,0x10ffffff,title1,strlen(title1)); |
118 | __menuet__write_text(8,8,0x10ffffff,title1,strlen(title1)); |
119 | __menuet__write_text(180,8,0x00ffffff,title2,strlen(title2)); |
119 | __menuet__write_text(180,8,0x00ffffff,title2,strlen(title2)); |
120 | __menuet__write_text(600,8,0x00ffffff,title3,strlen(title3)); |
120 | __menuet__write_text(600,8,0x00ffffff,title3,strlen(title3)); |
121 | } |
121 | } |
122 | 122 | ||
123 | void draw_window(void) |
123 | void draw_window(void) |
124 | { |
124 | { |
125 | // start redraw |
125 | // start redraw |
126 | __menuet__window_redraw(1); |
126 | __menuet__window_redraw(1); |
127 | // define&draw window |
127 | // define&draw window |
128 | __menuet__define_window(win.x,win.y,win.dx,win.dy,TYPEWIN(0,0,0,1,skin,0,0,0),0,0); |
128 | __menuet__define_window(win.x,win.y,win.dx,win.dy,TYPEWIN(0,0,0,1,skin,0,0,0),0,0); |
129 | // end redraw |
129 | // end redraw |
130 | __menuet__window_redraw(2); |
130 | __menuet__window_redraw(2); |
131 | // display string |
131 | // display string |
132 | Title(); |
132 | Title(); |
133 | } |
133 | } |
134 | 134 | ||
135 | void app_main(void) |
135 | int main(void) |
136 | { |
136 | { |
137 | 137 | ||
138 | win.x = 100; |
138 | win.x = 100; |
139 | win.y = 100; |
139 | win.y = 100; |
140 | win.dx = 400; |
140 | win.dx = 400; |
141 | win.dy = 400; |
141 | win.dy = 400; |
142 | 142 | ||
143 | draw_window(); |
143 | draw_window(); |
144 | 144 | ||
145 | cgl = kosglCreateContext( 0, 0); |
145 | cgl = kosglCreateContext( 0, 0); |
146 | kosglMakeCurrent( 0, 20, win.dx, win.dy-20, cgl); |
146 | kosglMakeCurrent( 0, 20, win.dx, win.dy-20, cgl); |
147 | 147 | ||
148 | glMatrixMode(GL_MODELVIEW); |
148 | glMatrixMode(GL_MODELVIEW); |
149 | glLoadIdentity(); |
149 | glLoadIdentity(); |
150 | 150 | ||
151 | glClearDepth(1.0); |
151 | glClearDepth(1.0); |
152 | glEnable( GL_CULL_FACE ); |
152 | glEnable( GL_CULL_FACE ); |
153 | glEnable(GL_DEPTH_TEST); |
153 | glEnable(GL_DEPTH_TEST); |
154 | 154 | ||
155 | 155 | ||
156 | int width, height; |
156 | int width, height; |
157 | unsigned char* texture; |
157 | unsigned char* texture; |
158 | LoadFileBMP( "./logio.bmp", &texture, &width, &height, false ); |
158 | LoadFileBMP( "./logio.bmp", &texture, &width, &height, false ); |
159 | 159 | ||
160 | /* Setup texturing */ |
160 | /* Setup texturing */ |
161 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); |
161 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); |
162 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); |
162 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); |
163 | 163 | ||
164 | /* generate texture object IDs */ |
164 | /* generate texture object IDs */ |
165 | glGenTextures(1, TexObj); |
165 | glGenTextures(1, TexObj); |
166 | glBindTexture(GL_TEXTURE_2D, *TexObj); |
166 | glBindTexture(GL_TEXTURE_2D, *TexObj); |
167 | glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture); |
167 | glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture); |
168 | 168 | ||
169 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
169 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
170 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
170 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
171 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
171 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
172 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
172 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
173 | glBindTexture(GL_TEXTURE_2D, *TexObj); |
173 | glBindTexture(GL_TEXTURE_2D, *TexObj); |
174 | glEnable(GL_TEXTURE_2D); |
174 | glEnable(GL_TEXTURE_2D); |
175 | 175 | ||
176 | pri=new process_table_entry_; |
176 | pri=new process_table_entry_; |
177 | SysCall(66,1,1); |
177 | SysCall(66,1,1); |
178 | 178 | ||
179 | reshape(); |
179 | reshape(); |
180 | 180 | ||
181 | do{ |
181 | do{ |
182 | 182 | ||
183 | angle += 0.001 + 0.1*Fps (330,8); |
183 | angle += 0.001 + 0.1*Fps (330,8); |
184 | 184 | ||
185 | DrawGL(); |
185 | DrawGL(); |
186 | 186 | ||
187 | switch(__menuet__check_for_event()) |
187 | switch(__menuet__check_for_event()) |
188 | { |
188 | { |
189 | case 1: draw_window(); |
189 | case 1: draw_window(); |
190 | reshape(); |
190 | reshape(); |
191 | break; |
191 | break; |
192 | 192 | ||
193 | case 2: |
193 | case 2: |
194 | switch(__menuet__getkey()){ |
194 | switch(__menuet__getkey()){ |
195 | 195 | ||
196 | case KEY_F: |
196 | case KEY_F: |
197 | if(!FullScreen){ |
197 | if(!FullScreen){ |
198 | skin=0; |
198 | skin=0; |
199 | SysCall(67,0,0,SysCall(14)>>16,SysCall(14)&0xffff); |
199 | SysCall(67,0,0,SysCall(14)>>16,SysCall(14)&0xffff); |
200 | draw_window(); |
200 | draw_window(); |
201 | reshape(); |
201 | reshape(); |
202 | FullScreen = 1; |
202 | FullScreen = 1; |
203 | } |
203 | } |
204 | else{ |
204 | else{ |
205 | skin=3; |
205 | skin=3; |
206 | draw_window(); |
206 | draw_window(); |
207 | SysCall(67,win.x,win.y,win.dx,win.dy); |
207 | SysCall(67,win.x,win.y,win.dx,win.dy); |
208 | reshape(); |
208 | reshape(); |
209 | FullScreen = 0; |
209 | FullScreen = 0; |
210 | }; |
210 | }; |
211 | break; |
211 | break; |
212 | 212 | ||
213 | case KEY_ESC: disabletgl(); |
213 | case KEY_ESC: disabletgl(); |
214 | return;} |
214 | return 0;} |
215 | break; |
215 | break; |
216 | 216 | ||
217 | case 3: disabletgl(); |
217 | case 3: disabletgl(); |
218 | return; |
218 | return 0; |
219 | } |
219 | } |
220 | }while(1); |
220 | }while(1); |
221 | } |
221 | } |